types

package
v0.16.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 25, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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 As

func As[T any](v Value) T

func Fields

func Fields(d Object) ([]string, error)

Fields returns a list of all the fields at the root of the object sorted lexicographically.

func Is

func Is[T any](v Value) (T, bool)

func IsEqual

func IsEqual(v, other Value) (bool, error)

IsEqual returns true if v is equal to the given value.

func IsGreaterThan

func IsGreaterThan(v, other Value) (bool, error)

IsGreaterThan returns true if v is greather than the given value.

func IsGreaterThanOrEqual

func IsGreaterThanOrEqual(v, other Value) (bool, error)

IsGreaterThanOrEqual returns true if v is greather than or equal to the given value.

func IsLesserThan

func IsLesserThan(v, other Value) (bool, error)

IsLesserThan returns true if v is lesser than the given value.

func IsLesserThanOrEqual

func IsLesserThanOrEqual(v, other Value) (bool, error)

IsLesserThanOrEqual returns true if v is lesser than or equal to the given value.

func IsNotEqual

func IsNotEqual(v, other Value) (bool, error)

IsNotEqual returns true if v is not equal to the given value.

func IsNull

func IsNull(v Value) bool

func IsTruthy

func IsTruthy(v Value) (bool, error)

IsTruthy returns whether v is not equal to the zero value of its type.

func IsZeroValue

func IsZeroValue(v Value) (bool, error)

IsZeroValue indicates if the value data is the zero value for the value type. This function doesn't perform any allocation.

func MarshalTextIndent

func MarshalTextIndent(v Value, prefix, indent string) ([]byte, error)

func ParseTimestamp

func ParseTimestamp(s string) (time.Time, error)

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

func Add(v1, v2 Value) (res Value, err error)

Add u to v and return the result. Only numeric values and booleans can be added together.

func BitwiseAnd

func BitwiseAnd(v1, v2 Value) (res Value, err error)

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

func BitwiseOr(v1, v2 Value) (res Value, err error)

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

func BitwiseXor(v1, v2 Value) (res Value, err error)

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

func Div(v1, v2 Value) (res Value, err error)

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

func Mod(v1, v2 Value) (res Value, err error)

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

func Mul(v1, v2 Value) (res Value, err error)

Mul calculates v * u and returns the result. Only numeric values and booleans can be calculated together.

func NewArrayValue

func NewArrayValue(a Array) Value

NewArrayValue returns a SQL ARRAY value.

func NewBlobValue

func NewBlobValue(x []byte) Value

NewBlobValue returns a SQL BLOB value.

func NewBoolValue

func NewBoolValue(x bool) Value

NewBoolValue returns a SQL BOOL value.

func NewDoubleValue

func NewDoubleValue(x float64) Value

NewDoubleValue returns a SQL DOUBLE value.

func NewIntegerValue

func NewIntegerValue(x int64) Value

NewIntegerValue returns a SQL INTEGER value.

func NewNullValue

func NewNullValue() Value

NewNullValue returns a SQL NULL value.

func NewObjectValue

func NewObjectValue(d Object) Value

NewObjectValue returns a SQL OBJECT value.

func NewTextValue

func NewTextValue(x string) Value

NewTextValue returns a SQL TEXT value.

func NewTimestampValue

func NewTimestampValue(x time.Time) Value

NewTimestampValue returns a SQL TIMESTAMP value.

func NewValueWith

func NewValueWith[T any](t ValueType, v T) Value

NewValueWith creates a value with the given type and value.

func Sub

func Sub(v1, v2 Value) (res Value, err error)

Sub calculates v - u and returns the result. Only numeric values and booleans can be calculated together.

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) IsAny

func (t ValueType) IsAny() bool

IsAny returns whether this is type is Any or a real type

func (ValueType) IsNumber

func (t ValueType) IsNumber() bool

IsNumber returns true if t is either an integer or a float.

func (ValueType) IsTimestampCompatible

func (t ValueType) IsTimestampCompatible() bool

IsTimestampCompatible returns true if t is either a timestamp, an integer, or a text.

func (ValueType) String

func (t ValueType) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL