Documentation ¶
Index ¶
- Constants
- func DecodeEntity(e Entity, dst interface{}) error
- func InternalType(v interface{}) (interface{}, error)
- func IsAllowedType(c ColumnType) bool
- func SetPrimary(id Key, dst interface{}) error
- type Binary
- type Bool
- type Column
- func (c Column) BoolOption(key string) (b bool, found bool)
- func (c Column) Equals(other *Column) bool
- func (c Column) GoName() string
- func (c Column) HasDefault() bool
- func (c Column) IntOption(key string) (i int, found bool)
- func (c Column) StringOption(key string) (s string, found bool)
- func (c *Column) Validate() error
- type ColumnAddedChange
- type ColumnAlterChange
- type ColumnDeletedChange
- type ColumnType
- type Decoder
- type DefaultTextNormalizer
- type Deployer
- type Encoder
- type Entity
- type FilesDeployer
- type FilesProvider
- type Float
- type Index
- type IndexAddedChange
- type IndexRemovedChange
- type IndexState
- type IndexType
- type Int
- type Key
- type List
- type Map
- type Property
- type PropertyMap
- type RawDecoder
- type RawEncoder
- type Schema
- type SchemaChange
- type SchemaProvider
- type Set
- type StringProvider
- type Table
- type TableAddedChange
- type TableDeletedChange
- type Text
- type TextNormalizer
- type Timestamp
- type Tokenizer
- type Transcoder
- type Uint
- type Value
Constants ¶
const ( Tag = "db" DefaultTag = "default" )
const ( RedisEngine = "redis" MysqlEngine = "mysql" CassandraEngine = "cassandra" )
const ( OptSubType = "subtype" OptRequired = "required" OptMaxLen = "max_len" )
const ListBson = "__MDZL__"
const NilValue = "{NIL}"
const SetBson = "__MDZS__"
Variables ¶
This section is empty.
Functions ¶
func DecodeEntity ¶
MapEntity takes an entity and a pointer to a mapped object, and maps the entity's properties into the object's fields. Note that dst must be a pointer to a struct, anything else will fail
func InternalType ¶
func InternalType(v interface{}) (interface{}, error)
InternalType takes an arbitrary object and maps it to the internal db type matching it
func IsAllowedType ¶
func IsAllowedType(c ColumnType) bool
IsAllowedType returns true if a given type string is in the our allowed types list
func SetPrimary ¶
SetPrimary puts a primary id into a model object's primary field. dst must be a non nil pointer to a struct for this to work
Types ¶
type Column ¶
type Column struct { Name string `yaml:"name"` ClientName string `yaml:"clientName"` Type ColumnType `yaml:"type"` Default interface{} `yaml:"default,omitempty"` Comment string `yaml:"comment,omitempty"` Options map[string]interface{} `yaml:"options,omitempty"` // Admin Options AdminOptions struct { // If true - we do not show this column in forms Hidden bool `yaml:"hidden,omitempty"` // if true - we set a readonly property in the admin for this column ReadOnly bool `yaml:"readonly,omitempty"` // If set - mark the form ordering priority of this column in the admin form Priority int `yaml:"priority,omitempty"` // If set - specify a custom format for the admin (date, location, markdown, etc) // see https://github.com/jdorn/json-editor#format Format string `yaml:"format,omitempty"` } `yaml:"adminOptions,omitempty"` }
Column describes a column in a table, if we are talking about a strict schema
func (Column) HasDefault ¶
type ColumnAddedChange ¶
type ColumnAddedChange struct { SchemaChange Column *Column }
type ColumnAlterChange ¶
type ColumnAlterChange struct { SchemaChange Column *Column }
type ColumnDeletedChange ¶
type ColumnDeletedChange struct { SchemaChange Column *Column }
type ColumnType ¶
type ColumnType string
const ( IntType ColumnType = "Int" UintType ColumnType = "Uint" FloatType ColumnType = "Float" TextType ColumnType = "Text" BoolType ColumnType = "Bool" TimestampType ColumnType = "Timestamp" BinaryType ColumnType = "Binary" SetType ColumnType = "Set" ListType ColumnType = "List" MapType ColumnType = "Map" UnknownType ColumnType = "" )
data types
func TypeOf ¶
func TypeOf(v interface{}) ColumnType
TypeOf returns the ColumnType representation of an internal data type variable. If the variable is not of any internal type, we return UnknownType
type Decoder ¶
type Decoder interface {
Decode(value []byte, tp ColumnType) (interface{}, error)
}
type DefaultTextNormalizer ¶
func NewNormalizer ¶
func NewNormalizer(locale language.Tag, removeAccents, removePunct bool) *DefaultTextNormalizer
func (*DefaultTextNormalizer) Normalize ¶
func (d *DefaultTextNormalizer) Normalize(input []byte) (ret string, err error)
func (*DefaultTextNormalizer) NormalizeString ¶
func (d *DefaultTextNormalizer) NormalizeString(input string) (string, error)
type Entity ¶
type Entity struct { Id Key `bson:"id"` Properties PropertyMap `bson:"properties"` TTL time.Duration `bson:"ttl"` }
func EncodeStruct ¶
EncodeStruct takes a model struct and encodes it into an entity. The struct must have a primary field, and cannot be nil
type FilesDeployer ¶
type FilesDeployer struct {
// contains filtered or unexported fields
}
func NewFileDeployer ¶
func NewFileDeployer(rootDir string) FilesDeployer
type FilesProvider ¶
type FilesProvider struct {
// contains filtered or unexported fields
}
FilesProvider is a simple schema provider that reads static files in a directory, and monitors this directory for changes in files. If it finds a changed file, it re-reads it and issues an update
func NewFilesProvider ¶
func NewFilesProvider(root string) *FilesProvider
NewFilesProvider creates a files based provider listening on schema files inside root
func (*FilesProvider) Init ¶
func (p *FilesProvider) Init() error
Init reads all the schema files in the root directory.
NOTE: It raises an error only if reading the directory is empty. It can behave as if everything is normal even if ALL the schema files in the directory are bad
func (*FilesProvider) Schemas ¶
func (p *FilesProvider) Schemas() []*Schema
Schemas returns a list of all the schemas in the root directory
func (*FilesProvider) Updates ¶
func (p *FilesProvider) Updates() (<-chan *Schema, error)
Updates starts monitoring the root dir for changes. Any changed or new schema is returned through the updates channel. Drivers can diff it by name with its older version to tell what changes had been made to it
type Index ¶
type Index struct { Name string `yaml:"name"` Columns []string `yaml:"columns,omitempty"` Type IndexType `yaml:"type"` State IndexState `yaml:"-"` ExtraParams map[string]interface{} `yaml:"options,omitempty"` }
Index provides a description of an index, to be used by the specific driver
type IndexAddedChange ¶
type IndexAddedChange struct { SchemaChange Index *Index }
type IndexRemovedChange ¶
type IndexRemovedChange struct { SchemaChange Index *Index }
type IndexState ¶
type IndexState int8
const ( IndexReady IndexState = 1 IndexPending IndexState = 2 IndexGarbage IndexState = 3 )
type IndexType ¶
type IndexType string
const ( IdKey = "id" // Index type specds SimpleIndex IndexType = "simple" CompoundIndex IndexType = "compound" SortedIndex IndexType = "sorted" GeoIndex IndexType = "geo" FullTextIndex IndexType = "fulltext" // primary index types PrimaryRandom IndexType = "random" PrimaryCompound IndexType = "compound" )
type List ¶
type List []interface{} //
func (List) MarshalBson ¶
func (l List) MarshalBson(buf *bytes2.ChunkedWriter, key string)
type PropertyMap ¶
type PropertyMap map[string]interface{}
func (PropertyMap) UnmarshalBson ¶
func (p PropertyMap) UnmarshalBson(buf *bytes.Buffer, kind byte)
UnmarshalBson overrieds the default unmarshaling of a map, to allow us to extract our internal types
type RawDecoder ¶
type RawDecoder struct { }
RawDecoder taekes a raw byte array and type information and decodes them
func (RawDecoder) Decode ¶
func (d RawDecoder) Decode(value []byte, tp ColumnType) (interface{}, error)
type RawEncoder ¶
type RawEncoder struct{}
func (RawEncoder) Encode ¶
func (c RawEncoder) Encode(v interface{}) ([]byte, error)
type Schema ¶
Schema describes a database and all its tables
func Load ¶
Load reads a schema from a reader and validates it. Returns the loaded schema if it was okay or an error if it wasn't
type SchemaChange ¶
type SchemaChange struct {
Table *Table
}
type SchemaProvider ¶
type SchemaProvider interface { Init() error Schemas() []*Schema Updates() (<-chan *Schema, error) Stop() }
SchemaProvider is an interface for drivers, letting them access schema definitions, and notifying them about schema changes in real time
type Set ¶
type Set map[interface{}]struct{}
func NewSet ¶
func NewSet(elements ...interface{}) Set
NewSet creates a new set from a list of elements
func NewSetFromMap ¶
func NewSetFromMap(m map[interface{}]struct{}) Set
func (Set) MarshalBson ¶
func (s Set) MarshalBson(buf *bytes2.ChunkedWriter, key string)
MarshalBson overrides the vitess library's marshaling for set objects
func (Set) MarshalJSON ¶
MarshalBson encodes a timestamp property as a Bson time
type StringProvider ¶
type StringProvider struct {
// contains filtered or unexported fields
}
StringProvider wraps a schema string (mainly used for testing) in a provider. It does NOT provide any updates and does not support multiple schemata
func NewStringProvider ¶
func NewStringProvider(sc string) *StringProvider
NewStringProvider wraps the schema in sc in a provider
func (*StringProvider) Init ¶
func (p *StringProvider) Init() error
Init loads the schema string into the provider, reporting an error if it is a bad one
func (StringProvider) Schemas ¶
func (p StringProvider) Schemas() []*Schema
Schemas returns a one-sized slice of schemas containing our parsed string schema
func (StringProvider) Updates ¶
func (StringProvider) Updates() (<-chan *Schema, error)
Updates does nothing in this provider and returns nil
type Table ¶
type Table struct { Name string `yaml:"-"` BaseName string `yaml:"name"` Comment string `yaml:"comment,omitempty"` Class string `yaml:"class,omitempty"` // the generated class name, leave empty for the same as Name Engines []string `yaml:"engines,omitempty"` // If the table is not strict, we do not enforce a schema, and are just aware // of indexed columns. // You could use the schema for reference only Strict bool Columns map[string]*Column `yaml:"columns,omitempty"` Indexes []*Index `yaml:"indexes,omitempty"` Primary *Index `yaml:"primary"` AdminOptions struct { ListColumns []string `yaml:"listColumns,omitempty"` SearchBy []string `yaml:"searchBy,omitempty"` } `yaml:"adminOptions,omitempty"` }
Table describes a table in the database, with its columns (optional) and indexes
func (*Table) AddColumn ¶
func (t *Table) AddColumn(name string, tp ColumnType, def interface{}, comment string) error
AddColumn adds a column to the table, or returns an error if this column already exists
func (*Table) AddColumnQuick ¶
func (t *Table) AddColumnQuick(name string, tp ColumnType) error
AddColumn adds a column to the table, or returns an error if this column already exists
type TableAddedChange ¶
type TableAddedChange struct {
SchemaChange
}
type TableDeletedChange ¶
type TableDeletedChange struct {
SchemaChange
}
type Text ¶
type Text string //
func (Text) MarshalBson ¶
func (t Text) MarshalBson(buf *bytes2.ChunkedWriter, key string)
MarshalBson overrides the vitess library's marshaling of strings that encodes strings as binary
type TextNormalizer ¶
type Timestamp ¶
func (Timestamp) MarshalBson ¶
func (t Timestamp) MarshalBson(buf *bytes2.ChunkedWriter, key string)
MarshalBson encodes a timestamp property as a Bson time
func (Timestamp) MarshalJSON ¶
MarshalBson encodes a timestamp property as a Bson time
type Transcoder ¶
type Transcoder interface {
Transcode([]byte, ColumnType) ([]byte, error)
}