dialect

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package dialect provides database-specific SQL generation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dialect

type Dialect interface {
	// Name returns the dialect name (e.g., "postgresql", "mysql").
	Name() string

	// CreateTableSQL generates a CREATE TABLE statement.
	CreateTableSQL(table *types.Table) string

	// CreateTableIfNotExistsSQL generates a CREATE TABLE IF NOT EXISTS statement.
	CreateTableIfNotExistsSQL(table *types.Table) string

	// DropTableSQL generates a DROP TABLE statement.
	DropTableSQL(schema, name string) string

	// DropTableIfExistsSQL generates a DROP TABLE IF EXISTS statement.
	DropTableIfExistsSQL(schema, name string) string

	// AlterTableSQL generates ALTER TABLE statements for all actions.
	AlterTableSQL(schema, tableName string, actions []*types.TableAction) []string

	// HasTableSQL returns SQL to check if a table exists (returns count).
	HasTableSQL(schema, tableName string) string

	// HasColumnSQL returns SQL to check if a column exists (returns count).
	HasColumnSQL(schema, tableName, columnName string) string

	// ColumnDefinitionSQL generates the column definition for use in CREATE TABLE.
	ColumnDefinitionSQL(col *types.Column) string

	// CommentColumnSQL returns SQL to add a comment to a column.
	CommentColumnSQL(tableName, columnName, comment string) string

	// QuoteIdentifier quotes an identifier (table/column name) for this dialect.
	QuoteIdentifier(name string) string

	// QualifyTable returns a schema-qualified table name.
	// If schema is empty, returns just the quoted table name.
	QualifyTable(schema, tableName string) string

	// CreateMigrationsTableSQL returns SQL to create the migrations tracking table.
	CreateMigrationsTableSQL(tableName string) string

	// InsertMigrationSQL returns parameterized SQL to record a migration.
	// Parameters: $1=name, $2=batch
	InsertMigrationSQL(tableName string) string

	// DeleteMigrationSQL returns parameterized SQL to remove a migration record.
	// Parameters: $1=name
	DeleteMigrationSQL(tableName string) string

	// GetAppliedMigrationsSQL returns SQL to get all applied migration names.
	GetAppliedMigrationsSQL(tableName string) string

	// GetLastBatchSQL returns SQL to get the highest batch number.
	GetLastBatchSQL(tableName string) string

	// GetMigrationsByBatchSQL returns parameterized SQL to get migrations for a batch.
	// Parameters: $1=batch
	GetMigrationsByBatchSQL(tableName string) string
}

Dialect defines the interface for database-specific SQL generation.

func GetDialect

func GetDialect(name string) Dialect

GetDialect returns a dialect implementation by name.

type MySQLDialect

type MySQLDialect struct{}

MySQLDialect implements Dialect for MySQL.

func (*MySQLDialect) AlterTableSQL

func (d *MySQLDialect) AlterTableSQL(schema, tableName string, actions []*types.TableAction) []string

AlterTableSQL generates ALTER TABLE statements for all actions.

func (*MySQLDialect) ColumnDefinitionSQL

func (d *MySQLDialect) ColumnDefinitionSQL(col *types.Column) string

ColumnDefinitionSQL generates the column definition SQL.

func (*MySQLDialect) CommentColumnSQL

func (d *MySQLDialect) CommentColumnSQL(tableName, columnName, comment string) string

CommentColumnSQL returns SQL to add a comment to a column in MySQL. Note: MySQL supports inline COMMENT in CREATE TABLE.

func (*MySQLDialect) CreateMigrationsTableSQL

func (d *MySQLDialect) CreateMigrationsTableSQL(tableName string) string

CreateMigrationsTableSQL returns SQL to create the migrations tracking table.

func (*MySQLDialect) CreateTableIfNotExistsSQL

func (d *MySQLDialect) CreateTableIfNotExistsSQL(table *types.Table) string

CreateTableIfNotExistsSQL generates a CREATE TABLE IF NOT EXISTS statement.

func (*MySQLDialect) CreateTableSQL

func (d *MySQLDialect) CreateTableSQL(table *types.Table) string

CreateTableSQL generates a CREATE TABLE statement for MySQL.

func (*MySQLDialect) DeleteMigrationSQL

func (d *MySQLDialect) DeleteMigrationSQL(tableName string) string

DeleteMigrationSQL returns parameterized SQL to remove a migration record.

func (*MySQLDialect) DropTableIfExistsSQL

func (d *MySQLDialect) DropTableIfExistsSQL(schema, name string) string

DropTableIfExistsSQL generates a DROP TABLE IF EXISTS statement.

func (*MySQLDialect) DropTableSQL

func (d *MySQLDialect) DropTableSQL(schema, name string) string

DropTableSQL generates a DROP TABLE statement.

func (*MySQLDialect) GetAppliedMigrationsSQL

func (d *MySQLDialect) GetAppliedMigrationsSQL(tableName string) string

GetAppliedMigrationsSQL returns SQL to get all applied migration names ordered by id.

func (*MySQLDialect) GetLastBatchSQL

func (d *MySQLDialect) GetLastBatchSQL(tableName string) string

GetLastBatchSQL returns SQL to get the highest batch number.

func (*MySQLDialect) GetMigrationsByBatchSQL

func (d *MySQLDialect) GetMigrationsByBatchSQL(tableName string) string

GetMigrationsByBatchSQL returns parameterized SQL to get migrations for a batch.

func (*MySQLDialect) HasColumnSQL

func (d *MySQLDialect) HasColumnSQL(schema, tableName, columnName string) string

HasColumnSQL returns SQL to check if a column exists in MySQL.

func (*MySQLDialect) HasTableSQL

func (d *MySQLDialect) HasTableSQL(schema, tableName string) string

HasTableSQL returns SQL to check if a table exists in MySQL.

func (*MySQLDialect) InsertMigrationSQL

func (d *MySQLDialect) InsertMigrationSQL(tableName string) string

InsertMigrationSQL returns parameterized SQL to record a migration.

func (*MySQLDialect) Name

func (d *MySQLDialect) Name() string

Name returns "mysql".

func (*MySQLDialect) QualifyTable

func (d *MySQLDialect) QualifyTable(schema, tableName string) string

QualifyTable returns a schema-qualified table name. MySQL uses database.table syntax.

func (*MySQLDialect) QuoteIdentifier

func (d *MySQLDialect) QuoteIdentifier(name string) string

QuoteIdentifier quotes an identifier with backticks for MySQL.

type PostgresDialect

type PostgresDialect struct{}

PostgresDialect implements Dialect for PostgreSQL.

func (*PostgresDialect) AlterTableSQL

func (d *PostgresDialect) AlterTableSQL(schema, tableName string, actions []*types.TableAction) []string

AlterTableSQL generates ALTER TABLE statements for all actions.

func (*PostgresDialect) ColumnDefinitionSQL

func (d *PostgresDialect) ColumnDefinitionSQL(col *types.Column) string

ColumnDefinitionSQL generates the column definition SQL.

func (*PostgresDialect) CommentColumnSQL

func (d *PostgresDialect) CommentColumnSQL(tableName, columnName, comment string) string

CommentColumnSQL returns SQL to add a comment to a column in PostgreSQL. tableName should be pre-qualified (e.g., from QualifyTable).

func (*PostgresDialect) CreateMigrationsTableSQL

func (d *PostgresDialect) CreateMigrationsTableSQL(tableName string) string

CreateMigrationsTableSQL returns SQL to create the migrations tracking table in public schema.

func (*PostgresDialect) CreateTableIfNotExistsSQL

func (d *PostgresDialect) CreateTableIfNotExistsSQL(table *types.Table) string

CreateTableIfNotExistsSQL generates a CREATE TABLE IF NOT EXISTS statement.

func (*PostgresDialect) CreateTableSQL

func (d *PostgresDialect) CreateTableSQL(table *types.Table) string

CreateTableSQL generates a CREATE TABLE statement for PostgreSQL.

func (*PostgresDialect) DeleteMigrationSQL

func (d *PostgresDialect) DeleteMigrationSQL(tableName string) string

DeleteMigrationSQL returns parameterized SQL to remove a migration record.

func (*PostgresDialect) DropTableIfExistsSQL

func (d *PostgresDialect) DropTableIfExistsSQL(schema, name string) string

DropTableIfExistsSQL generates a DROP TABLE IF EXISTS statement.

func (*PostgresDialect) DropTableSQL

func (d *PostgresDialect) DropTableSQL(schema, name string) string

DropTableSQL generates a DROP TABLE statement.

func (*PostgresDialect) GetAppliedMigrationsSQL

func (d *PostgresDialect) GetAppliedMigrationsSQL(tableName string) string

GetAppliedMigrationsSQL returns SQL to get all applied migration names ordered by id.

func (*PostgresDialect) GetLastBatchSQL

func (d *PostgresDialect) GetLastBatchSQL(tableName string) string

GetLastBatchSQL returns SQL to get the highest batch number.

func (*PostgresDialect) GetMigrationsByBatchSQL

func (d *PostgresDialect) GetMigrationsByBatchSQL(tableName string) string

GetMigrationsByBatchSQL returns parameterized SQL to get migrations for a batch.

func (*PostgresDialect) HasColumnSQL

func (d *PostgresDialect) HasColumnSQL(schema, tableName, columnName string) string

HasColumnSQL returns SQL to check if a column exists in PostgreSQL.

func (*PostgresDialect) HasTableSQL

func (d *PostgresDialect) HasTableSQL(schema, tableName string) string

HasTableSQL returns SQL to check if a table exists in PostgreSQL.

func (*PostgresDialect) InsertMigrationSQL

func (d *PostgresDialect) InsertMigrationSQL(tableName string) string

InsertMigrationSQL returns parameterized SQL to record a migration.

func (*PostgresDialect) Name

func (d *PostgresDialect) Name() string

Name returns "postgresql".

func (*PostgresDialect) QualifyTable

func (d *PostgresDialect) QualifyTable(schema, tableName string) string

QualifyTable returns a schema-qualified table name.

func (*PostgresDialect) QuoteIdentifier

func (d *PostgresDialect) QuoteIdentifier(name string) string

QuoteIdentifier quotes an identifier with double quotes for PostgreSQL.

Jump to

Keyboard shortcuts

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