schema

package
v0.48.4 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package schema provides functionality for modeling SQL constructs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Column

type Column struct {
	Name  string    `json:"name"`
	Table *Table    `json:"-"`
	Kind  kind.Kind `json:"kind"`

	NotNull    bool `json:"not_null"`
	HasDefault bool `json:"has_default"`

	// Size typically applies to text fields, e.g. VARCHAR(255).
	Size int `json:"size"`

	Unique     bool          `json:"unique"`
	ForeignKey *FKConstraint `json:"foreign_key,omitempty"`
}

Column models a table column definition.

func (*Column) Equal added in v0.48.2

func (c *Column) Equal(b *Column) bool

func (*Column) String added in v0.48.2

func (c *Column) String() string

type FKConstraint

type FKConstraint struct {
	// RefTable is the name of the referenced parent table.
	RefTable string `json:"ref_table"`
	// RefCol is the name of the referenced col in the parent table.
	RefCol string `json:"ref_col"`
	// OnDelete is one of CASCADE or SET_NULL, defaults to CASCADE.
	OnDelete string `json:"on_delete"`
	// OnUpdate is one of CASCADE or SET_NULL, defaults to CASCADE.
	OnUpdate string `json:"on_update"`
}

FKConstraint models a foreign key constraint.

func (*FKConstraint) Equal added in v0.48.2

func (fk *FKConstraint) Equal(b *FKConstraint) bool

type Table

type Table struct {
	// Name is the table name.
	Name string `json:"name"`

	// PKColName is the name of the primary key column, or empty.
	//
	// REVISIT: this construct does not allow for composite PK.
	PKColName string `json:"primary_key,omitempty"`

	// AutoIncrement, if true, indicates that a PK column
	// should autoincrement.
	//
	// REVISIT: this construct does not allow for composite PK.
	AutoIncrement bool `json:"auto_increment"`

	// Cols is the table's column definitions.
	Cols []*Column `json:"cols"`
}

Table models a database table definition.

func NewTable

func NewTable(tblName string, colNames []string, colKinds []kind.Kind) *Table

NewTable is a convenience constructor for creating a simple table definition.

func (*Table) ColKinds

func (t *Table) ColKinds() []kind.Kind

ColKinds returns a new slice containing the kinds of t's columns.

func (*Table) ColNames

func (t *Table) ColNames() []string

ColNames returns a new slice containing the names of t's columns.

func (*Table) ColsByName

func (t *Table) ColsByName(cols []string) ([]*Column, error)

ColsByName returns the ColDefs for each named column, or an error if any column is not matched.

func (*Table) Equal added in v0.48.2

func (t *Table) Equal(b *Table) bool

func (*Table) FindCol

func (t *Table) FindCol(name string) (*Column, error)

FindCol returns the named Column or nil if not found.

func (*Table) String

func (t *Table) String() string

Jump to

Keyboard shortcuts

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