Documentation
¶
Overview ¶
Package schema contains utility functions for relating Go types and Beam Schemas.
Not all Go types can be converted to schemas. This is Go is more expressive than Beam schemas. Just as not all Go types can be serialized, similarly, not all Beam Schemas will have a conversion to Go types, until the correct mechanism exists in the SDK to handle them.
While efforts will be made to have conversions be reversable, this will not be possible in all instances. Eg. Go arrays as fields will be converted to Beam Arrays, but a Beam Array type will map by default to a Go slice.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FromType ¶
FromType returns a Beam Schema of the passed in type. Returns an error if the type cannot be converted to a Schema.
func RegisterLogicalType ¶
func RegisterLogicalType(lt LogicalType)
RegisterLogicalType registers a logical type with the beam schema system. A logical type is a type that has distinct representations and storage.
RegisterLogicalType will panic if the storage type of the LogicalType instance is not a valid storage type.
func RegisterType ¶
RegisterType converts the type to it's schema representation, and converts it back to a synthetic type so we can map from the synthetic type back to the user type. Recursively registers other named struct types in any component parts.
func Registered ¶
Registered returns whether the given type has been registered with the schema package.
Types ¶
type LogicalType ¶
type LogicalType interface { ID() string ArgumentType() reflect.Type ArgumentValue() reflect.Value GoType() reflect.Type StorageType() reflect.Type // ToStorageType converts an instance of the Go type to the schema storage type. ToStorageType(input reflect.Value) reflect.Value // ToGoType converts an instance of the given schema storage type to the Go type. ToGoType(base reflect.Value) reflect.Value }
LogicalType is an interface between custom Go types, and schema storage types.
A LogicalType is a way to define a new type that can be stored in a schema field using a known underlying type for storage. The storage type must be comprised of known schema field types, or pre-registered LogicalTypes. LogicalTypes may not be mutually recursive at any level of indirection.
func NewConvertibleLogicalType ¶
func NewConvertibleLogicalType(identifier string, goType, storageType reflect.Type) LogicalType
NewConvertibleLogicalType creates a LogicalType where the go type and storage representation can be converted between each other with reflect.Value.Convert.