schema

package
v0.0.0-...-98c8ee3 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2019 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ColumnNames

func ColumnNames(cols []*Column) []string

ColumnNames of the Columns.

func FieldNames

func FieldNames(fields []*Field) []string

FieldNames of the fields.

Types

type BaseType

type BaseType interface {
	GetName() string
	GoType() GoType
	SQLType() SQLType
}

type BaseTypeNotNullable

type BaseTypeNotNullable struct {
	Name     string
	Go       GoType
	Postgres SQLType
}

func (*BaseTypeNotNullable) GetName

func (t *BaseTypeNotNullable) GetName() string

func (*BaseTypeNotNullable) GoType

func (t *BaseTypeNotNullable) GoType() GoType

func (*BaseTypeNotNullable) SQLType

func (t *BaseTypeNotNullable) SQLType() SQLType

type BaseTypeNullable

type BaseTypeNullable struct {
	Name     string
	Go       GoType
	GoNull   GoType
	Postgres SQLType
}

func (*BaseTypeNullable) GetName

func (t *BaseTypeNullable) GetName() string

func (*BaseTypeNullable) GoType

func (t *BaseTypeNullable) GoType() GoType

func (*BaseTypeNullable) GoTypeNull

func (t *BaseTypeNullable) GoTypeNull() GoType

func (*BaseTypeNullable) GoTypeNullField

func (t *BaseTypeNullable) GoTypeNullField() string

func (*BaseTypeNullable) SQLType

func (t *BaseTypeNullable) SQLType() SQLType

type Column

type Column struct {
	Name string
	Type Type

	SQLType    string
	SQLDefault string

	Nullable bool
}

Field holds information about a database field. Types are Go types, converted by TranslateFieldType.

func (*Column) GoType

func (c *Column) GoType() GoType

type Enum

type Enum struct {
	Name    string
	Choices []string
}

func (*Enum) GetName

func (e *Enum) GetName() string

func (*Enum) GoType

func (e *Enum) GoType() GoType

func (*Enum) GoTypeNull

func (e *Enum) GoTypeNull() GoType

func (*Enum) GoTypeNullField

func (e *Enum) GoTypeNullField() string

func (*Enum) SQLType

func (e *Enum) SQLType() SQLType

type Field

type Field struct {
	Name     string
	Type     Type
	Nullable bool

	Tags Tags
}

Field holds information about a database field. Types are Go types, converted by TranslateFieldType.

func (*Field) GenerateTags

func (f *Field) GenerateTags() string

func (*Field) GoType

func (f *Field) GoType() GoType

func (*Field) HasTag

func (f *Field) HasTag(tag string) bool

func (*Field) IsStruct

func (f *Field) IsStruct() bool

type ForeignKey

type ForeignKey struct {
	Model string
	Name  string

	Columns        []string
	ForeignModel   string
	ForeignColumns []string

	Nullable              bool
	Unique                bool
	ForeignColumnNullable bool
	ForeignColumnUnique   bool
}

ForeignKey represents a foreign key constraint in a database

func (*ForeignKey) Column

func (f *ForeignKey) Column() string

func (*ForeignKey) ForeignColumn

func (f *ForeignKey) ForeignColumn() string

type GoType

type GoType struct {
	Pkg  string
	Name string
}

type Index

type Index struct {
	Name    string
	Columns []string
}

Index represents an index in a database

type Model

type Model struct {
	Name    string
	Fields  []*Field
	Columns []*Column

	PrimaryKey  *PrimaryKey
	Indexes     []*Index
	Uniques     []*Unique
	ForeignKeys []*ForeignKey

	IsJoinModel bool

	ToOneRelationships  []*ToOneRelationship
	ToManyRelationships []*ToManyRelationship
}

Model metadata from the database schema.

func GetModel

func GetModel(models []*Model, name string) (tbl *Model)

GetModel by name. Panics if not found (for use in templates mostly).

func (*Model) DeleteColumn

func (t *Model) DeleteColumn(name string)

DeleteColumn by name. does nothing if not found.

func (*Model) DeleteForeignKey

func (t *Model) DeleteForeignKey(name string)

DeleteForeignKey by name. does nothing if not found.

func (*Model) DeleteIndex

func (t *Model) DeleteIndex(name string)

DeleteIndex by name. does nothing if not found.

func (*Model) DeleteUnique

func (t *Model) DeleteUnique(name string)

DeleteUnique by name. does nothing if not found.

func (*Model) FindColumn

func (t *Model) FindColumn(name string) *Column

FindColumn by name. Returns nil if not found.

func (*Model) FindField

func (t *Model) FindField(name string) (col *Field)

FindField by name. Returns nil if not found (for use in templates mostly).

func (*Model) FindForeignKey

func (t *Model) FindForeignKey(name string) *ForeignKey

FindForeignKey by name. Returns nil if not found.

func (*Model) FindIndex

func (t *Model) FindIndex(name string) *Index

FindIndex by name. Returns nil if not found.

func (*Model) FindUnique

func (t *Model) FindUnique(name string) *Unique

FindUnique by name. Returns nil if not found.

func (*Model) GetColumn

func (t *Model) GetColumn(name string) *Column

GetColumn by name. Returns nil if not found.

func (*Model) GetField

func (t *Model) GetField(name string) (col *Field)

GetField by name. Panics if not found (for use in templates mostly).

func (*Model) IsUniqueColumn

func (t *Model) IsUniqueColumn(name string) bool

func (*Model) SingleColumnForeignKeys

func (m *Model) SingleColumnForeignKeys() []*ForeignKey

type NullableType

type NullableType interface {
	GetName() string
	GoType() GoType
	GoTypeNull() GoType
	GoTypeNullField() string
}

type PrimaryKey

type PrimaryKey struct {
	Columns []string
}

PrimaryKey represents a primary key in a database

type SQLColumnDef

type SQLColumnDef struct {
	Name string
	Type GoType
}

SQLColumnDef formats a field name and type like an SQL field definition.

func (SQLColumnDef) String

func (s SQLColumnDef) String() string

String for fmt.Stringer

type SQLColumnDefs

type SQLColumnDefs []SQLColumnDef

SQLColumnDefs has small helper functions

func SQLColDefinitions

func SQLColDefinitions(cols []*Column, names []string) SQLColumnDefs

SQLColDefinitions creates a definition in sql format for a field

func (SQLColumnDefs) Names

func (s SQLColumnDefs) Names() []string

Names returns all the names

func (SQLColumnDefs) Types

func (s SQLColumnDefs) Types() []GoType

Types returns all the types

type SQLType

type SQLType struct {
	Type      string
	ZeroValue string
}

type Schema

type Schema struct {
	Types  map[string]Type
	Models map[string]*Model
}

func New

func New() *Schema

func (*Schema) CalculateRelationships

func (s *Schema) CalculateRelationships()

type Struct

type Struct struct {
	Name   string
	Fields []*Field
}

func (*Struct) GetName

func (s *Struct) GetName() string

func (*Struct) GoType

func (s *Struct) GoType() GoType

func (*Struct) GoTypeNull

func (s *Struct) GoTypeNull() GoType

func (*Struct) GoTypeNullField

func (s *Struct) GoTypeNullField() string

type Tags

type Tags map[string]string

Tags represent a set of tags from a single struct field

func (Tags) String

func (t Tags) String() string

type ToManyRelationship

type ToManyRelationship struct {
	Model    string
	Column   string
	Nullable bool
	Unique   bool

	ForeignModel          string
	ForeignColumn         string
	ForeignColumnNullable bool
	ForeignColumnUnique   bool

	ToJoinModel bool
	JoinModel   string

	JoinLocalColumn         string
	JoinLocalColumnNullable bool
	JoinLocalColumnUnique   bool

	JoinForeignColumn         string
	JoinForeignColumnNullable bool
	JoinForeignColumnUnique   bool
}

ToManyRelationship describes a relationship between two models where the local model has no id, and the foreign model has an id that matches a field in the local model.

type ToOneRelationship

type ToOneRelationship struct {
	Model    string
	Column   string
	Nullable bool
	Unique   bool

	ForeignModel          string
	ForeignColumn         string
	ForeignColumnNullable bool
	ForeignColumnUnique   bool
}

ToOneRelationship describes a relationship between two models where the local model has no id, and the foregin model has an id that matches a field in the local model, that field is also unique which changes the dynamic into a one-to-one style, not a to-many.

type Type

type Type interface {
	GetName() string
	GoType() GoType
}

type Unique

type Unique struct {
	Name    string
	Columns []string
}

Unique represents a unique constraint in a database

Jump to

Keyboard shortcuts

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