models

package
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2020 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ColumnDescriptor

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

ColumnDescriptor - metadata of a column in an entity model

func NewSchemaColumn

func NewSchemaColumn(name string, dbtype string, isprimarykey bool, isautoincrement bool, isunique bool, isnotnull bool, defaultvalue string) *ColumnDescriptor

NewSchemaColumn creates a new SchemaColumn

**Parameters**

  • name: name of column
  • dbtype: database type of column
  • isprimarykey: determines whether column in a primary key
  • isautoincrement: determines whether column has auto increment flag
  • isunique: determines whether values of column have to be unique
  • isnotnull: determines whether values of column are not allowed to contain null values
  • defaultvalue: default value of column if no value is specified in insert statement

**Returns**

  • *SchemaColumn: created column information

func (*ColumnDescriptor) DBType

func (column *ColumnDescriptor) DBType() string

func (*ColumnDescriptor) DataType

func (column *ColumnDescriptor) DataType() reflect.Type

func (*ColumnDescriptor) DefaultValue

func (column *ColumnDescriptor) DefaultValue() string

func (*ColumnDescriptor) Field

func (column *ColumnDescriptor) Field() string

func (*ColumnDescriptor) HasDefault

func (column *ColumnDescriptor) HasDefault() bool

HasDefault determines whether column has a default value

**Returns**

  • bool: true when column has a default value, false otherwise

func (*ColumnDescriptor) IsAutoIncrement

func (column *ColumnDescriptor) IsAutoIncrement() bool

func (*ColumnDescriptor) IsNotNull

func (column *ColumnDescriptor) IsNotNull() bool

func (*ColumnDescriptor) IsPrimaryKey

func (column *ColumnDescriptor) IsPrimaryKey() bool

func (*ColumnDescriptor) IsUnique

func (column *ColumnDescriptor) IsUnique() bool

func (*ColumnDescriptor) Name

func (column *ColumnDescriptor) Name() string

type EntityModel

type EntityModel struct {
	Table string
	// contains filtered or unexported fields
}

EntityModel - model of an entity in a database

func CreateModel

func CreateModel(entitytype reflect.Type) *EntityModel

CreateModel - creates a new entity model for a type

func CreateModelWithTable added in v0.2.7

func CreateModelWithTable(entitytype reflect.Type, table string) *EntityModel

CreateModelWithTable - creates a new entity model for a type

func CreateViewModel

func CreateViewModel(entitytype reflect.Type, statement string) *EntityModel

CreateViewModel creates an entity model with a view as source

**Parameters**

  • entitytype: type of entity reflected by view
  • statement: operation providing command text of view

**Returns**

  • *EntityModel: created entity model

func (*EntityModel) Column

func (model *EntityModel) Column(columnname string) *ColumnDescriptor

Column - provides access to a column descriptor by column name

func (*EntityModel) ColumnFromField

func (model *EntityModel) ColumnFromField(fieldname string) *ColumnDescriptor

ColumnFromField - provides access to a column descriptor by field name

func (*EntityModel) Columns

func (model *EntityModel) Columns() []*ColumnDescriptor

Columns - access to all columns in model

func (*EntityModel) EntityType

func (model *EntityModel) EntityType() reflect.Type

EntityType - get entity type information used to create model

func (*EntityModel) Indices

func (model *EntityModel) Indices() []*IndexDescriptor

Indices index definitions of entity model

**Returns**

  • []*IndexDescriptor: index definitions

func (*EntityModel) Uniques

func (model *EntityModel) Uniques() []*IndexDescriptor

Uniques index definitions of entity model

**Returns**

  • []*IndexDescriptor: index definitions

func (*EntityModel) ViewSQL

func (model *EntityModel) ViewSQL() string

ViewSQL sql used to create view

**Returns**

  • string: view sql string

type IndexDescriptor

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

IndexDescriptor database description of an index

func NewIndexDescriptor

func NewIndexDescriptor(name string, columns ...string) *IndexDescriptor

NewIndexDescriptor creates a new IndexDescriptor

func (*IndexDescriptor) Columns

func (index *IndexDescriptor) Columns() []string

Columns database column referenced by index

func (*IndexDescriptor) Name

func (index *IndexDescriptor) Name() string

Name name of index

type Schema

type Schema interface {
	SchemaName() string
	Type() SchemaType
}

Schema schema of a structure in database

type SchemaType

type SchemaType int

SchemaType type of database schema

const (
	// SchemaTypeTable regular database table
	SchemaTypeTable SchemaType = iota

	// SchemaTypeView database view
	SchemaTypeView
)

type Table

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

Table information about a regular database table

func NewTableDescriptor

func NewTableDescriptor(name string, columns []*ColumnDescriptor, indices []*IndexDescriptor, uniques []*IndexDescriptor) *Table

NewTableDescriptor creates a new Table

**Parameters**

  • name: name of table
  • columns: columns of table
  • indices: index definitions of table
  • uniques: unique descriptors of table

**Returns**

  • *Table: created table descriptor

func (*Table) Columns

func (table *Table) Columns() []*ColumnDescriptor

Columns columns of table definition

**Returns**

  • []*ColumnDescriptor: columns contained in table definition

func (*Table) Indices

func (table *Table) Indices() []*IndexDescriptor

Indices index definitions of table definition

**Returns**

  • []*IndexDescriptor: index definitions contained in table definition

func (*Table) SchemaName

func (table *Table) SchemaName() string

SchemaName name of table in database

**Returns**

  • string: name string

func (*Table) Type

func (table *Table) Type() SchemaType

Type type of schema

**Returns**

  • SchemaType: always returns SchemaTypeTable

func (*Table) Uniques

func (table *Table) Uniques() []*IndexDescriptor

Uniques unique index definitions of table definition

**Returns**

  • []*IndexDescriptor: unique index definitions contained in table definition

type View

type View struct {
	Name string
	SQL  string
}

View information about a view

func (*View) SchemaName

func (view *View) SchemaName() string

SchemaName name of view in database

**Returns**

  • string: name string

func (*View) Type

func (view *View) Type() SchemaType

Type type of schema

**Returns**

  • SchemaType: type of schema

Jump to

Keyboard shortcuts

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