Documentation ¶
Overview ¶
Package keyval contains types representing key-values and related utilities. These types model both queries and the data returned by queries. They can be constructed from query strings using [parser.Parser] but are also designed to be easily constructed directly in Go source code.
Embedded Query Strings ¶
When working with SQL, programmers will often embed SQL strings in the application. This requires extra tooling to catch syntax errors at build time. Instead of using string literals, FDBQ allows the programmer to directly construct the queries using the types in this package, allowing some syntax errors to be caught at build time.
This package does not prevent all kinds of syntax errors, only "structural" ones. For instance, the type system ensures tuples only contain valid elements and limits what kinds of objects can be used as the value of a key-value. In spite of this, invalid queries can still be constructed (see package class).
Operations (Visitor Pattern) ¶
The Directory, Tuple, & Value types would be best represented by tagged unions. While Go does not natively support tagged unions, this codebase implements equivalent functionality using the visitor pattern. See package [operation] which generates the boilerplate code associated with this. See DirectoryOperation, TupleOperation, or ValueOperation as examples of the generated code.
Primitive Types ¶
There are a special group of types defined in this package named the "primitive" types. These include Nil, Int, Uint, Bool, Float, String, UUID, and Bytes. All of these types can be used as a TupElement or as a Value. When used as a TupElement, they are serialized by FDB tuple packing. When used as a Value, they are known as a "primitive" values and are serialized by FDBQ.
Index ¶
- type Bool
- type Bytes
- type Clear
- type DirElement
- type Directory
- type DirectoryOperation
- type Float
- type Int
- type Key
- type KeyValue
- type MaybeMore
- type Nil
- type Query
- type QueryOperation
- type String
- type TupElement
- type Tuple
- type TupleOperation
- type UUID
- type Uint
- type Value
- type ValueOperation
- type ValueType
- type Variable
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bool ¶
type Bool bool
Bool is a "primitive" type implementing a bool as either a TupElement or Value. When used as a Value, it's serialized as a single byte (0 for false, 1 for true).
func (Bool) TupElement ¶
func (x Bool) TupElement(op TupleOperation)
func (Bool) Value ¶
func (x Bool) Value(op ValueOperation)
type Bytes ¶
type Bytes []byte
Bytes is a "primitive" type implementing a byte string as either a TupElement or Value. When used as a Value, it's serialized as is.
func (Bytes) TupElement ¶
func (x Bytes) TupElement(op TupleOperation)
func (Bytes) Value ¶
func (x Bytes) Value(op ValueOperation)
type Clear ¶
type Clear struct{}
Clear is a special kind of Value which designates a KeyValue as a clear query. When executed, the provided key is cleared from the DB. Clear may not be used in a query containing Variable.
func (Clear) Value ¶
func (x Clear) Value(op ValueOperation)
type DirElement ¶
type DirElement interface { // DirElement executes the given DirectoryOperation on this DirElement. DirElement(DirectoryOperation) // Eq returns true if the given value is equal to this DirElement. Eq(interface{}) bool }
type Directory ¶
type Directory []DirElement
Directory can be passed to [engine.Engine] as a directory query. These kinds of queries define a directory path schema. When executed, all directories matching the schema are returned.
func (Directory) Query ¶
func (x Directory) Query(op QueryOperation)
type DirectoryOperation ¶
type Float ¶
type Float float64
Float is a "primitive" type implementing a float64 as either a TupElement or Value. When used as a Value, it's serialized as an 8-byte array in accordance with IEEE 754. Endianness depends on how the [engine.Engine] is configured.
func (Float) TupElement ¶
func (x Float) TupElement(op TupleOperation)
func (Float) Value ¶
func (x Float) Value(op ValueOperation)
type Int ¶
type Int int64
Int is a "primitive" type implementing an int64 as either a TupElement or Value. When used as a Value, it's serialized as a 2-compliment 8-byte string. Endianness depends on how the [engine.Engine] is configured.
func (Int) TupElement ¶
func (x Int) TupElement(op TupleOperation)
func (Int) Value ¶
func (x Int) Value(op ValueOperation)
type Key ¶
Key can be passed to [engine.Engine] as a query. When used as a query, it is equivalent to a KeyValue whose Value is an empty Variable.
func (Key) Query ¶
func (x Key) Query(op QueryOperation)
type KeyValue ¶
KeyValue can be passed to [engine.Engine] as a query or be returned from [engine.Engine] as a query's result. When returned as a result, KeyValue will not contain a Variable, Clear, or MaybeMore.
func (KeyValue) Query ¶
func (x KeyValue) Query(op QueryOperation)
type MaybeMore ¶
type MaybeMore struct{}
MaybeMore is a special kind of TupElement. It may only appear as the last element of the Tuple. A Query containing a MaybeMore defines a schema which allows all keys prefixed by the key in the schema. TODO: Implement as a flag on Tuple.
func (MaybeMore) TupElement ¶
func (x MaybeMore) TupElement(op TupleOperation)
type Nil ¶
type Nil struct{}
Nil is a "primitive" type representing an empty element when used as a TupElement. It's equivalent to an empty Bytes when used as a Value. Go's nil value is never allowed in a Key or KeyValue. Instead, use this type.
func (Nil) TupElement ¶
func (x Nil) TupElement(op TupleOperation)
func (Nil) Value ¶
func (x Nil) Value(op ValueOperation)
type Query ¶
type Query = query
Query is an interface implemented by the types which can be passed to [engine.Engine] as a query. This includes KeyValue, Key, & Directory.
type QueryOperation ¶
type QueryOperation interface { // ForDirectory performs the QueryOperation if the given query is of type Directory. ForDirectory(Directory) // ForKey performs the QueryOperation if the given query is of type Key. ForKey(Key) // ForKeyValue performs the QueryOperation if the given query is of type KeyValue. ForKeyValue(KeyValue) }
type String ¶
type String string
String is a "primitive" type implementing a string as either a TupElement or Value. When used as a Value, it's serialized as a UTF-8 encoded byte string.
func (String) DirElement ¶
func (x String) DirElement(op DirectoryOperation)
func (String) TupElement ¶
func (x String) TupElement(op TupleOperation)
func (String) Value ¶
func (x String) Value(op ValueOperation)
type TupElement ¶
type TupElement interface { // TupElement executes the given TupleOperation on this TupElement. TupElement(TupleOperation) // Eq returns true if the given value is equal to this TupElement. Eq(interface{}) bool }
type Tuple ¶
type Tuple []TupElement
Tuple may contain a Tuple, Variable, MaybeMore, or any of the "primitive" types.
func (Tuple) TupElement ¶
func (x Tuple) TupElement(op TupleOperation)
func (Tuple) Value ¶
func (x Tuple) Value(op ValueOperation)
type TupleOperation ¶
type TupleOperation interface { // ForTuple performs the TupleOperation if the given TupElement is of type Tuple. ForTuple(Tuple) // ForNil performs the TupleOperation if the given TupElement is of type Nil. ForNil(Nil) // ForInt performs the TupleOperation if the given TupElement is of type Int. ForInt(Int) // ForUint performs the TupleOperation if the given TupElement is of type Uint. ForUint(Uint) // ForBool performs the TupleOperation if the given TupElement is of type Bool. ForBool(Bool) // ForFloat performs the TupleOperation if the given TupElement is of type Float. ForFloat(Float) // ForString performs the TupleOperation if the given TupElement is of type String. ForString(String) // ForUUID performs the TupleOperation if the given TupElement is of type UUID. ForUUID(UUID) // ForBytes performs the TupleOperation if the given TupElement is of type Bytes. ForBytes(Bytes) // ForVariable performs the TupleOperation if the given TupElement is of type Variable. ForVariable(Variable) // ForMaybeMore performs the TupleOperation if the given TupElement is of type MaybeMore. ForMaybeMore(MaybeMore) }
type UUID ¶
type UUID [16]byte
UUID is a "primitive" type implementing a 16-byte string as either a TupElement or Value. When used as a Value, it's serialized as is.
func (UUID) TupElement ¶
func (x UUID) TupElement(op TupleOperation)
func (UUID) Value ¶
func (x UUID) Value(op ValueOperation)
type Uint ¶
type Uint uint64
Uint is a "primitive" type implementing a uint64 as either a TupElement or Value. When used as a Value, it's serialized as an 8-byte array. Endianness depends on how the [engine.Engine] is configured.
func (Uint) TupElement ¶
func (x Uint) TupElement(op TupleOperation)
func (Uint) Value ¶
func (x Uint) Value(op ValueOperation)
type Value ¶
type Value = value
Value may contain Tuple, Variable, Clear, or any of the "primitive" types.
type ValueOperation ¶
type ValueOperation interface { // ForTuple performs the ValueOperation if the given value is of type Tuple. ForTuple(Tuple) // ForNil performs the ValueOperation if the given value is of type Nil. ForNil(Nil) // ForInt performs the ValueOperation if the given value is of type Int. ForInt(Int) // ForUint performs the ValueOperation if the given value is of type Uint. ForUint(Uint) // ForBool performs the ValueOperation if the given value is of type Bool. ForBool(Bool) // ForFloat performs the ValueOperation if the given value is of type Float. ForFloat(Float) // ForString performs the ValueOperation if the given value is of type String. ForString(String) // ForUUID performs the ValueOperation if the given value is of type UUID. ForUUID(UUID) // ForBytes performs the ValueOperation if the given value is of type Bytes. ForBytes(Bytes) // ForVariable performs the ValueOperation if the given value is of type Variable. ForVariable(Variable) // ForClear performs the ValueOperation if the given value is of type Clear. ForClear(Clear) }
type ValueType ¶
type ValueType string
ValueType defines the expected types of a Variable.
const ( // AnyType designates a Variable to allow any value. // A Variable containing AnyType and an empty Variable // are equivalent. AnyType ValueType = "" // IntType designates a Variable to allow Int values. IntType ValueType = "int" // UintType designates a Variable to allow Uint values. UintType ValueType = "uint" // BoolType designates a Variable to allow Bool values. BoolType ValueType = "bool" // FloatType designates a Variable to allow Float values. FloatType ValueType = "float" // StringType designates a Variable to allow String values. StringType ValueType = "string" // BytesType designates a Variable to allow Bytes values. BytesType ValueType = "bytes" // UUIDType designates a Variable to allow UUID values. UUIDType ValueType = "uuid" // TupleType designates a Variable to allow Tuple values. TupleType ValueType = "tuple" )
type Variable ¶
type Variable []ValueType
Variable is a placeholder which implements the DirElement, TupElement, & Value interfaces. A Query containing a Variable defines a schema. When the Query is executed, all key-values (or directories) matching the schema are returned.
func (Variable) DirElement ¶
func (x Variable) DirElement(op DirectoryOperation)
func (Variable) TupElement ¶
func (x Variable) TupElement(op TupleOperation)
func (Variable) Value ¶
func (x Variable) Value(op ValueOperation)
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package class classifies a key-value by the kind of operation it represents.
|
Package class classifies a key-value by the kind of operation it represents. |
Package compare validates tuples against a schema.
|
Package compare validates tuples against a schema. |
Package convert converts between FDBQ and FDB types.
|
Package convert converts between FDBQ and FDB types. |
Operation generates the interfaces and glue-code for the visitor pattern.
|
Operation generates the interfaces and glue-code for the visitor pattern. |
Package values serializes and deserializes values.
|
Package values serializes and deserializes values. |