Help us shape the future of Go! Take the 2026 Go Developer Survey

driver

package
v1.20.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Blueprint

type Blueprint interface {
	// GetAddedColumns Get the added columns.
	GetAddedColumns() []ColumnDefinition
	// GetCommands Get the commands.
	GetCommands() []*Command
	// GetTableName Get the table name with prefix.
	GetTableName() string
	// HasCommand Determine if the blueprint has a specific command.
	HasCommand(command string) bool
}

type BlueprintDescriber

type BlueprintDescriber interface{ DescribeBlueprint() BlueprintDescription }

type BlueprintDescription

type BlueprintDescription struct {
	Table, Prefix, Engine, Charset, Collation string
	Temporary                                 bool
	Columns                                   []ColumnDefinition
	Commands                                  []*Command
}

Descriptions expose optional settings without coupling drivers to private blueprint fields. Pointer values distinguish an omitted option from zero.

type Column

type Column struct {
	// DefaultValue preserves SQL NULL versus an empty string for DDL reconstruction.
	// DefaultKnown distinguishes rich metadata from the legacy string-only contract.
	DefaultValue  any
	DefaultKnown  bool
	Generation    *ColumnGeneration
	Collation     string
	Comment       string
	Default       string
	Extra         string
	Name          string
	Type          string
	TypeName      string
	Autoincrement bool
	Nullable      bool
}

type ColumnDefinition

type ColumnDefinition interface {
	StoredAs(expression any) ColumnDefinition
	VirtualAs(expression any) ColumnDefinition
	Persisted() ColumnDefinition
	Invisible() ColumnDefinition
	Charset(charset string) ColumnDefinition
	Collation(collation string) ColumnDefinition
	StartingValue(value uint64) ColumnDefinition
	From(value uint64) ColumnDefinition
	Fixed() ColumnDefinition
	Srid(value int) ColumnDefinition
	Instant() ColumnDefinition
	// After sets the column "after" another column (MySQL only)
	After(column string) ColumnDefinition
	// Always defines the precedence of sequence values over input for an identity column (PostgreSQL only)
	Always() ColumnDefinition
	// AutoIncrement set the column as auto increment
	AutoIncrement() ColumnDefinition
	// Change the column (MySQL / PostgreSQL / SQL Server)
	Change() ColumnDefinition
	// Comment sets the comment value (MySQL / PostgreSQL)
	Comment(comment string) ColumnDefinition
	// Default set the default value
	Default(def any) ColumnDefinition
	// First sets the column "first" in the table (MySQL only)
	First() ColumnDefinition
	// GeneratedAs creates an identity column with specified sequence options (PostgreSQL only)
	GeneratedAs(expression ...string) ColumnDefinition
	// GetAfter returns the after value
	GetAfter() string
	// GetAllowed returns the allowed value
	GetAllowed() []any
	// GetAutoIncrement returns the autoIncrement value
	GetAutoIncrement() bool
	// GetComment returns the comment value
	GetComment() (comment string)
	// GetDefault returns the default value
	GetDefault() any
	// GetGeneratedAs returns the generatedAs value
	GetGeneratedAs() string
	// GetLength returns the length value
	GetLength() int
	// GetName returns the name value
	GetName() string
	// GetNullable returns the nullable value
	GetNullable() bool
	// GetOnUpdate returns the onUpdate value
	GetOnUpdate() any
	// GetPlaces returns the places value
	GetPlaces() int
	// GetPrecision returns the precision value
	GetPrecision() int
	// GetTotal returns the total value
	GetTotal() int
	// GetType returns the type value
	GetType() string
	// GetUnsigned returns the unsigned value
	GetUnsigned() bool
	// GetUseCurrent returns the useCurrent value
	GetUseCurrent() bool
	// GetUseCurrentOnUpdate returns the useCurrentOnUpdate value
	GetUseCurrentOnUpdate() bool
	// IsAlways returns the always value
	IsAlways() bool
	// IsChange returns true if the column has changed
	IsChange() bool
	// IsFirst returns true if the column is first
	IsFirst() bool
	// IsSetComment returns true if the comment value is set
	IsSetComment() bool
	// IsSetGeneratedAs returns true if the generatedAs value is set
	IsSetGeneratedAs() bool
	// OnUpdate sets the column to use the value on update (Mysql only)
	OnUpdate(value any) ColumnDefinition
	// Places set the decimal places
	Places(places int) ColumnDefinition
	// Total set the decimal total
	Total(total int) ColumnDefinition
	// Nullable allow NULL values to be inserted into the column
	Nullable(nullable ...bool) ColumnDefinition
	// Unsigned set the column as unsigned (Mysql only)
	Unsigned() ColumnDefinition
	// UseCurrent set the column to use the current timestamp
	UseCurrent() ColumnDefinition
	// UseCurrentOnUpdate set the column to use the current timestamp on update (Mysql only)
	UseCurrentOnUpdate() ColumnDefinition
}

type ColumnDescriber

type ColumnDescriber interface{ DescribeColumn() ColumnDescription }

type ColumnDescription

type ColumnDescription struct {
	Name, Type, After, Charset, Collation, Subtype, RawDefinition     string
	StoredAs, VirtualAs, Expression, Default, OnUpdate                any
	Allowed                                                           []any
	StoredSet, VirtualSet, Persisted, Invisible, Fixed, Instant       bool
	Always, Change, First                                             bool
	AutoIncrement, Nullable, Unsigned, UseCurrent, UseCurrentOnUpdate *bool
	Comment, GeneratedAs                                              *string
	Length, Places, Precision, Total, Srid, Dimensions                *int
	StartingValue                                                     *uint64
}

type ColumnGeneration

type ColumnGeneration struct {
	Type       string  `json:"type"`
	Expression *string `json:"expression"`
}

type ColumnMetadata

type ColumnMetadata struct {
	Name          string            `json:"name"`
	Type          string            `json:"type"`
	TypeName      string            `json:"type_name"`
	Collation     *string           `json:"collation"`
	Nullable      bool              `json:"nullable"`
	Default       any               `json:"default"`
	AutoIncrement bool              `json:"auto_increment"`
	Comment       *string           `json:"comment"`
	Generation    *ColumnGeneration `json:"generation"`
	Extra         string            `json:"-"`
}

ColumnMetadata retains Laravel's nullable metadata without changing the legacy Column fields.

type Command

type Command struct {
	Column             ColumnDefinition
	Deferrable         *bool
	InitiallyImmediate *bool
	Algorithm          string
	From               string
	Index              string
	Language           string
	Name               string
	On                 string
	OnDelete           string
	OnUpdate           string
	To                 string
	Value              string
	Columns            []string
	References         []string
	ShouldBeSkipped    bool
}

type CompileLimitGrammar

type CompileLimitGrammar interface {
	CompileLimit(builder sq.SelectBuilder, conditions *Conditions) sq.SelectBuilder
}

type CompileOffsetGrammar

type CompileOffsetGrammar interface {
	CompileOffset(builder sq.SelectBuilder, conditions *Conditions) sq.SelectBuilder
}

type CompileOrderByGrammar

type CompileOrderByGrammar interface {
	CompileOrderBy(builder sq.SelectBuilder, conditions *Conditions) sq.SelectBuilder
}

type Conditions

type Conditions struct {
	CrossJoin     []Join
	Distinct      *bool
	GroupBy       []string
	Having        *Having
	Join          []Join
	InRandomOrder *bool
	LeftJoin      []Join
	LockForUpdate *bool
	Limit         *uint64
	Offset        *uint64
	OrderBy       []string
	RightJoin     []Join
	Selects       []string
	SharedLock    *bool
	Table         string
	Where         []Where
}

type DBColumn

type DBColumn struct {
	Collation     string
	Comment       string
	Default       string
	Extra         string
	Name          string
	Nullable      string
	Type          string
	TypeName      string
	Length        int
	Places        int
	Precision     int
	Autoincrement bool
	Primary       bool
}

type DBForeignKey

type DBForeignKey struct {
	Name           string
	Columns        string
	ForeignSchema  string
	ForeignTable   string
	ForeignColumns string
	OnUpdate       string
	OnDelete       string
}

type DBGrammar

type DBGrammar interface {
	// CompileLockForUpdate Compile the lock for update.
	CompileLockForUpdate(builder sq.SelectBuilder, conditions *Conditions) sq.SelectBuilder
	// CompileInRandomOrder Compile the random order.
	CompileInRandomOrder(builder sq.SelectBuilder, conditions *Conditions) sq.SelectBuilder
	// CompilePlaceholderFormat Compile the placeholder format.
	CompilePlaceholderFormat() PlaceholderFormat
	// CompileSharedLock Compile the shared lock.
	CompileSharedLock(builder sq.SelectBuilder, conditions *Conditions) sq.SelectBuilder
	// CompileVersion Compile the version.
	CompileVersion() string
}

type DBIndex

type DBIndex struct {
	Columns string
	Name    string
	Type    string
	Primary bool
	Unique  bool
}

type Dialect

type Dialect interface {
	Name() string
	NewConnector(database.Config) (sqldriver.Connector, error)
	NewQueryGrammar(GrammarOptions) query.Grammar
	NewProcessor() query.Processor
}

Dialect supplies the database-specific connection and query components. The framework retains ownership of SQL pools, query state, execution and transactions.

type DialectWithEscaper

type DialectWithEscaper interface {
	Escape(value any, binary bool) (string, error)
}

DialectWithEscaper supplies database-specific literal rendering for SQL previews. Executed statements continue to use bound parameters.

type DialectWithServerVersion

type DialectWithServerVersion interface {
	ServerVersionSQL() string
}

DialectWithServerVersion supplies the SQL used for connection-local version discovery.

type Driver

type Driver interface {
	// Docker returns the database driver for Docker.
	Docker() (docker.DatabaseDriver, error)
	// Grammar returns the database grammar.
	Grammar() Grammar
	// Pool returns the database pool.
	Pool() database.Pool
	// Processor returns the database processor.
	Processor() Processor
}

type DriverWithDialect

type DriverWithDialect interface {
	Dialect() Dialect
}

DriverWithDialect is implemented by drivers which supply their query components. Older drivers can continue to use the framework's remaining built-in dialects.

type DriverWithServerVersion

type DriverWithServerVersion interface {
	SetServerVersion(func() (string, error))
}

DriverWithServerVersion receives version discovery backed by the managed writer. Schema grammars use this to compile version-dependent DDL without their own pools.

type ForeignKey

type ForeignKey struct {
	Name           string
	ForeignSchema  string
	ForeignTable   string
	OnUpdate       string
	OnDelete       string
	Columns        []string
	ForeignColumns []string
}

type Grammar

type Grammar interface {
	SchemaGrammar
	DBGrammar
	JsonGrammar
}

Grammar is the schema and DDL grammar a driver module supplies. Row locking and random ordering are not part of it: the framework compiles those itself, so no driver module needs to import GORM to describe them.

type GrammarOptions

type GrammarOptions struct {
	Prefix        string
	Driver        string
	ServerVersion func() (string, error)
}

GrammarOptions carries connection-local compilation settings. ServerVersion uses the managed writer pool; constructing a grammar must not open a separate connection.

type Having

type Having struct {
	Query any
	Args  []any
}

type Index

type Index struct {
	Name    string
	Type    string
	Columns []string
	Primary bool
	Unique  bool
}

type Join

type Join struct {
	Query string
	Args  []any
}

type JsonGrammar

type JsonGrammar interface {
	// CompileJsonColumnsUpdate Compile the JSON  columns for an update statement.
	CompileJsonColumnsUpdate(values map[string]any) (map[string]any, error)
	// CompileJsonContains Compile a "JSON contains" statement into SQL.
	CompileJsonContains(column string, value any, isNot bool) (string, []any, error)
	// CompileJsonContainsKey Compile a "JSON contains key" statement into SQL.
	CompileJsonContainsKey(column string, isNot bool) string
	// CompileJsonLength Compile a "JSON length" statement into SQL.
	CompileJsonLength(column string) string
	// CompileJsonSelector Wrap the given JSON selector.
	CompileJsonSelector(column string) string
	// CompileJsonValues Normalizes and converts values into database-compatible types.
	CompileJsonValues(args ...any) []any
}

type PlaceholderFormat

type PlaceholderFormat interface {
	ReplacePlaceholders(sql string) (string, error)
}

type Processor

type Processor interface {
	ProcessColumns(dbColumns []DBColumn) []Column
	ProcessForeignKeys(dbIndexes []DBForeignKey) []ForeignKey
	ProcessIndexes(dbIndexes []DBIndex) []Index
	ProcessTypes(types []Type) []Type
}

type Schema

type Schema struct {
	Name    string  `json:"name"`
	Path    *string `json:"path"`
	Default bool    `json:"default"`
}

Schema is a database namespace. SQLite supplies its attached file as Path.

type SchemaBlueprintPlanner

type SchemaBlueprintPlanner interface {
	SchemaExecutionPolicy(Blueprint) SchemaExecutionPolicy
	CompileSchemaBlueprint(Blueprint, SchemaCatalog) ([]SchemaStatement, bool, error)
}

type SchemaCatalog

type SchemaCatalog interface {
	Select(SchemaStatement) ([]map[string]any, error)
	Columns(string) ([]ColumnMetadata, error)
	ResolveTable(string) (string, string, error)
}

SchemaCatalog exposes read-only access on the schema manager's active session. Dialects compile catalog queries; connection ownership stays in the framework.

type SchemaCompiler

type SchemaCompiler interface {
	CompileSchemaCommand(Blueprint, *Command) ([]SchemaStatement, bool, error)
	CompileSchemaStartingValues(Blueprint) ([]SchemaStatement, error)
}

SchemaCompiler extends the legacy grammar without changing existing drivers. Unhandled commands use SchemaGrammar's legacy compilation methods.

type SchemaConnectionInfo

type SchemaConnectionInfo struct {
	Database, Username, Schema, Prefix string
	SearchPath                         any
}

type SchemaCurrentSchemas

type SchemaCurrentSchemas interface {
	ResolveCurrentSchemas(SchemaConnectionInfo, SchemaCatalog) ([]string, error)
}

type SchemaDatabaseFiles

type SchemaDatabaseFiles interface {
	CreateDatabase(string) error
	DropDatabaseIfExists(string) error
}

SchemaDatabaseFiles is implemented by databases whose database operations create or remove local files rather than execute SQL.

type SchemaExecutionPolicy

type SchemaExecutionPolicy struct {
	Transactional                 bool
	NestedTransaction             bool
	DisableForeignKeys            bool
	ForeignKeysOutsideTransaction bool
	SessionSettings               []SchemaSessionSetting
}

type SchemaGrammar

type SchemaGrammar interface {
	// CompileAdd Compile an add column command.
	CompileAdd(blueprint Blueprint, command *Command) string
	// CompileChange Compile a change column command.
	CompileChange(blueprint Blueprint, command *Command) []string
	// CompileColumns Compile the query to determine the columns.
	CompileColumns(schema, table string) (string, error)
	// CompileComment Compile a column comment command.
	CompileComment(blueprint Blueprint, command *Command) string
	// CompileCreate Compile a create table command.
	CompileCreate(blueprint Blueprint) string
	// CompileDefault Compile a default value command.
	CompileDefault(blueprint Blueprint, command *Command) string
	// CompileDrop Compile a drop table command.
	CompileDrop(blueprint Blueprint) string
	// CompileDropAllTables Compile the SQL needed to drop all tables.
	CompileDropAllTables(schema string, tables []Table) []string
	// CompileDropAllTypes Compile the SQL needed to drop all types.
	CompileDropAllTypes(schema string, types []Type) []string
	// CompileDropAllViews Compile the SQL needed to drop all views.
	CompileDropAllViews(schema string, views []View) []string
	// CompileDropColumn Compile a drop column command.
	CompileDropColumn(blueprint Blueprint, command *Command) []string
	// CompileDropForeign Compile a drop foreign key command.
	CompileDropForeign(blueprint Blueprint, command *Command) string
	// CompileDropFullText Compile a drop fulltext index command.
	CompileDropFullText(blueprint Blueprint, command *Command) string
	// CompileDropIfExists Compile a drop table (if exists) command.
	CompileDropIfExists(blueprint Blueprint) string
	// CompileDropIndex Compile a drop index command.
	CompileDropIndex(blueprint Blueprint, command *Command) string
	// CompileDropPrimary Compile a drop primary key command.
	CompileDropPrimary(blueprint Blueprint, command *Command) string
	// CompileDropUnique Compile a drop unique key command.
	CompileDropUnique(blueprint Blueprint, command *Command) string
	// CompileForeign Compile a foreign key command.
	CompileForeign(blueprint Blueprint, command *Command) string
	// CompileForeignKeys Compile the query to determine the foreign keys.
	CompileForeignKeys(schema, table string) string
	// CompileFullText Compile a fulltext index key command.
	CompileFullText(blueprint Blueprint, command *Command) string
	// CompileIndex Compile a plain index key command.
	CompileIndex(blueprint Blueprint, command *Command) string
	// CompileIndexes Compile the query to determine the indexes.
	CompileIndexes(schema, table string) (string, error)
	// CompilePrimary Compile a primary key command.
	CompilePrimary(blueprint Blueprint, command *Command) string
	// CompilePrune Compile the SQL needed to prune or shrink the database.
	CompilePrune(database string) string
	// CompileRename Compile a rename table command.
	CompileRename(blueprint Blueprint, command *Command) string
	// CompileRenameColumn Compile a rename column command.
	CompileRenameColumn(blueprint Blueprint, command *Command, columns []Column) (string, error)
	// CompileRenameIndex Compile a rename index command.
	CompileRenameIndex(blueprint Blueprint, command *Command, indexes []Index) []string
	// CompileTables Compile the query to determine the tables.
	CompileTables(database string) string
	// CompileTableComment Compile a table comment command.
	CompileTableComment(blueprint Blueprint, command *Command) string
	// CompileTypes Compile the query to determine the types.
	CompileTypes() string
	// CompileUnique Compile a unique key command.
	CompileUnique(blueprint Blueprint, command *Command) string
	// CompileViews Compile the query to determine the views.
	CompileViews(database string) string
	// GetAttributeCommands Get the commands for the schema build.
	GetAttributeCommands() []string
	// TypeBigInteger Create the column definition for a big integer type.
	TypeBigInteger(column ColumnDefinition) string
	// TypeBoolean Create the column definition for a boolean type.
	TypeBoolean(column ColumnDefinition) string
	// TypeChar Create the column definition for a char type.
	TypeChar(column ColumnDefinition) string
	// TypeDate Create the column definition for a date type.
	TypeDate(column ColumnDefinition) string
	// TypeDateTime Create the column definition for a date-time type.
	TypeDateTime(column ColumnDefinition) string
	// TypeDateTimeTz Create the column definition for a date-time (with time zone) type.
	TypeDateTimeTz(column ColumnDefinition) string
	// TypeDecimal Create the column definition for a decimal type.
	TypeDecimal(column ColumnDefinition) string
	// TypeDouble Create the column definition for a double type.
	TypeDouble(column ColumnDefinition) string
	// TypeEnum Create the column definition for an enumeration type.
	TypeEnum(column ColumnDefinition) string
	// TypeFloat Create the column definition for a float type.
	TypeFloat(column ColumnDefinition) string
	// TypeInteger Create the column definition for an integer type.
	TypeInteger(column ColumnDefinition) string
	// TypeJson Create the column definition for a json type.
	TypeJson(column ColumnDefinition) string
	// TypeJsonb Create the column definition for a jsonb type.
	TypeJsonb(column ColumnDefinition) string
	// TypeLongText Create the column definition for a long text type.
	TypeLongText(column ColumnDefinition) string
	// TypeMediumInteger Create the column definition for a medium integer type.
	TypeMediumInteger(column ColumnDefinition) string
	// TypeMediumText Create the column definition for a medium text type.
	TypeMediumText(column ColumnDefinition) string
	// TypeText Create the column definition for a text type.
	TypeText(column ColumnDefinition) string
	// TypeTime Create the column definition for a time type.
	TypeTime(column ColumnDefinition) string
	// TypeTimeTz Create the column definition for a time (with time zone) type.
	TypeTimeTz(column ColumnDefinition) string
	// TypeTimestamp Create the column definition for a timestamp type.
	TypeTimestamp(column ColumnDefinition) string
	// TypeTimestampTz Create the column definition for a timestamp (with time zone) type.
	TypeTimestampTz(column ColumnDefinition) string
	// TypeTinyInteger Create the column definition for a tiny integer type.
	TypeTinyInteger(column ColumnDefinition) string
	// TypeTinyText Create the column definition for a tiny text type.
	TypeTinyText(column ColumnDefinition) string
	// TypeSmallInteger Create the column definition for a small integer type.
	TypeSmallInteger(column ColumnDefinition) string
	// TypeString Create the column definition for a string type.
	TypeString(column ColumnDefinition) string
	// TypeUuid Create the column definition for a uuid type.
	TypeUuid(column ColumnDefinition) string
}

type SchemaGrammarWithVersionResolver

type SchemaGrammarWithVersionResolver interface {
	SetVersionResolver(func() (string, error))
}

SchemaGrammarWithVersionResolver binds a grammar instance to its own managed connection, including schema connections selected after construction.

type SchemaMetadataGrammar

type SchemaMetadataGrammar interface {
	CompileSchemaMetadata(SchemaMetadataQuery) (SchemaStatement, error)
	CurrentSchemas(database string) []string
}

type SchemaMetadataQuery

type SchemaMetadataQuery struct {
	Kind, Schema, Table string
	Schemas             []string
}

type SchemaMetadataResolver

type SchemaMetadataResolver interface {
	ResolveSchemaMetadata(SchemaMetadataQuery, SchemaCatalog) (SchemaMetadataResult, error)
}

type SchemaMetadataResult

type SchemaMetadataResult struct {
	Rows      []map[string]any
	ColumnSQL []string
}

type SchemaOperation

type SchemaOperation struct {
	Kind, Name, Charset, Collation string
	Enabled                        bool
	Tables                         []Table
	Views                          []View
	Types                          []Type
}

type SchemaOperationPlanner

type SchemaOperationPlanner interface {
	SchemaOperationPolicy(SchemaOperation) SchemaExecutionPolicy
}

type SchemaOperationsGrammar

type SchemaOperationsGrammar interface {
	CompileSchemaOperation(SchemaOperation) ([]SchemaStatement, error)
	ForeignKeyStateQuery() string
}

SchemaOperationsGrammar supplies SQL; leasing sessions and restoring their original constraint state remain the schema manager's responsibility.

type SchemaSessionSetting

type SchemaSessionSetting struct {
	Read    SchemaStatement
	Value   any
	Compile func(any) SchemaStatement
}

SchemaSessionSetting describes a reversible setting on the leased writer. The framework reads its original value and restores it even after cancellation.

type SchemaStatement

type SchemaStatement struct {
	SQL      string
	Bindings []any
	// ReadOnly statements validate schema objects without executing a write.
	ReadOnly bool
}

SchemaStatement keeps values separate from SQL throughout schema execution.

type Table

type Table struct {
	SchemaQualifiedName string
	Collation           string
	Comment             string
	Engine              string
	Name                string
	Schema              string
	Size                int
}

type Type

type Type struct {
	SchemaQualifiedName string
	Category            string
	Name                string
	Schema              string
	Type                string
	Implicit            bool
}

type View

type View struct {
	SchemaQualifiedName string
	Name                string
	Schema              string
	Definition          string
}

type Where

type Where struct {
	Query any
	Args  []any
	Type  WhereType
	Or    bool
	IsNot bool
}

type WhereType

type WhereType int

WhereType type of where condition

const (
	WhereTypeBase WhereType = iota
	WhereTypeJsonContains
	WhereTypeJsonContainsKey
	WhereTypeJsonLength
)

Jump to

Keyboard shortcuts

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