schema

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2023 License: Apache-2.0 Imports: 4 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 is the actual name in postgres
	Name string `json:"name"`

	// Column type
	Type string `json:"type"`

	Default  *string `json:"default"`
	Nullable bool    `json:"nullable"`

	// Optional comment for the column
	Comment string `json:"comment"`
}

type Index

type Index struct {
	// Name is the name of the index in postgres
	Name string `json:"name"`
}

type Schema

type Schema struct {
	// Name is the name of the schema
	Name string `json:"name"`
	// Tables is a map of virtual table name -> table mapping
	Tables map[string]Table `json:"tables"`
}

func New

func New() *Schema

func (*Schema) AddTable

func (s *Schema) AddTable(name string, t Table)

func (*Schema) GetTable

func (s *Schema) GetTable(name string) *Table

func (*Schema) RemoveTable

func (s *Schema) RemoveTable(name string)

func (*Schema) RenameTable

func (s *Schema) RenameTable(from, to string) error

func (*Schema) Scan

func (s *Schema) Scan(value interface{}) error

Make the Schema struct implement the sql.Scanner interface. This method simply decodes a JSON-encoded value into the struct fields.

func (Schema) Value

func (s Schema) Value() (driver.Value, error)

Make the Schema struct implement the driver.Valuer interface. This method simply returns the JSON-encoded representation of the struct.

type Table

type Table struct {
	// OID for the table
	OID string `json:"oid"`

	// Name is the actual name in postgres
	Name string `json:"name"`

	// Optional comment for the table
	Comment string `json:"comment"`

	// Columns is a map of virtual column name -> column mapping
	Columns map[string]Column `json:"columns"`

	// Indexes is a map of the indexes defined on the table
	Indexes map[string]Index `json:"indexes"`

	// The columns that make up the primary key
	PrimaryKey []string `json:"primaryKey"`
}

func (*Table) AddColumn

func (t *Table) AddColumn(name string, c Column)

func (*Table) GetColumn

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

func (*Table) GetPrimaryKey added in v0.2.0

func (t *Table) GetPrimaryKey() (columns []*Column)

func (*Table) RemoveColumn

func (t *Table) RemoveColumn(column string)

func (*Table) RenameColumn

func (t *Table) RenameColumn(from, to string)

Jump to

Keyboard shortcuts

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