schema

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Column

type Column struct {
	Name          string
	GoName        string
	Datatype      datatype.Datatype
	Unsigned      bool
	Nullable      bool
	Default       *string
	Params        []string
	Charset       string
	Collation     string
	PrimaryKey    bool
	AutoIncrement bool
}

Column represents a column in a table

func (*Column) ExportedGoName

func (c *Column) ExportedGoName() string

ExportedGoName returns the string that will be used for naming Exported types, functions, etc in generated Go code

func (*Column) GoTypeString

func (c *Column) GoTypeString() string

GoTypeString returns the string keyword of the column type's corresponding Go type

func (*Column) RequiredImport

func (c *Column) RequiredImport() string

RequiredImport returns any packages that need to be imported to support the Go type of a column in generated Go code

func (*Column) UnmarshalYAML

func (c *Column) UnmarshalYAML(value *yaml.Node) (err error)

type Database

type Database struct {
	Dialect string
	Tables  []Table
}

Database represents a single database/schema in a DBMS.

func (*Database) GetTable

func (db *Database) GetTable(name string) (Table, bool)

GetTable returns a table matching the given name if present. If a matching table is found, the returned bool is true. If a matching table is not found, the returned bool is false.

func (*Database) UnmarshalYAML

func (db *Database) UnmarshalYAML(value *yaml.Node) (err error)

type Index

type Index struct {
	Name    string
	Columns []string
	Unique  bool
}

Index represents a simple index on a column or columns

type Reference

type Reference struct {
	GoName      string
	TableName   string
	HasOne      bool
	HasMany     bool
	Required    bool
	ColumnNames []string
	OnDelete    string
	OnUpdate    string
}

Reference represents a relationship between tables. Not a SQL-native concept, more of an ORM-style design. Translates to foreign keys and constraints in SQL

func (*Reference) ColNames

func (r *Reference) ColNames(ft Table) []string

ColNames returns a list foreign key column names for the given reference. The method assumes that the `fTable` value is correct (for example, the "many" side in a one-to-many reference) and not necessarily the target table of the Reference itself. So make sure the Yoyo-to-RDB reference translation has already happened before calling ColNames.

func (*Reference) ExportedGoName added in v0.0.5

func (r *Reference) ExportedGoName() string

ExportedGoName returns the string that will be used for naming Exported types, functions, etc in generated Go code

func (*Reference) UnmarshalYAML

func (r *Reference) UnmarshalYAML(value *yaml.Node) (err error)

type Table

type Table struct {
	Name       string
	GoName     string
	Columns    []Column
	Indices    []Index
	References []Reference
}

Table represents a table in a database

func (*Table) ExportedGoName

func (t *Table) ExportedGoName() string

ExportedGoName returns a string with a name to use to represent the table in Exported go types or variables. If a GoName is explicitly set already, the returned value will be that forced into PascalCase. If not, it will be the default name forced into PascalCase.

func (*Table) GetColumn

func (t *Table) GetColumn(name string) (Column, bool)

GetColumn returns a column matching the given name if present. If a matching column is found, the returned bool is true. If a matching column is not found, the returned bool is false.

func (*Table) PKColNames

func (t *Table) PKColNames() (cols []string)

PKColNames returns a list of column names that represent this table's Primary Key. This is usually a slice with a single value, but may be empty if there is no PK, and may be several if it's a compound PK

func (*Table) PKColumns

func (t *Table) PKColumns() (cols []Column)

PKColumns returns a list of Columns that represent this table's Primary Key. This is usually a slice with a single value, but may be empty if there is no PK, and may be several if it's a compound PK

func (*Table) QueryPackageName

func (t *Table) QueryPackageName() (name string)

QueryPackageName returns a string to use for this table's query package

func (*Table) UnmarshalYAML

func (t *Table) UnmarshalYAML(value *yaml.Node) (err error)

Jump to

Keyboard shortcuts

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