types

package
v0.0.0-...-ac4bb89 Latest Latest
Warning

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

Go to latest
Published: May 23, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToSQL

func ToSQL(s Schema, target string) xo.Schema

ToSQL converts the Go types generated by goType to the SQL type of the DB.

Types

type Enum

type Enum struct {
	Name   string   `json:"name,omitempty"`
	Values []string `json:"values,omitempty"`
}

Enum is a enum type.

type Field

type Field struct {
	Name       string `json:"name,omitempty"`
	Type       Type   `json:"type,omitempty"`
	Default    string `json:"default,omitempty"`
	IsPrimary  bool   `json:"is_primary,omitempty"`
	IsSequence bool   `json:"is_sequence,omitempty"`
}

Field is a column, index, enum value, or stored procedure parameter.

type ForeignKey

type ForeignKey struct {
	Name      string  `json:"name,omitempty"`
	Fields    []Field `json:"column,omitempty"`     // column that has the key on it
	RefTable  string  `json:"ref_table,omitempty"`  // table the foreign key refers to
	RefFields []Field `json:"ref_column,omitempty"` // column in ref table the index refers to
}

ForeignKey is a foreign key.

type Index

type Index struct {
	Name      string  `json:"name,omitempty"`
	Fields    []Field `json:"fields,omitempty"`
	IsUnique  bool    `json:"is_unique,omitempty"`
	IsPrimary bool    `json:"is_primary,omitempty"`
}

Index is a index.

type Schema

type Schema struct {
	Name   string  `json:"name,omitempty"`
	Enums  []Enum  `json:"enums,omitempty"`
	Tables []Table `json:"tables,omitempty"`
}

Schema is the intermediate schema.

type Table

type Table struct {
	Name        string       `json:"name,omitempty"`
	Columns     []Field      `json:"columns,omitempty"`
	PrimaryKeys []Field      `json:"primary_keys,omitempty"`
	Indexes     []Index      `json:"indexes,omitempty"`
	ForeignKeys []ForeignKey `json:"foreign_keys,omitempty"`
}

func NewRefTable

func NewRefTable(refTableName, leftTable, leftCol, rightTable, rightCol string) Table

NewRefTable creates a reference table with the specified name, mapping from leftTable to rightTable. Indexes and foreign keys are automatically created.

leftCol is used as the name of the left column and rightCol is used as the name of the right column. It is assumed that both columns refer to the id column of leftTable and rightTable.

func NewTable

func NewTable(name string, manual bool) Table

NewTable creates a new table with the specified name. If manual is false, a primary key named "id" is automatically created.

type Type

type Type struct {
	Type     string `json:"type,omitempty"`
	IsArray  bool   `json:"array,omitempty"`
	EnumName string `json:"enum_name,omitempty"`
	Nullable bool   `json:"nullable,omitempty"`
}

Type holds information for a database type.

Jump to

Keyboard shortcuts

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