Documentation
¶
Index ¶
- Constants
- Variables
- func GetSchemasFromDir(dir string) (map[string]*Schema, error)
- func NewRelationBackRefError(relation *Relation) error
- func NewRelationNodeError(schema *Schema, field *Field) error
- func UnmarshalJSONValue(data []byte, valueData []byte, dataType jsonparser.ValueType, offset int) (any, error)
- type Builder
- func (b *Builder) AddSchema(schema *Schema)
- func (b *Builder) Clone() *Builder
- func (b *Builder) CreateFKs() error
- func (b *Builder) CreateM2mJunctionSchema(currentSchema *Schema, r *Relation) (*Schema, bool, error)
- func (b *Builder) CreateRelations() (err error)
- func (b *Builder) Dir(dirs ...string) string
- func (b *Builder) Init() (err error)
- func (b *Builder) Relation(name string) *Relation
- func (b *Builder) Relations() []*Relation
- func (b *Builder) ReplaceSchema(name string, schema *Schema)
- func (b *Builder) SaveToDir(dir string) error
- func (b *Builder) Schema(name string) (*Schema, error)
- func (b *Builder) SchemaFile(name string) string
- func (b *Builder) Schemas() []*Schema
- type Entity
- func (e *Entity) Delete(name string) *Entity
- func (e *Entity) Empty() bool
- func (e *Entity) First() *orderedmap.Pair[string, any]
- func (e *Entity) Get(name string, defaultValues ...any) any
- func (e *Entity) GetString(name string, defaultValues ...string) string
- func (e *Entity) GetUint64(name string, optional bool) (uint64, error)
- func (e *Entity) ID() uint64
- func (e *Entity) MarshalJSON() ([]byte, error)
- func (e *Entity) Set(name string, value any) *Entity
- func (e *Entity) SetID(value any) error
- func (e *Entity) ToJSON() (string, error)
- func (e *Entity) ToMap() (map[string]any, error)
- func (e *Entity) UnmarshalJSON(data []byte) (err error)
- type Field
- type FieldDB
- type FieldEnum
- type FieldRenderer
- type FieldType
- type Relation
- func (r *Relation) Clone() *Relation
- func (r *Relation) CreateFKFields() error
- func (r *Relation) GetBackRefName() string
- func (r *Relation) GetFKColumns() *RelationFKColumns
- func (r *Relation) GetTargetFKColumn() string
- func (r *Relation) HasFKs() bool
- func (r *Relation) Init(schema *Schema, relationSchema *Schema, f *Field) *Relation
- func (r *Relation) IsBidi() bool
- func (r *Relation) IsSameType() bool
- type RelationFKColumns
- type RelationType
- type Schema
- type SchemaDB
- type SchemaDBIndex
Constants ¶
const FieldCreatedAt = "created_at"
const FieldDeletedAt = "deleted_at"
const FieldID = "id"
const FieldUpdatedAt = "updated_at"
Variables ¶
var MediaSchema = `` /* 1062-byte string literal not displayed */
var PermissionSchema = `` /* 823-byte string literal not displayed */
var RoleSchema = `` /* 1093-byte string literal not displayed */
var UserSchema = `` /* 1836-byte string literal not displayed */
Functions ¶
func NewRelationBackRefError ¶
func NewRelationNodeError ¶
func UnmarshalJSONValue ¶
func UnmarshalJSONValue(data []byte, valueData []byte, dataType jsonparser.ValueType, offset int) (any, error)
UnmarshalJSONValue converts json bytes to a Go value.
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder holds the schema of the database.
func NewBuilderFromDir ¶
NewBuilderFromDir creates a new schema from a directory.
func (*Builder) CreateM2mJunctionSchema ¶
func (*Builder) CreateRelations ¶
CreateRelations creates all relations between nodes
func (*Builder) Dir ¶
Dir returns the directory of the builder. If dirs is not empty, it will set the dir to the first element of dirs.
func (*Builder) ReplaceSchema ¶
ReplaceSchema replaces a schema
func (*Builder) SchemaFile ¶
SchemaFile returns the json file path of a schema
type Entity ¶
type Entity struct {
// contains filtered or unexported fields
}
Entity represents a single entity.
func NewEntityFromJSON ¶
NewEntityFromJSON creates a new entity from a JSON string.
func NewEntityFromMap ¶
NewEntityFromMap creates a new entity from a map.
func (*Entity) First ¶
func (e *Entity) First() *orderedmap.Pair[string, any]
First returns the oldest key/value pair in the entity.
func (*Entity) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (*Entity) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface.
type Field ¶
type Field struct {
Type FieldType `json:"type"`
Name string `json:"name"`
Label string `json:"label"`
IsMultiple bool `json:"multiple,omitempty"` // Is a multiple field.
Renderer *FieldRenderer `json:"renderer,omitempty"` // renderer of the field.
Size int64 `json:"size,omitempty"` // max size parameter for string, blob, etc.
Unique bool `json:"unique,omitempty"` // column with unique constraint.
Optional bool `json:"optional,omitempty"` // null or not null attribute.
Default any `json:"default,omitempty"` // default value.
Enums []*FieldEnum `json:"enums,omitempty"` // enum values.
Relation *Relation `json:"relation,omitempty"` // relation of the field.
DB *FieldDB `json:"db,omitempty"` // db config for the field.
// Querier
Sortable bool `json:"sortable,omitempty"` // Has a "sort" option in the tag.
Filterable bool `json:"filterable,omitempty"` // Has a "filter" option in the tag.
IsSystemField bool `json:"is_system_field,omitempty"` // Is a system field.
}
Field define the data struct for a field
func CreateUint64Field ¶
func (*Field) IsValidValue ¶
IsValidValue returns true if the value is valid for the column
type FieldDB ¶
type FieldDB struct {
Attr string `json:"attr,omitempty"` // extra attributes.
Collation string `json:"collation,omitempty"` // collation type (utf8mb4_unicode_ci, utf8mb4_general_ci)
Increment bool `json:"increment,omitempty"` // auto increment
Key string `json:"key,omitempty"` // key definition (PRI, UNI or MUL).
}
FieldDB define the db config for a field
type FieldRenderer ¶
type FieldRenderer struct {
Class string `json:"class,omitempty"` // renderer class name
Settings map[string]any `json:"settings,omitempty"` // renderer settings.
}
FieldRenderer define the renderer of a field
type FieldType ¶
type FieldType int
FieltType define the data type of a field
func (FieldType) IsRelationType ¶
func (FieldType) MarshalJSON ¶
MarshalJSON marshal an enum value to the quoted json string value
func (*FieldType) UnmarshalJSON ¶
UnmarshalJSON unmashals a quoted json string to the enum value
type Relation ¶
type Relation struct {
BackRef *Relation `json:"-"` // back reference relation
Name string `json:"-"` // relation name: auto generated
SchemaName string `json:"-"` // schema name: get from the current schema
FieldName string `json:"-"` // field name: get from the current field
TargetSchemaName string `json:"schema"` // target schema name
TargetFieldName string `json:"field,omitempty"` // target field name, aka the back reference field name
Type RelationType `json:"type"` // the relation type: o2o, o2m, m2m
Owner bool `json:"owner,omitempty"` // the relation owner: true, false
// FKColumns []string `json:"fk_columns"`
FKColumns *RelationFKColumns `json:"fk_columns"`
JunctionTable string `json:"junction_table,omitempty"` // junction table name for m2m relation
Optional bool `json:"optional"`
FKFields []*Field `json:"-"`
RelationSchemas []*Schema `json:"-"` // for m2m relation
JunctionSchema *Schema `json:"-"` // for m2m relation
}
Reation define the relation structure
func (*Relation) CreateFKFields ¶
CreateFKFields create the foreign key fields
func (*Relation) GetBackRefName ¶
GetBackRefName get the back reference name
func (*Relation) GetFKColumns ¶
func (r *Relation) GetFKColumns() *RelationFKColumns
func (*Relation) GetTargetFKColumn ¶
GetTargetFKColumn return the FK column name for o2m and o2o relation
func (*Relation) IsSameType ¶
IsSameType check if the relation is same type
type RelationFKColumns ¶
type RelationType ¶
type RelationType int
RelationType define the relation type of a field
const ( RelationInvalid RelationType = iota O2O O2M M2M )
func (RelationType) IsM2M ¶
func (t RelationType) IsM2M() bool
func (RelationType) IsO2M ¶
func (t RelationType) IsO2M() bool
func (RelationType) IsO2O ¶
func (t RelationType) IsO2O() bool
func (RelationType) MarshalJSON ¶
func (t RelationType) MarshalJSON() ([]byte, error)
MarshalJSON marshal an enum value to the quoted json string value
func (RelationType) String ¶
func (t RelationType) String() string
String returns the string representation of a type.
func (*RelationType) UnmarshalJSON ¶
func (t *RelationType) UnmarshalJSON(b []byte) error
UnmarshalJSON unmashals a quoted json string to the enum value
func (RelationType) Valid ¶
func (t RelationType) Valid() bool
Valid reports if the given type if known type.
type Schema ¶
type Schema struct {
Name string `json:"name"`
Namespace string `json:"namespace"`
LabelFieldName string `json:"label_field"`
DisableTimestamp bool `json:"disable_timestamp"`
Fields []*Field `json:"fields"`
IsSystemSchema bool `json:"is_system_schema,omitempty"`
IsJunctionSchema bool `json:"is_junction_schema,omitempty"`
DB *SchemaDB `json:"db,omitempty"`
// RelationsFKColumns map[string][]string `json:"-"`
DBColumns []string `json:"-"`
// contains filtered or unexported fields
}
Schema holds the node data.
func NewSchemaFromJSON ¶
NewSchemaFromJSON creates a new node from a json string.
func NewSchemaFromJSONFile ¶
NewSchemaFromJSONFile creates a new node from a json file.
func (*Schema) SaveToFile ¶
type SchemaDB ¶
type SchemaDB struct {
Indexes []*SchemaDBIndex `json:"indexes,omitempty"`
}