spec

package
v0.1.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 11, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// operations collection.
	BoolOps     = []Op{Eq, Neq}
	EnumOps     = append(BoolOps, In, NotIn)
	NumericOps  = append(EnumOps, Gt, Gte, Lt, Lte)
	StringOps   = append(NumericOps, Contains, StartsWith, EndsWith)
	NullableOps = []Op{IsNil, NotNil}
)

Functions

This section is empty.

Types

type Attribute

type Attribute interface {
	Name() string
	Value() any
}

Attribute represents an attribute definition.

type BinaryType

type BinaryType struct {
	Name string
	Size int
}

func (*BinaryType) GetName added in v0.1.2

func (b *BinaryType) GetName() string

func (*BinaryType) Kind

func (*BinaryType) Kind() string

func (*BinaryType) ProtobufKind

func (*BinaryType) ProtobufKind() string

type BitType

type BitType struct {
	Name string

	// Len indicates the Length of bits
	Len int
}

func (*BitType) GetName added in v0.1.2

func (b *BitType) GetName() string

func (*BitType) Kind

func (*BitType) Kind() string

func (*BitType) ProtobufKind

func (*BitType) ProtobufKind() string

type BoolType

type BoolType struct {
	Name string
}

func (*BoolType) GetName added in v0.1.2

func (b *BoolType) GetName() string

func (*BoolType) Kind

func (*BoolType) Kind() string

func (*BoolType) ProtobufKind

func (*BoolType) ProtobufKind() string

type EnumType

type EnumType struct {
	Name   string
	Values []string
}

func (*EnumType) GetName added in v0.1.2

func (e *EnumType) GetName() string

func (*EnumType) Kind

func (*EnumType) Kind() string

func (*EnumType) ProtobufKind

func (*EnumType) ProtobufKind() string

type Field

type Field struct {
	Name      string         `json:"name,omitempty"`
	Type      Type           `json:"type,omitempty"`
	Nullable  bool           `json:"nullable,omitempty"`
	Optional  bool           `json:"optional,omitempty"`
	Sensitive bool           `json:"sensitive,omitempty"`
	Tag       string         `json:"tag,omitempty"`
	Comment   string         `json:"comment,omitempty"`
	Default   sql.NullString `json:"default,omitempty"`
	Order     int            `json:"order,omitempty"`

	Alias      string `json:"alias,omitempty"`
	Sortable   bool   `json:"sortable,omitempty"`
	Filterable bool   `json:"filterable,omitempty"`

	ForeignKey    bool `json:"foreignKey,omitempty"`
	PrimaryKey    bool `json:"primaryKey,omitempty"`
	Index         bool `json:"index,omitempty"`
	Unique        bool `json:"unique,omitempty"`
	AutoIncrement bool `json:"autoIncrement,omitempty"`
	OnUpdate      bool `json:"onUpdate,omitempty"`
	Remote        bool `json:"remote,omitempty"`

	Rel   *Relation `json:"rel,omitempty"`
	Ops   []Op      `json:"ops,omitempty"`
	Table *Table    `json:"table,omitempty"`

	Attrs []Attribute `json:"attrs,omitempty"`
}

Field represents a Field definition.

func (*Field) RelBelongsTo

func (f *Field) RelBelongsTo() bool

RelBelongsTo returns true if the relation is belongsto

func (*Field) RelHasMany

func (f *Field) RelHasMany() bool

RelMany returns true if the relation is many

func (*Field) RelHasOne

func (f *Field) RelHasOne() bool

RelOne returns true if the relation is one

func (*Field) RelManyToMany

func (f *Field) RelManyToMany() bool

RelManyToMany returns true if the relation is many to many

func (*Field) RelNone

func (f *Field) RelNone() bool

RelNone returns true if the relation is none.

type FieldBuilder added in v0.1.2

type FieldBuilder struct {
	// contains filtered or unexported fields
}

FieldBuilder represents a field builder.

func Builder added in v0.1.2

func Builder(name string) *FieldBuilder

func (*FieldBuilder) Alias added in v0.1.2

func (fb *FieldBuilder) Alias(alias string) *FieldBuilder

func (*FieldBuilder) Attrs added in v0.1.2

func (fb *FieldBuilder) Attrs(attrs ...Attribute) *FieldBuilder

func (*FieldBuilder) AutoIncrement added in v0.1.2

func (fb *FieldBuilder) AutoIncrement(autoIncrement bool) *FieldBuilder

func (*FieldBuilder) Build added in v0.1.2

func (fb *FieldBuilder) Build() *Field

func (*FieldBuilder) Comment added in v0.1.2

func (fb *FieldBuilder) Comment(comment string) *FieldBuilder

func (*FieldBuilder) Default added in v0.1.4

func (fb *FieldBuilder) Default(d sql.NullString) *FieldBuilder

func (*FieldBuilder) Filterable added in v0.1.2

func (fb *FieldBuilder) Filterable(filterable bool) *FieldBuilder

func (*FieldBuilder) ForeignKey added in v0.1.2

func (fb *FieldBuilder) ForeignKey(foreignKey bool) *FieldBuilder

func (*FieldBuilder) Index added in v0.1.2

func (fb *FieldBuilder) Index(index bool) *FieldBuilder

func (*FieldBuilder) Nullable added in v0.1.2

func (fb *FieldBuilder) Nullable(nullable bool) *FieldBuilder

func (*FieldBuilder) OnUpdate added in v0.1.2

func (fb *FieldBuilder) OnUpdate(onUpdate bool) *FieldBuilder

func (*FieldBuilder) Ops added in v0.1.2

func (fb *FieldBuilder) Ops(ops []Op) *FieldBuilder

func (*FieldBuilder) Optional added in v0.1.2

func (fb *FieldBuilder) Optional(optional bool) *FieldBuilder

func (*FieldBuilder) PrimaryKey added in v0.1.2

func (fb *FieldBuilder) PrimaryKey(primaryKey bool) *FieldBuilder

func (*FieldBuilder) Rel added in v0.1.2

func (fb *FieldBuilder) Rel(rel *Relation) *FieldBuilder

func (*FieldBuilder) Remote added in v0.1.2

func (fb *FieldBuilder) Remote(remote bool) *FieldBuilder

func (*FieldBuilder) Sensitive added in v0.1.2

func (fb *FieldBuilder) Sensitive(sensitive bool) *FieldBuilder

func (*FieldBuilder) Sortable added in v0.1.2

func (fb *FieldBuilder) Sortable(sortable bool) *FieldBuilder

func (*FieldBuilder) Table added in v0.1.2

func (fb *FieldBuilder) Table(table *Table) *FieldBuilder

func (*FieldBuilder) Tag added in v0.1.2

func (fb *FieldBuilder) Tag(tag string) *FieldBuilder

func (*FieldBuilder) Type added in v0.1.2

func (fb *FieldBuilder) Type(t Type) *FieldBuilder

func (*FieldBuilder) Unique added in v0.1.2

func (fb *FieldBuilder) Unique(unique bool) *FieldBuilder

type FloatType

type FloatType struct {
	Name      string
	Precision int
	Scale     int
}

func (*FloatType) GetName added in v0.1.2

func (f *FloatType) GetName() string

func (*FloatType) Kind

func (f *FloatType) Kind() string

func (*FloatType) ProtobufKind

func (f *FloatType) ProtobufKind() string

type IntegerType

type IntegerType struct {
	Name     string
	Size     int
	Unsigned bool
}

func (*IntegerType) GetName added in v0.1.2

func (i *IntegerType) GetName() string

func (*IntegerType) Kind

func (i *IntegerType) Kind() string

func (*IntegerType) ProtobufKind

func (i *IntegerType) ProtobufKind() string

type JSONType

type JSONType struct {
	Name string
}

func (*JSONType) GetName added in v0.1.2

func (j *JSONType) GetName() string

func (*JSONType) Kind

func (*JSONType) Kind() string

func (*JSONType) ProtobufKind

func (*JSONType) ProtobufKind() string

type JoinTable

type JoinTable struct {
	Name         string `json:"name,omitempty"`
	JoinField    *Field `json:"join_field,omitempty"`
	JoinRefField *Field `json:"join_ref_field,omitempty"`
}

type ObjectType

type ObjectType struct {
	Name     string
	Exported bool
}

func (*ObjectType) GetName added in v0.1.2

func (o *ObjectType) GetName() string

func (*ObjectType) Kind

func (o *ObjectType) Kind() string

func (*ObjectType) ProtobufKind

func (o *ObjectType) ProtobufKind() string

type Op

type Op int
const (
	Unknown Op = iota
	Eq
	Neq
	In
	NotIn
	Gt
	Gte
	Lt
	Lte
	IsNil
	NotNil
	Contains
	StartsWith
	EndsWith
	AND
	OR
	NOT
)

func GetOP

func GetOP(name string) Op

func (Op) Name

func (o Op) Name() string

type RelType

type RelType uint8

RelType represents a relation type.

const (
	RelTypeNone RelType = iota
	RelTypeBelongsTo
	RelTypeHasOne
	RelTypeHasMany
	RelTypeManyToMany
)

func GetRelType

func GetRelType(name string) RelType

func (RelType) Name

func (r RelType) Name() string

type Relation

type Relation struct {
	Type      RelType     `json:"type,omitempty"`
	Field     *Field      `json:"field,omitempty"`
	RefTable  *Table      `json:"ref_table,omitempty"`
	RefField  *Field      `json:"ref_field,omitempty"`
	JoinTable *JoinTable  `json:"join_table,omitempty"`
	Inverse   bool        `json:"inverse,omitempty"`
	Attrs     []Attribute `json:"attrs,omitempty"`
}

Relation represents a Relation definition.

type Schema

type Schema struct {
	Name string

	Attrs []Attribute
	// contains filtered or unexported fields
}

Schema represents an schema definition.

func (*Schema) AddTables

func (s *Schema) AddTables(tables ...*Table)

AddTable adds a new table to the schema.

func (*Schema) JoinTable

func (s *Schema) JoinTable(name string) *Table

JoinTable returns the table with the given name.

func (*Schema) JoinTables

func (s *Schema) JoinTables() []*Table

JoinTables 返回所有关联表

func (*Schema) RemoveTable

func (s *Schema) RemoveTable(name string)

RemoveTable removes the table with the given name.

func (*Schema) Table

func (s *Schema) Table(name string) *Table

Table return the table with the given name.

func (*Schema) Tables

func (s *Schema) Tables() []*Table

Tables 返回非关联表的 Table 列表

type SpatialType

type SpatialType struct {
	Name string
}

func (*SpatialType) GetName added in v0.1.2

func (s *SpatialType) GetName() string

func (*SpatialType) Kind

func (s *SpatialType) Kind() string

func (*SpatialType) ProtobufKind

func (s *SpatialType) ProtobufKind() string

type StringType

type StringType struct {
	Name      string
	Size      int
	Charset   string
	Collation string
}

func (*StringType) GetName added in v0.1.2

func (s *StringType) GetName() string

func (*StringType) Kind

func (*StringType) Kind() string

func (*StringType) ProtobufKind

func (*StringType) ProtobufKind() string

type Table

type Table struct {
	Name    string
	Comment string

	ID    *Field
	Attrs []Attribute

	IsJoinTable bool
	JoinTable   *JoinTable

	Schema *Schema
	// contains filtered or unexported fields
}

Table represents a table definition.

func (*Table) AddFields

func (t *Table) AddFields(fields ...*Field)

AddField adds a new field to the table.

func (*Table) AutoIncrement added in v0.1.2

func (t *Table) AutoIncrement() bool

AutoIncrement returns true if the table has a auto increment primaryKey.

func (*Table) Fields

func (t *Table) Fields() []*Field

func (*Table) FilterFields

func (t *Table) FilterFields() []*Field

FilterFields returns the fields that is filterable.

func (*Table) GetField

func (t *Table) GetField(name string) *Field

GetField returns the field with the given name.

func (*Table) HasFilterField

func (t *Table) HasFilterField() bool

HasFilterField returns true if any field is filterable

func (*Table) HasParent

func (t *Table) HasParent() bool

HasParent returns true if the table has a parent table.

func (*Table) HasRelations added in v0.1.2

func (t *Table) HasRelations() bool

HasRelations returns true if the table has a relation table.

func (*Table) RemoveField

func (t *Table) RemoveField(name string)

RemoveField removes the field with the given name.

func (*Table) SortedFields added in v0.1.4

func (t *Table) SortedFields() []*Field

type TimeType

type TimeType struct {
	Name string
	Size int
}

func (*TimeType) GetName added in v0.1.2

func (t *TimeType) GetName() string

func (*TimeType) Kind

func (*TimeType) Kind() string

func (*TimeType) ProtobufKind

func (*TimeType) ProtobufKind() string

type Type

type Type interface {
	GetName() string
	Kind() string
	ProtobufKind() string
}

Type represents a field type definition.

type UUIDType added in v0.1.2

type UUIDType struct {
	Name    string
	Version string
}

func (*UUIDType) GetName added in v0.1.2

func (o *UUIDType) GetName() string

func (*UUIDType) Kind added in v0.1.2

func (*UUIDType) Kind() string

func (*UUIDType) ProtobufKind added in v0.1.2

func (*UUIDType) ProtobufKind() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL