schema

package
v1.8.94 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SchemaTypeMySQL      = "mysql"
	SchemaTypePostgreSQL = "postgresql"
	SchemaTypeSQLServer  = "sqlserver"
)
View Source
const (
	RenameTable        = "RENAME_TABLE"
	CreateTable        = "CREATE_TABLE"
	DropTable          = "DROP_TABLE"
	ChangeColumn       = "CHANGE_COLUMN"
	AddColumn          = "ADD_COLUMN"
	DropColumn         = "DROP_COLUMN"
	AddIndex           = "ADD_INDEX"
	DropIndex          = "DROP_INDEX"
	ChangeCharacterSet = "CHANGE_CHARACTER_SET"
)

Variables

This section is empty.

Functions

func DataTypeToFormatString

func DataTypeToFormatString(column *Column) (fieldType string)

DataTypeToFormatString converts a database type to its equivalent golang datatype TODO move to mysql specific TODO make column types constants in mysql

func DataTypeToGoTypeString

func DataTypeToGoTypeString(column *Column) (fieldType string)

DataTypeToGoTypeString converts a database type to its equivalent golang datatype

func DataTypeToTypescriptDefault added in v1.8.45

func DataTypeToTypescriptDefault(dataType string) (fieldType string)

TODO move to mysql specific TODO make column types constants in mysql

func DataTypeToTypescriptString added in v1.8.19

func DataTypeToTypescriptString(dbDataType string) (fieldType string)

TODO move to mysql specific TODO make column types constants in mysql

func ExtractBaseGoType added in v1.8.67

func ExtractBaseGoType(goDataType string) string

func GoBaseTypeToBaseTypescriptDefault added in v1.8.67

func GoBaseTypeToBaseTypescriptDefault(goDataType string) string

func GoBaseTypeToBaseTypescriptType added in v1.8.67

func GoBaseTypeToBaseTypescriptType(goDataType string) string

func GoTypeFormatString added in v1.7.7

func GoTypeFormatString(goType string) (fieldType string)

DataTypeToFormatString converts a database type to its equivalent golang datatype

func GoTypeToTypescriptDefault added in v1.8.48

func GoTypeToTypescriptDefault(goDataType string) (fieldType string)

func GoTypeToTypescriptString added in v1.8.48

func GoTypeToTypescriptString(goDataType string) string

func IsGoTypeBaseType added in v1.8.67

func IsGoTypeBaseType(goDataType string) bool

func IsNull added in v1.8.89

func IsNull(fieldType string) bool

IsNull returns true if the field uses the `null` package

func IsString

func IsString(column *Column) bool

TODO move to mysql specific TODO make column types constants in mysql

func IsValidSQLType

func IsValidSQLType(str string) bool

DataTypeToGoTypeString converts a database type to its equivalent golang datatype

func ParseMapTypeToTypescriptString added in v1.8.74

func ParseMapTypeToTypescriptString(goDataType string) string

Types

type Column

type Column struct {
	Name string `json:"column"`
	// Position     int    `json:"position"`
	Default      string `json:"default"`
	IsNullable   bool   `json:"isNullable"`
	IsUnsigned   bool   `json:"isUnsigned"`
	DataType     string `json:"dataType"`
	MaxLength    int    `json:"maxLength"`
	Precision    int    `json:"precision"`
	CharSet      string `json:"charSet"`
	Collation    string `json:"collation"`
	Type         string `json:"type"`
	ColumnKey    string `json:"columnKey"`
	NumericScale int    `json:"numericScale"`
	Extra        string `json:"extra"`
	FmtType      string `json:"fmtType"`
	GoType       string `json:"goType"`
	IsString     bool   `json:"isString"`
}

Column represents a column in a table

type ColumnWithTable

type ColumnWithTable struct {
	*Column
	TableName string
}

ColumnWithTable is a column with the table name included

type Database added in v1.8.48

type Database struct {
	RunID               int64                               `json:"-"`
	Name                string                              `json:"name"`
	SortedSetKeys       []string                            `json:"-"`
	Tables              map[string]*Table                   `json:"tables"`
	Enums               map[string][]map[string]interface{} `json:"-"`
	DefaultCharacterSet string                              `json:"defaultCharacterSet"`
	DefaultCollation    string                              `json:"defaultCollation"`
}

Database represents a database

func (*Database) ToSchema added in v1.8.48

func (d *Database) ToSchema(schemaName string) *Schema

type Schema

type Schema struct {
	RunID               int64                               `json:"-"`
	Name                string                              `json:"name"`
	SortedSetKeys       []string                            `json:"-"`
	Tables              map[string]*Table                   `json:"tables"`
	Enums               map[string][]map[string]interface{} `json:"-"`
	DefaultCharacterSet string                              `json:"defaultCharacterSet"`
	DefaultCollation    string                              `json:"defaultCollation"`
}

Schema represents a database structure

func (*Schema) FindTableByName

func (s *Schema) FindTableByName(tableName string) (table *Table, e error)

FindTableByName finds a table by its name in the database

func (*Schema) ToSortedTables

func (s *Schema) ToSortedTables() SortedTables

ToSortedTables returns SortedTables

type SchemaChange

type SchemaChange struct {
	Type          string
	SQL           string
	IsDestructive bool
}

type SchemaComparison

type SchemaComparison struct {
	Database    string
	DatabaseKey string
	Additions   int
	Alterations int
	Deletions   int
	Changes     []*SchemaChange
}

type SchemaList

type SchemaList struct {
	Schemas  []*Schema           `json:"schemas"`
	TableMap map[string]struct{} `json:"-"`
}

func LoadLocalSchemas

func LoadLocalSchemas() (*SchemaList, error)

loadDatabase loads a database from configuration

type Server

type Server struct {
	Name            string `json:"name"`
	Host            string `json:"host"`
	Databases       map[string]*Schema
	Connection      *sql.DB
	CurrentDatabase string
}

Server represents a server

func (*Server) SchemaExists

func (s *Server) SchemaExists(schemaName string) bool

SchemaExists checks if the database `databaseName` exists in its list of databases

type SortedColumns

type SortedColumns []*Column

SortedColumns is a slice of Column objects

func (SortedColumns) Len

func (c SortedColumns) Len() int

Len is part of sort.Interface.

func (SortedColumns) Less

func (c SortedColumns) Less(i, j int) bool

Less is part of sort.Interface. We use count as the value to sort by

func (SortedColumns) Swap

func (c SortedColumns) Swap(i, j int)

Swap is part of sort.Interface.

type SortedTables

type SortedTables []*Table

SortedTables is a slice of Table objects

func (SortedTables) Len

func (c SortedTables) Len() int

Len is part of sort.Interface.

func (SortedTables) Less

func (c SortedTables) Less(i, j int) bool

Less is part of sort.Interface. We use count as the value to sort by

func (SortedTables) Swap

func (c SortedTables) Swap(i, j int)

Swap is part of sort.Interface.

type Table

type Table struct {
	Name          string             `json:"name"`
	Engine        string             `json:"engine"`
	Version       int                `json:"version"`
	RowFormat     string             `json:"rowFormat"`
	Rows          int64              `json:"-"`
	DataLength    int64              `json:"-"`
	Collation     string             `json:"collation"`
	CharacterSet  string             `json:"characterSet"`
	AutoIncrement int64              `json:"-"`
	Columns       map[string]*Column `json:"columns"`
	SchemaName    string
}

Table represents a table in a database

func (*Table) Key added in v1.8.91

func (table *Table) Key() string

func (*Table) ToSortedColumns

func (table *Table) ToSortedColumns() SortedColumns

ToSortedColumns returns SortedColumns

Jump to

Keyboard shortcuts

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