Documentation ¶
Index ¶
- Variables
- func As[T any](v Value) T
- func Fields(d Document) ([]string, error)
- func Is[T any](v Value) (T, bool)
- func IsEqual(v, other Value) (bool, error)
- func IsGreaterThan(v, other Value) (bool, error)
- func IsGreaterThanOrEqual(v, other Value) (bool, error)
- func IsLesserThan(v, other Value) (bool, error)
- func IsLesserThanOrEqual(v, other Value) (bool, error)
- func IsNotEqual(v, other Value) (bool, error)
- func IsNull(v Value) bool
- func IsTruthy(v Value) (bool, error)
- func IsZeroValue(v Value) (bool, error)
- func MarshalTextIndent(v Value, prefix, indent string) ([]byte, error)
- type Array
- type Document
- type Value
- func Add(v1, v2 Value) (res Value, err error)
- func BitwiseAnd(v1, v2 Value) (res Value, err error)
- func BitwiseOr(v1, v2 Value) (res Value, err error)
- func BitwiseXor(v1, v2 Value) (res Value, err error)
- func Div(v1, v2 Value) (res Value, err error)
- func Mod(v1, v2 Value) (res Value, err error)
- func Mul(v1, v2 Value) (res Value, err error)
- func NewArrayValue(a Array) Value
- func NewBlobValue(x []byte) Value
- func NewBoolValue(x bool) Value
- func NewDocumentValue(d Document) Value
- func NewDoubleValue(x float64) Value
- func NewIntegerValue(x int64) Value
- func NewNullValue() Value
- func NewTextValue(x string) Value
- func NewValueWith[T any](t ValueType, v T) Value
- func Sub(v1, v2 Value) (res Value, err error)
- type ValueType
Constants ¶
This section is empty.
Variables ¶
var ( // ErrFieldNotFound must be returned by Document implementations, when calling the GetByField method and // the field wasn't found in the document. ErrFieldNotFound = errors.New("field not found") // ErrValueNotFound must be returned by Array implementations, when calling the GetByIndex method and // the index wasn't found in the array. ErrValueNotFound = errors.New("value not found") )
Functions ¶
func Fields ¶
Fields returns a list of all the fields at the root of the document sorted lexicographically.
func IsGreaterThan ¶
IsGreaterThan returns true if v is greather than the given value.
func IsGreaterThanOrEqual ¶
IsGreaterThanOrEqual returns true if v is greather than or equal to the given value.
func IsLesserThan ¶
IsLesserThan returns true if v is lesser than the given value.
func IsLesserThanOrEqual ¶
IsLesserThanOrEqual returns true if v is lesser than or equal to the given value.
func IsNotEqual ¶
IsNotEqual returns true if v is not equal to the given value.
func IsZeroValue ¶
IsZeroValue indicates if the value data is the zero value for the value type. This function doesn't perform any allocation.
Types ¶
type Array ¶
type Array interface { // Iterate goes through all the values of the array and calls the given function by passing each one of them. // If the given function returns an error, the iteration stops. Iterate(fn func(i int, value Value) error) error // GetByIndex returns a value by index of the array. GetByIndex(i int) (Value, error) // MarshalJSON implements the json.Marshaler interface. // It returns a JSON representation of the array. MarshalJSON() ([]byte, error) }
An Array contains a set of values.
type Document ¶
type Document interface { // Iterate goes through all the fields of the document and calls the given function by passing each one of them. // If the given function returns an error, the iteration stops. Iterate(fn func(field string, value Value) error) error // GetByField returns a value by field name. // Must return ErrFieldNotFound if the field doesn't exist. GetByField(field string) (Value, error) // MarshalJSON implements the json.Marshaler interface. // It returns a JSON representation of the document. MarshalJSON() ([]byte, error) }
A Document represents a group of key value pairs.
type Value ¶
type Value interface { Type() ValueType V() any String() string MarshalJSON() ([]byte, error) MarshalText() ([]byte, error) }
func Add ¶
Add u to v and return the result. Only numeric values and booleans can be added together.
func BitwiseAnd ¶
BitwiseAnd calculates v & u and returns the result. Only numeric values and booleans can be calculated together. If both v and u are integers, the result will be an integer.
func BitwiseOr ¶
BitwiseOr calculates v | u and returns the result. Only numeric values and booleans can be calculated together. If both v and u are integers, the result will be an integer.
func BitwiseXor ¶
BitwiseXor calculates v ^ u and returns the result. Only numeric values and booleans can be calculated together. If both v and u are integers, the result will be an integer.
func Div ¶
Div calculates v / u and returns the result. Only numeric values and booleans can be calculated together. If both v and u are integers, the result will be an integer.
func Mod ¶
Mod calculates v / u and returns the result. Only numeric values and booleans can be calculated together. If both v and u are integers, the result will be an integer.
func Mul ¶
Mul calculates v * u and returns the result. Only numeric values and booleans can be calculated together.
func NewDocumentValue ¶
NewDocumentValue returns a value of type Document.
func NewDoubleValue ¶
NewDoubleValue encodes x and returns a value.
func NewIntegerValue ¶
NewIntegerValue encodes x and returns a value whose type depends on the magnitude of x.
func NewValueWith ¶
NewValueWith creates a value with the given type and value.
type ValueType ¶
type ValueType uint8
ValueType represents a value type supported by the database.
const ( // AnyValue denotes the absence of type AnyValue ValueType = 0x00 NullValue ValueType = 0x05 BooleanValue ValueType = 0x10 IntegerValue ValueType = 0x20 DoubleValue ValueType = 0xD0 TextValue ValueType = 0xDA BlobValue ValueType = 0xE0 ArrayValue ValueType = 0xE6 DocumentValue ValueType = 0xF0 )
List of supported value types.