Documentation ¶
Overview ¶
Package types provides a type system for the add engine. Values have a type, and types are described by type descriptors. Types define operations on their values, such as comparison.
Index ¶
- Variables
- type ArithmeticAdder
- type ArithmeticDivider
- type ArithmeticExponentiator
- type ArithmeticModulator
- type ArithmeticMultiplicator
- type ArithmeticSubtractor
- type BoolType
- type BoolValue
- type Caster
- type Comparator
- type DateType
- type DateValue
- type Error
- type FunctionType
- type FunctionValue
- type IntegerType
- func (t IntegerType) Add(left, right Value) (Value, error)
- func (t IntegerType) Compare(left, right Value) (int, error)
- func (t IntegerType) Div(left, right Value) (Value, error)
- func (t IntegerType) Mod(left, right Value) (Value, error)
- func (t IntegerType) Mul(left, right Value) (Value, error)
- func (t IntegerType) Name() string
- func (t IntegerType) Pow(left, right Value) (Value, error)
- func (t IntegerType) String() string
- func (t IntegerType) Sub(left, right Value) (Value, error)
- type IntegerValue
- type IsNuller
- type IsTyper
- type NullValue
- type RealType
- func (t RealType) Add(left, right Value) (Value, error)
- func (t RealType) Compare(left, right Value) (int, error)
- func (t RealType) Div(left, right Value) (Value, error)
- func (t RealType) Mul(left, right Value) (Value, error)
- func (t RealType) Name() string
- func (t RealType) Pow(left, right Value) (Value, error)
- func (t RealType) String() string
- func (t RealType) Sub(left, right Value) (Value, error)
- type RealValue
- type Serializer
- type StringType
- func (t StringType) Add(left, right Value) (Value, error)
- func (StringType) Cast(v Value) (Value, error)
- func (t StringType) Compare(left, right Value) (int, error)
- func (t StringType) Deserialize(data []byte) (Value, error)
- func (t StringType) Name() string
- func (t StringType) Serialize(v Value) ([]byte, error)
- func (t StringType) String() string
- type StringValue
- type Type
- type TypeIndicator
- type Value
Constants ¶
This section is empty.
Variables ¶
var ( // Bool is the Bool type. Bools are comparable with true>false. The name of // this type is "Bool". Bool = BoolType{ // contains filtered or unexported fields } )
var ( // Date is the date type. Dates are comparable. A date that is later than // another date is considered larger. The name of this type is "Date". Date = DateType{ // contains filtered or unexported fields } )
var ( // Function is the function type. Functions are not comparable. The name of // this type is "Function". Function = FunctionType{ // contains filtered or unexported fields } )
var ( // Integer is the date type. Integers are comparable. The name of this type // is "Integer". Integer = IntegerType{ // contains filtered or unexported fields } )
var ( // Real is the date type. Reals are comparable. The name of this type // is "Real". Real = RealType{ // contains filtered or unexported fields } )
var ( // String is the string type. Strings are comparable. Comparison is done // lexicographically. The name of this type is "String". String = StringType{ // contains filtered or unexported fields } )
Functions ¶
This section is empty.
Types ¶
type ArithmeticAdder ¶
ArithmeticAdder wraps the arithmetic add operation, usually represented by a '+'. The actual addition is defined and must be documented by the implementing type.
type ArithmeticDivider ¶
ArithmeticDivider wraps the arithmetic div operation, usually represented by a '/'. The actual division is defined and must be documented by the implementing type.
type ArithmeticExponentiator ¶
ArithmeticExponentiator wraps the arithmetic pow operation, usually represented by a '**'. The actual exponentiation is defined and must be documented by the implementing type.
type ArithmeticModulator ¶
ArithmeticModulator wraps the arithmetic mod operation, usually represented by a '%'. The actual modulation is defined and must be documented by the implementing type.
type ArithmeticMultiplicator ¶
ArithmeticMultiplicator wraps the arithmetic mul operation, usually represented by a '*'. The actual multiplication is defined and must be documented by the implementing type.
type ArithmeticSubtractor ¶
ArithmeticSubtractor wraps the arithmetic sub operation, usually represented by a '-'. The actual subtraction is defined and must be documented by the implementing type.
type BoolType ¶
type BoolType struct {
// contains filtered or unexported fields
}
BoolType is a basic type. Values of this type describe a boolean value, either true or false.
func (BoolType) Compare ¶
Compare compares two bool values. For this to succeed, both values must be of type BoolValue and be not nil. The bool value true is considered larger than false. This method will return 1 if left>right, 0 if left==right, and -1 if left<right.
func (BoolType) Deserialize ¶
Deserialize can deserialize a single byte to a bool value. If the length of the given data is not 1, an error will be returned. A zero byte will be deserialized to the value false, while everything else will be deserialized to the value true.
type BoolValue ¶
type BoolValue struct { // Value is the underlying primitive value. Value bool // contains filtered or unexported fields }
BoolValue is a value of type Bool. The boolean value is held as a primitive Go bool.
type Caster ¶
Caster wraps the Cast method, which is used to transform the input value into an output value. Types can implement this interface. E.g. if the type String implements Caster, any value passed into the Cast method should be attempted to be cast to String, or an error should be returned.
type Comparator ¶
type Comparator interface { // Compare compares the given to values left and right as follows. -1 if // left<right, 0 if left==right, 1 if left>right. However, NULL<any, so if // the left value is NULL, and is comparable to the right value (same type), // this will return -1 and no error. NULL~NULL is undefined. Compare(left, right Value) (int, error) }
Comparator is the interface that wraps the basic compare method. The compare method compares the left and right value as follows. -1 if left<right, 0 if left==right, 1 if left>right. What exectly is considered to be <, ==, > is up to the implementation. By definition, the NULL value is smaller than any other value. When comparing NULL to another NULL value, and both NULLs have the same type, the result is undefined, however, no error must be returned.
type DateType ¶
type DateType struct {
// contains filtered or unexported fields
}
DateType is a comparable type.
type DateValue ¶
type DateValue struct { // Value is the underlying primitive value. Value time.Time // contains filtered or unexported fields }
DateValue is a value of type Date.
type Error ¶
type Error string
Error is a sentinel error.
func ErrCannotCast ¶
ErrCannotCast returns an error that indicates, that a case from the given from type to the given to type cannot be performed.
func ErrDataSizeMismatch ¶
ErrDataSizeMismatch returns an error that indicates, that data which had an unexpected size was passed in. This will be useful for functions that expect fixed-size data.
func ErrTypeMismatch ¶
ErrTypeMismatch returns an error that indicates a type mismatch, and includes the expected and the actual type.
type FunctionType ¶
type FunctionType struct {
// contains filtered or unexported fields
}
FunctionType is a non-comparable type.
type FunctionValue ¶
FunctionValue is a value of type Function. This can not be called, it is simply a shell that holds a function name and the arguments, that were used in the SQL statement. It is the engine's responsibility, to execute the appropriate code to make this function call happen.
func NewFunction ¶
func NewFunction(name string, args ...Value) FunctionValue
NewFunction creates a new value of type Function.
func (FunctionValue) String ¶
func (v FunctionValue) String() string
type IntegerType ¶
type IntegerType struct {
// contains filtered or unexported fields
}
IntegerType is a comparable type.
func (IntegerType) Add ¶
func (t IntegerType) Add(left, right Value) (Value, error)
Add adds the left and right value, producing a new integer value. This only works, if left and right are of type integer.
func (IntegerType) Compare ¶
func (t IntegerType) Compare(left, right Value) (int, error)
Compare compares two date values. For this to succeed, both values must be of type IntegerValue and be not nil. A date later than another date is considered larger. This method will return 1 if left>right, 0 if left==right, and -1 if left<right.
func (IntegerType) Div ¶
func (t IntegerType) Div(left, right Value) (Value, error)
Div divides the left by the right value, producing a new real value. This only works, if left and right are of type integer.
func (IntegerType) Mod ¶
func (t IntegerType) Mod(left, right Value) (Value, error)
Mod modulates the left and right value, producing a new integer value. This only works, if left and right are of type integer.
func (IntegerType) Mul ¶
func (t IntegerType) Mul(left, right Value) (Value, error)
Mul multiplicates the left and right value, producing a new integer value. This only works, if left and right are of type integer.
type IntegerValue ¶
type IntegerValue struct { // Value is the underlying primitive value. Value int64 // contains filtered or unexported fields }
IntegerValue is a value of type Integer.
func NewInteger ¶
func NewInteger(v int64) IntegerValue
NewInteger creates a new value of type Integer.
func (IntegerValue) String ¶
func (v IntegerValue) String() string
type IsNuller ¶
type IsNuller interface {
IsNull() bool
}
IsNuller wraps the method IsNull, which determines whether the value is a null value or not.
type NullValue ¶
type NullValue struct {
// contains filtered or unexported fields
}
NullValue is a value of type null. It has no actual value.
type RealType ¶
type RealType struct {
// contains filtered or unexported fields
}
RealType is a comparable type.
func (RealType) Add ¶
Add adds the left and right value, producing a new real value. This only works, if left and right are of type real.
func (RealType) Compare ¶
Compare compares two real values. For this to succeed, both values must be of type RealValue and be not nil.
func (RealType) Div ¶
Div divides the left by the right value, producing a new real value. This only works, if left and right are of type real.
func (RealType) Mul ¶
Mul multiplicates the left and right value, producing a new real value. This only works, if left and right are of type real.
type RealValue ¶
type RealValue struct { // Value is the underlying primitive value. Value float64 // contains filtered or unexported fields }
RealValue is a value of type Real.
type Serializer ¶
Serializer wraps two basic methods for two-way serializing values. Which values can be serialized and deserialized, is up to the implementing object. It must be documented, what can and can not be serialized and deserialized.
type StringType ¶
type StringType struct {
// contains filtered or unexported fields
}
StringType is a comparable type.
func (StringType) Add ¶
func (t StringType) Add(left, right Value) (Value, error)
Add concatenates the left and right right value. This only works, if left and right are string values.
func (StringType) Cast ¶
func (StringType) Cast(v Value) (Value, error)
Cast attempts to cast the given value to a String. This is done by returning a string representing the string value of the given value.
func (StringType) Compare ¶
func (t StringType) Compare(left, right Value) (int, error)
Compare for the String is defined as the lexicographical comparison of the two underlying primitive values. This method will return 1 if left>right, 0 if left==right, and -1 if left<right.
func (StringType) Deserialize ¶
func (t StringType) Deserialize(data []byte) (Value, error)
Deserialize reads the data size from the first 4 passed-in bytes, and then converts the rest of the bytes to a string leveraging the Go runtime.
type StringValue ¶
type StringValue struct { // Value is the underlying primitive value. Value string // contains filtered or unexported fields }
StringValue is a value of type String.
func (StringValue) String ¶
func (v StringValue) String() string
type Type ¶
Type is a data type that consists of a type descriptor and a comparator. The comparator forces types to define relations between two values of this type. A type is only expected to be able to handle values of its own type.
func ByIndicator ¶
func ByIndicator(indicator TypeIndicator) Type
ByIndicator accepts a type indicator and returns the corresponding type. If the returned type is nil, the type indicator is unknown.
type TypeIndicator ¶
type TypeIndicator uint8
TypeIndicator is a type that is used to serialize types. Each indicator corresponds to a type.
const ( TypeIndicatorUnknown TypeIndicator = iota TypeIndicatorBool TypeIndicatorDate TypeIndicatorInteger TypeIndicatorReal TypeIndicatorString )
Known type indicators corresponding to known types.
func (TypeIndicator) String ¶
func (i TypeIndicator) String() string
Source Files ¶
- arithmetic.go
- bool_type.go
- bool_value.go
- caster.go
- comparator.go
- date_type.go
- date_value.go
- doc.go
- error.go
- function_type.go
- function_value.go
- integer_type.go
- integer_value.go.go
- null_value.go
- real_type.go
- real_value.go
- serializer.go
- string_type.go
- string_value.go
- type.go
- typeindicator_string.go
- types.go
- value.go