schema

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CheckConstraint added in v0.5.0

type CheckConstraint struct {
	// Name is the name of the check constraint in postgres
	Name string `json:"name"`

	// The columns that the check constraint is defined on
	Columns []string `json:"columns"`

	// The definition of the check constraint
	Definition string `json:"definition"`

	// NoInherit indicates that the check constraint should not be inherited
	NoInherit bool `json:"noInherit"`
}

CheckConstraint represents a check constraint on a table

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"`
	Unique   bool    `json:"unique"`

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

	// Will contain possible enum values if the type is an enum
	EnumValues []string `json:"enumValues"`

	// Whether or not the column has been deleted in the virtual schema
	Deleted bool `json:"-"`

	// Postgres type type, e.g enum, composite, range
	PostgresType string `json:"postgresType"`
}

Column represents a column in a table

type ExcludeConstraint added in v0.9.0

type ExcludeConstraint struct {
	// Name is the name of the exclude constraint in postgres
	Name string `json:"name"`

	// Method is the index method of the exclude constraint
	Method string `json:"method"`

	// Predicate is the predicate of the index
	Predicate string `json:"predicate"`

	// The columns that the exclusion constraint is defined on
	Columns []string `json:"columns"`

	// The definition of the exclusion
	Definition string `json:"definition"`
}

ExcludeConstraint represents a unique constraint on a table

type ForeignKey added in v0.5.0

type ForeignKey struct {
	// Name is the name of the foreign key in postgres
	Name string `json:"name"`

	// The columns that the foreign key is defined on
	Columns []string `json:"columns"`

	// The table that the foreign key references
	ReferencedTable string `json:"referencedTable"`

	// The columns in the referenced table that the foreign key references
	ReferencedColumns []string `json:"referencedColumns"`

	// The ON DELETE behavior of the foreign key
	OnDelete string `json:"onDelete"`

	// OnDeleteSetColumns is the list of columns to update ON DELETE
	OnDeleteSetColumns []string `json:"onDeleteSetColumns"`

	// The ON UPDATE behavior of the foreign key
	OnUpdate string `json:"onUpdate"`

	// MatchType is the match type of the foreign key
	MatchType string `json:"matchType"`
}

ForeignKey represents a foreign key on a table

type Index

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

	// Unique indicates whether or not the index is unique
	Unique bool `json:"unique"`

	// Exclusion indicates whether or not the index is an exclusion index
	Exclusion bool `json:"exclusion"`

	// Columns is the set of key columns on which the index is defined
	Columns []string `json:"columns"`

	// Predicate is the optional predicate for the index
	Predicate *string `json:"predicate,omitempty"`

	// Method is the method for the index
	Method string `json:"method,omitempty"`

	// Definition is statement to construct the index
	Definition string `json:"definition"`
}

Index represents an index on a table

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"`
}

Schema represents a database schema

func New

func New() *Schema

func (*Schema) AddTable

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

AddTable adds a table to the schema

func (*Schema) GetTable

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

GetTable returns a table by name

func (*Schema) RemoveTable

func (s *Schema) RemoveTable(name string)

RemoveTable removes a table from the schema by marking it as deleted

func (*Schema) RenameTable

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

RenameTable renames a table in the schema

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) UnRemoveTable added in v0.9.0

func (s *Schema) UnRemoveTable(name string)

UnRemoveTable unremoves a previously removed table by marking it as not deleted

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"`

	// ForeignKeys is a map of all foreign keys defined on the table
	ForeignKeys map[string]*ForeignKey `json:"foreignKeys"`

	// CheckConstraints is a map of all check constraints defined on the table
	CheckConstraints map[string]*CheckConstraint `json:"checkConstraints"`

	// UniqueConstraints is a map of all unique constraints defined on the table
	UniqueConstraints map[string]*UniqueConstraint `json:"uniqueConstraints"`

	// ExcludeConstraints is a map of all exclude constraints defined on the table
	ExcludeConstraints map[string]*ExcludeConstraint `json:"excludeConstraints"`

	// Whether or not the table has been deleted in the virtual schema
	Deleted bool `json:"-"`
}

Table represents a table in the schema

func (*Table) AddColumn

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

AddColumn adds a column to the table

func (*Table) ConstraintExists added in v0.5.0

func (t *Table) ConstraintExists(name string) bool

ConstraintExists returns true if a constraint with the given name exists

func (*Table) GetColumn

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

GetColumn returns a column by name

func (*Table) GetConstraintColumns added in v0.8.0

func (t *Table) GetConstraintColumns(name string) []string

GetConstraintColumns gets the columns associated with the given constraint. It may return a nil slice if the constraint does not exist.

func (*Table) GetPrimaryKey added in v0.2.0

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

GetPrimaryKey returns the columns that make up the primary key

func (*Table) PhysicalColumnNamesFor added in v0.8.0

func (t *Table) PhysicalColumnNamesFor(columnNames ...string) []string

PhysicalColumnNamesFor returns the physical column names for the given virtual column names

func (*Table) RemoveColumn

func (t *Table) RemoveColumn(column string)

RemoveColumn removes a column from the table by marking it as deleted

func (*Table) RenameColumn

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

RenameColumn renames a column in the table

func (*Table) RenameConstraintColumns added in v0.10.0

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

RenameConstraintColumns renames all occurrences of a column name in any constraint on the table from `from` to `to`.

func (*Table) UnRemoveColumn added in v0.9.0

func (t *Table) UnRemoveColumn(column string)

UnRemoveColumn unremoves a previously removed column by marking it as not deleted

type UniqueConstraint added in v0.5.0

type UniqueConstraint struct {
	// Name is the name of the unique constraint in postgres
	Name string `json:"name"`

	// The columns that the unique constraint is defined on
	Columns []string `json:"columns"`
}

UniqueConstraint represents a unique constraint on a table

Jump to

Keyboard shortcuts

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