Documentation ¶
Index ¶
- Variables
- func As[T any](v Value) T
- func Fields(d Object) ([]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)
- func ParseTimestamp(s string) (time.Time, error)
- type Array
- type Object
- 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 NewDoubleValue(x float64) Value
- func NewIntegerValue(x int64) Value
- func NewNullValue() Value
- func NewObjectValue(d Object) Value
- func NewTextValue(x string) Value
- func NewTimestampValue(x time.Time) 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 object implementations, when calling the GetByField method and // the field wasn't found in the object. 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 object 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 Object ¶
type Object interface { // Iterate goes through all the fields of the object 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 object. MarshalJSON() ([]byte, error) }
A Object 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 NewDoubleValue ¶
NewDoubleValue returns a SQL DOUBLE value.
func NewIntegerValue ¶
NewIntegerValue returns a SQL INTEGER value.
func NewObjectValue ¶
NewObjectValue returns a SQL OBJECT value.
func NewTimestampValue ¶
NewTimestampValue returns a SQL TIMESTAMP value.
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 = iota NullValue BooleanValue IntegerValue DoubleValue TimestampValue TextValue BlobValue ArrayValue ObjectValue )
List of supported value types.
func (ValueType) IsTimestampCompatible ¶
IsTimestampCompatible returns true if t is either a timestamp, an integer, or a text.