metadata

package
v0.23.0-beta.5 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: Apache-2.0, BSD-3-Clause, MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetCatalogTypes

func SetCatalogTypes(tables []Table, types map[string]map[string]string)

SetCatalogTypes sets the CatalogType of each column of each table from types, by table name and column name. It marks each table with CatalogTypesRead.

func SetForeignKeys

func SetForeignKeys(tables []Table, keys map[string][]ForeignKey)

SetForeignKeys sets the ForeignKeys of each table from keys, by table name, sorted by constraint name, byte by byte, so the order does not depend on the collation of the server. The sort is stable: keys with no name (SQLite) keep the order of the catalogue. It marks each table with ForeignKeysRead.

Types

type Column

type Column struct {
	Name         string `sql:"primary_key"`
	IsPrimaryKey bool
	IsNullable   bool
	IsGenerated  bool
	HasDefault   bool
	DataType     DataType
	Comment      string
	// CatalogType is the type name of the column in the catalogue (Nanostack, see catalog.go).
	CatalogType string
}

Column struct

type DataType

type DataType struct {
	Name          string
	Kind          DataTypeKind
	IsUnsigned    bool
	Dimensions    int // The number of array dimensions
	SourceDialect string
}

DataType contains information about column data type

func (DataType) IsArray

func (d DataType) IsArray() bool

type DataTypeKind

type DataTypeKind string

DataTypeKind is database type kind(base, enum, user-defined, array)

const (
	BaseType        DataTypeKind = "base"
	EnumType        DataTypeKind = "enum"
	UserDefinedType DataTypeKind = "user-defined"
	RangeType       DataTypeKind = "range"
)

DataTypeKind possible values

type DialectQuerySet

type DialectQuerySet interface {
	GetTablesMetaData(db *sql.DB, schemaName string, tableType TableType) ([]Table, error)
	GetEnumsMetaData(db *sql.DB, schemaName string) ([]Enum, error)
}

DialectQuerySet is set of methods necessary to retrieve dialect metadata information

type Enum

type Enum struct {
	Name    string `sql:"primary_key"`
	Comment string
	Values  []string
}

Enum metadata struct

type ForeignKey

type ForeignKey struct {
	// Name is the name of the constraint. It is empty on SQLite, which keeps
	// no name for a foreign key.
	Name string
	// Columns are the referencing columns, in key order.
	Columns []string
	// ReferencedSchema is the schema of the referenced table: the database on
	// MySQL, and empty on SQLite.
	ReferencedSchema string
	// ReferencedTable is the name of the referenced table.
	ReferencedTable string
	// ReferencedColumns are the referenced columns, in the order of Columns.
	ReferencedColumns []string
}

ForeignKey is one foreign key of a base table.

type Schema

type Schema struct {
	Name           string
	TablesMetaData []Table
	ViewsMetaData  []Table
	EnumsMetaData  []Enum
}

Schema struct

func GetSchema

func GetSchema(db *sql.DB, querySet DialectQuerySet, schemaName string) (Schema, error)

GetSchema retrieves Schema information from database

func ReadSchema

func ReadSchema(db *sql.DB, querySet DialectQuerySet, schemaName string) (Schema, error)

ReadSchema retrieves Schema information from the database, as GetSchema does, and prints nothing.

func (Schema) IsEmpty

func (s Schema) IsEmpty() bool

IsEmpty returns true if schema info does not contain any table, views or enums metadata

type Table

type Table struct {
	Name    string `sql:"primary_key"`
	Comment string
	Columns []Column
	// UniqueIndexes are the unique indexes of a base table, from postgres.ReadSchema (Nanostack, see unique_index.go).
	UniqueIndexes []UniqueIndex
	// ForeignKeys are the foreign keys of a base table, from the ReadSchema function of each dialect (Nanostack, see catalog.go).
	ForeignKeys []ForeignKey
	// CatalogTypesRead and ForeignKeysRead say that the ReadSchema function of the dialect filled
	// Column.CatalogType and ForeignKeys (Nanostack, see catalog.go).
	CatalogTypesRead bool
	ForeignKeysRead  bool
}

Table metadata struct

func (Table) DefaultColumns

func (t Table) DefaultColumns() []Column

DefaultColumns returns list of columns with default values set for table

func (Table) MutableColumns

func (t Table) MutableColumns() []Column

MutableColumns returns list of mutable columns for table

type TableType

type TableType string

TableType is type of database table(view or base)

const (
	BaseTable TableType = "BASE TABLE"
	ViewTable TableType = "VIEW"
)

SQL table types

type UniqueIndex

type UniqueIndex struct {
	// Name is the name of the index, which is also the name of the
	// constraint that owns it.
	Name string
	// Columns are the key columns in index order, without INCLUDE columns.
	// An expression key is the empty string.
	Columns []string
	// Predicate is the WHERE clause of a partial index, as pg_get_expr
	// prints it, such as "(external_id IS NOT NULL)". Empty for a full index.
	Predicate string
	// NotKey says why equality on Columns can still match more than one
	// row, such as "expression key". Empty when the index proves that it
	// matches at most one.
	NotKey string
}

UniqueIndex is one unique index of a table: its primary key, a unique constraint or a unique index. postgres.ReadSchema reads them for each base table; GetSchema and the other dialects leave Table.UniqueIndexes empty.

Jump to

Keyboard shortcuts

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