schema

package
v0.0.0-...-9ed8f83 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2024 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SCHEMASKELLETON = `` /* 4697-byte string literal not displayed */

)

Variables

View Source
var (
	TOUPPER = map[string]string{
		"_a": "A",
		"_b": "B",
		"_c": "C",
		"_d": "D",
		"_e": "E",
		"_f": "F",
		"_g": "G",
		"_h": "H",
		"_i": "I",
		"_j": "J",
		"_k": "K",
		"_l": "L",
		"_m": "M",
		"_n": "N",
		"_o": "O",
		"_p": "P",
		"_q": "Q",
		"_r": "R",
		"_s": "S",
		"_t": "T",
		"_u": "U",
		"_v": "V",
		"_w": "W",
		"_x": "X",
		"_y": "Y",
		"_z": "Z",
		"_0": "0",
		"_1": "1",
		"_2": "2",
		"_3": "3",
		"_4": "4",
		"_5": "5",
		"_6": "6",
		"_7": "7",
		"_8": "8",
		"_9": "9",
	}
)

Functions

This section is empty.

Types

type Check

type Check struct {
	Name       string `json:"name"`
	Expression string `json:"expression"`
	Definition string `json:"definition"`
}

type Column

type Column struct {
	Name          string `json:"name"`
	Type          string `json:"type"`
	Unsigned      bool   `json:"unsigned"`
	Autoincrement bool   `json:"autoincrement"`
	Primary       bool   `json:"primary"`
	Nullable      bool   `json:"nullable"`
	Length        int    `json:"length,omitempty"`
	Default       string `json:"default,omitempty"`
	MappedType    string `json:"mappedType"`
	GormTag       string `json:"-"`
}

type Definition

type Definition struct {
	Namespaces []string `json:"namespaces"`
	Name       string   `json:"name"`
	Tables     []Row    `json:"tables"`
}

func NewDefinition

func NewDefinition(filename string) (*Definition, error)

func (*Definition) Generate

func (d *Definition) Generate(db *gorm.DB, modelDir string, migrationDir string) error

type Field

type Field struct {
	Name    string
	Type    string
	GormTag string
	JsonTag string
	Sql     string
}

type File

type File struct {
	Data      []byte
	Dir       string
	Version   string
	FileName  string
	Ext       string
	Print     bool
	CreatedAt time.Time
	// contains filtered or unexported fields
}

func LoadFile

func LoadFile(path string) (*File, error)

func NewFile

func NewFile(dir string, table *Table, version *Version, ext string) (*File, error)

func (*File) CreateFile

func (f *File) CreateFile() (err error)

func (*File) TimeVersion

func (f *File) TimeVersion(format string) error

func (*File) Unmarshal

func (f *File) Unmarshal(data any) error

func (*File) WithCreate

func (f *File) WithCreate(w func(w io.Writer) error) (err error)

func (*File) Write

func (f *File) Write(data any) error

type ForeignKey

type ForeignKey struct {
	ConstraintName        string   `json:"constraintName"`
	ColumnNames           []string `json:"columnNames"`
	LocalTableName        string   `json:"localTableName"`
	ReferencedColumnNames []string `json:"referencedColumnNames"`
	ReferencedTableName   string   `json:"referencedTableName"`
	DeleteRule            string   `json:"deleteRule"`
	UpdateRule            string   `json:"updateRule"`
}

type Index

type Index struct {
	KeyName     string   `json:"keyName"`
	ColumnNames []string `json:"columnNames"`
	Composite   bool     `json:"composite"`
	Primary     bool     `json:"primary"`
	Unique      bool     `json:"unique"`
	Expression  string   `json:"expression,omitempty"`
}

type Migrator

type Migrator struct {
	DB        *gorm.DB
	Tables    []*Table
	Relations map[string][]Relation
}

func NewMigrator

func NewMigrator() *Migrator

func (*Migrator) AddCheck

func (m *Migrator) AddCheck(t *Table, checks []Check)

func (*Migrator) AddColumn

func (m *Migrator) AddColumn(t *Table, columns map[string]Column)

func (*Migrator) AddForeignKey

func (m *Migrator) AddForeignKey(keys map[string]ForeignKey)

func (*Migrator) AddIndex

func (m *Migrator) AddIndex(t *Table, indexes []Index)

func (*Migrator) GetTabel

func (m *Migrator) GetTabel(name string) *Table

func (*Migrator) Schema

func (m *Migrator) Schema(path string) error

func (*Migrator) Sql

func (m *Migrator) Sql(path string) error

func (*Migrator) Tabel

func (m *Migrator) Tabel(row *Row) *Table

type Relation

type Relation struct {
	Name      string
	Type      string
	GormTag   string
	IsList    bool
	IsPointer bool
	Sql       string
}

type Row

type Row struct {
	Columns     map[string]Column     `json:"columns,omitempty"`
	Name        string                `json:"name"`
	Schema      string                `json:"schema"`
	Indexes     []Index               `json:"indexes,omitempty"`
	Checks      []Check               `json:"checks,omitempty"`
	ForeignKeys map[string]ForeignKey `json:"foreignKeys,omitempty"`
}

func (*Row) Down

func (r *Row) Down(migrator *Migrator) error

func (*Row) Migration

func (t *Row) Migration(migrator *Migrator) error

func (*Row) Up

func (r *Row) Up(migrator *Migrator)

type Structur

type Structur struct {
}

type Table

type Table struct {
	Name        string
	Fields      []*Field
	SqlFields   int
	ForeignKeys map[string]ForeignKey
	Sql         string
	CreatedAt   time.Time
	// contains filtered or unexported fields
}

func (*Table) AddCheck

func (t *Table) AddCheck(check Check)

func (*Table) AddColumn

func (t *Table) AddColumn(column Column, sqlString string)

func (*Table) AddIndex

func (t *Table) AddIndex(index Index)

func (*Table) AddRelation

func (t *Table) AddRelation(relation Relation)

func (*Table) DropCheck

func (t *Table) DropCheck(name string)

func (*Table) DropColumn

func (t *Table) DropColumn(name string)

func (*Table) DropIndex

func (t *Table) DropIndex(indexName string)

func (*Table) DropRelation

func (t *Table) DropRelation(name string)

type Version

type Version struct {
	Format    string
	Direction string
	Time      time.Time
}

Jump to

Keyboard shortcuts

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