schema

package
v0.0.0-...-c1325ea Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package schema contains the schema for the database.

Index

Constants

View Source
const (
	ColumnKeyPrimary = "PRI" // Primary key
	ColumnKeyUnique  = "UNI" // Unique constraint
	ColumnKeyMulti   = "MUL" // Non-unique index or first column of multi-column index
)

ColumnKey constants represent the normalized key type of a column. Each database driver maps its native key type to these values.

View Source
const (
	ColumnExtraAutoIncrement = "auto_increment"
)

ColumnExtra constants represent the normalized extra information of a column. Each database driver maps its native extra info to these values.

View Source
const (
	IndexNamePrimary = "PRIMARY"
)

IndexName constants represent well-known index names.

Variables

This section is empty.

Functions

func Register

func Register(name string, driver Driver)

Register registers a database driver by name. Called from init() in driver implementations.

Types

type Column

type Column struct {
	Table           string
	Name            string // ColumnName
	OrdinalPosition int
	Default         string // ColumnDefault
	Nullable        string
	DataType        string
	ColumnType      string
	Key             string // ColumnKey
	Extra           string
	Comment         string // ColumnComment
	ForeignKey      *ForeignKey
	IndexName       string
	NonUnique       int
	IsMultiKey      bool
}

func (*Column) IsAutoIncrement

func (c *Column) IsAutoIncrement() bool

func (*Column) IsForeignKey

func (c *Column) IsForeignKey() bool

func (*Column) IsNullable

func (c *Column) IsNullable() bool

func (*Column) IsPrimaryKey

func (c *Column) IsPrimaryKey() bool

func (*Column) IsUnique

func (c *Column) IsUnique() bool

func (*Column) IsUnsigned

func (c *Column) IsUnsigned() bool

type Driver

type Driver interface {
	// Open creates a new Scheme for the given configuration.
	Open(cfg *config.DB) (Scheme, error)
}

Driver is the interface for database driver registration. Each driver must register itself via init() to be discoverable.

type ForeignKey

type ForeignKey struct {
	ConstraintName string // FK constraint name
	Table          string // Source table (e.g., "posts")
	ColumnName     string // Column in source table (e.g., "user_id")
	RefTable       string // Referenced table (e.g., "users")
	RefColumn      string // Referenced column (e.g., "id")
}

type Index

type Index struct {
	Table      string
	NonUnique  int
	ColumnName string
	IndexName  string
}

type Scheme

type Scheme interface {
	io.Closer
	Load(ctx context.Context) ([]*Table, error)
}

func New

func New(cfg *config.DB) (Scheme, error)

type Table

type Table struct {
	Name               string
	Comment            string
	Columns            []*Column
	ForeignKeys        []ForeignKey
	ReverseForeignKeys []ForeignKey // Foreign keys from other tables referencing this table
}

Jump to

Keyboard shortcuts

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