Documentation
¶
Overview ¶
Package dialect provides database-specific implementations for Rain ORM. Implement this interface to add support for new database engines.
Index ¶
- func HasAnyFeature(features, feature Feature) bool
- func HasFeature(features, feature Feature) bool
- type BaseDialect
- type Dialect
- type Feature
- type MySQLDialect
- func (d *MySQLDialect) AutoIncrementKeyword() string
- func (d *MySQLDialect) BooleanLiteral(v bool) string
- func (d *MySQLDialect) CurrentTimestamp() string
- func (d *MySQLDialect) DataType(columnType schema.ColumnType) string
- func (d *MySQLDialect) DefaultValue(value interface{}) string
- func (d *MySQLDialect) Features() Feature
- func (d *MySQLDialect) LimitOffset(limit, offset int) string
- func (d *MySQLDialect) Name() string
- func (d *MySQLDialect) Placeholder(n int) string
- func (d *MySQLDialect) QuoteIdentifier(name string) string
- func (d *MySQLDialect) UpsertClause(table string, conflictCols []string, updateCols []string) string
- type PostgresDialect
- func (d *PostgresDialect) AutoIncrementKeyword() string
- func (d *PostgresDialect) BooleanLiteral(v bool) string
- func (d *PostgresDialect) CurrentTimestamp() string
- func (d *PostgresDialect) DataType(columnType schema.ColumnType) string
- func (d *PostgresDialect) DefaultValue(value interface{}) string
- func (d *PostgresDialect) Features() Feature
- func (d *PostgresDialect) LimitOffset(limit, offset int) string
- func (d *PostgresDialect) Name() string
- func (d *PostgresDialect) Placeholder(n int) string
- func (d *PostgresDialect) QuoteIdentifier(name string) string
- func (d *PostgresDialect) UpsertClause(table string, conflictCols []string, updateCols []string) string
- type SQLiteDialect
- func (d *SQLiteDialect) AutoIncrementKeyword() string
- func (d *SQLiteDialect) BooleanLiteral(v bool) string
- func (d *SQLiteDialect) CurrentTimestamp() string
- func (d *SQLiteDialect) DataType(columnType schema.ColumnType) string
- func (d *SQLiteDialect) DefaultValue(value interface{}) string
- func (d *SQLiteDialect) Features() Feature
- func (d *SQLiteDialect) LimitOffset(limit, offset int) string
- func (d *SQLiteDialect) Name() string
- func (d *SQLiteDialect) Placeholder(n int) string
- func (d *SQLiteDialect) QuoteIdentifier(name string) string
- func (d *SQLiteDialect) UpsertClause(table string, conflictCols []string, updateCols []string) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HasAnyFeature ¶
HasAnyFeature reports whether a feature set includes any requested capability.
func HasFeature ¶
HasFeature reports whether a feature set includes the requested capability.
Types ¶
type BaseDialect ¶
type BaseDialect struct{}
BaseDialect provides common implementations.
func (*BaseDialect) DataType ¶
func (d *BaseDialect) DataType(columnType schema.ColumnType) string
DataType returns default SQL type mapping.
func (*BaseDialect) DefaultValue ¶
func (d *BaseDialect) DefaultValue(value interface{}) string
DefaultValue returns default value representation.
func (*BaseDialect) Features ¶
func (d *BaseDialect) Features() Feature
Features returns the default shared feature set.
func (*BaseDialect) UpsertClause ¶
func (d *BaseDialect) UpsertClause(table string, conflictCols []string, updateCols []string) string
UpsertClause returns generic upsert syntax.
type Dialect ¶
type Dialect interface {
// Name returns the dialect name (e.g., "postgres", "mysql", "sqlite").
Name() string
// Features returns the set of SQL capabilities supported by the dialect.
Features() Feature
// QuoteIdentifier quotes a database identifier (table/column name).
QuoteIdentifier(name string) string
// Placeholder returns the parameter placeholder for the nth parameter.
Placeholder(n int) string
// DataType returns the SQL type for a given schema column type.
DataType(columnType schema.ColumnType) string
// DefaultValue returns the SQL representation of a default value.
DefaultValue(value interface{}) string
// AutoIncrementKeyword returns the auto-increment keyword.
AutoIncrementKeyword() string
// LimitOffset returns the LIMIT/OFFSET clause SQL.
LimitOffset(limit, offset int) string
// UpsertClause returns the UPSERT syntax (INSERT ... ON CONFLICT, etc.).
UpsertClause(table string, conflictCols []string, updateCols []string) string
// CurrentTimestamp returns the SQL for current timestamp.
CurrentTimestamp() string
// BooleanLiteral returns the SQL boolean literal (TRUE/FALSE or 1/0).
BooleanLiteral(v bool) string
}
Dialect represents a database-specific SQL dialect.
func GetDialect ¶
GetDialect returns a dialect by name.
type MySQLDialect ¶
type MySQLDialect struct {
BaseDialect
}
MySQLDialect implements MySQL-specific SQL.
func (*MySQLDialect) AutoIncrementKeyword ¶
func (d *MySQLDialect) AutoIncrementKeyword() string
AutoIncrementKeyword returns AUTO_INCREMENT for MySQL.
func (*MySQLDialect) BooleanLiteral ¶
func (d *MySQLDialect) BooleanLiteral(v bool) string
BooleanLiteral returns MySQL boolean literals.
func (*MySQLDialect) CurrentTimestamp ¶
func (d *MySQLDialect) CurrentTimestamp() string
CurrentTimestamp returns MySQL current timestamp.
func (*MySQLDialect) DataType ¶
func (d *MySQLDialect) DataType(columnType schema.ColumnType) string
DataType returns MySQL-specific type.
func (*MySQLDialect) DefaultValue ¶
func (d *MySQLDialect) DefaultValue(value interface{}) string
DefaultValue returns MySQL default value.
func (*MySQLDialect) Features ¶
func (d *MySQLDialect) Features() Feature
Features returns MySQL capabilities supported by Rain.
func (*MySQLDialect) LimitOffset ¶
func (d *MySQLDialect) LimitOffset(limit, offset int) string
LimitOffset returns MySQL LIMIT/OFFSET syntax.
func (*MySQLDialect) Placeholder ¶
func (d *MySQLDialect) Placeholder(n int) string
Placeholder returns MySQL-style ? placeholders.
func (*MySQLDialect) QuoteIdentifier ¶
func (d *MySQLDialect) QuoteIdentifier(name string) string
QuoteIdentifier quotes identifiers with backticks. Inner backticks are escaped by doubling them.
func (*MySQLDialect) UpsertClause ¶
func (d *MySQLDialect) UpsertClause(table string, conflictCols []string, updateCols []string) string
UpsertClause returns MySQL upsert syntax.
type PostgresDialect ¶
type PostgresDialect struct {
BaseDialect
}
PostgresDialect implements PostgreSQL-specific SQL.
func (*PostgresDialect) AutoIncrementKeyword ¶
func (d *PostgresDialect) AutoIncrementKeyword() string
AutoIncrementKeyword returns SERIAL for PostgreSQL.
func (*PostgresDialect) BooleanLiteral ¶
func (d *PostgresDialect) BooleanLiteral(v bool) string
BooleanLiteral returns PostgreSQL boolean literals.
func (*PostgresDialect) CurrentTimestamp ¶
func (d *PostgresDialect) CurrentTimestamp() string
CurrentTimestamp returns PostgreSQL current timestamp.
func (*PostgresDialect) DataType ¶
func (d *PostgresDialect) DataType(columnType schema.ColumnType) string
DataType returns PostgreSQL-specific type.
func (*PostgresDialect) DefaultValue ¶
func (d *PostgresDialect) DefaultValue(value interface{}) string
DefaultValue returns PostgreSQL default value.
func (*PostgresDialect) Features ¶
func (d *PostgresDialect) Features() Feature
Features returns PostgreSQL capabilities supported by Rain.
func (*PostgresDialect) LimitOffset ¶
func (d *PostgresDialect) LimitOffset(limit, offset int) string
LimitOffset returns PostgreSQL LIMIT/OFFSET syntax.
func (*PostgresDialect) Name ¶
func (d *PostgresDialect) Name() string
Name returns the dialect name.
func (*PostgresDialect) Placeholder ¶
func (d *PostgresDialect) Placeholder(n int) string
Placeholder returns PostgreSQL-style $n placeholders.
func (*PostgresDialect) QuoteIdentifier ¶
func (d *PostgresDialect) QuoteIdentifier(name string) string
QuoteIdentifier quotes identifiers with double quotes. Inner double quotes are escaped by doubling them.
func (*PostgresDialect) UpsertClause ¶
func (d *PostgresDialect) UpsertClause(table string, conflictCols []string, updateCols []string) string
UpsertClause returns PostgreSQL upsert syntax.
type SQLiteDialect ¶
type SQLiteDialect struct {
BaseDialect
}
SQLiteDialect implements SQLite-specific SQL.
func (*SQLiteDialect) AutoIncrementKeyword ¶
func (d *SQLiteDialect) AutoIncrementKeyword() string
AutoIncrementKeyword returns AUTOINCREMENT for SQLite.
func (*SQLiteDialect) BooleanLiteral ¶
func (d *SQLiteDialect) BooleanLiteral(v bool) string
BooleanLiteral returns SQLite boolean literals.
func (*SQLiteDialect) CurrentTimestamp ¶
func (d *SQLiteDialect) CurrentTimestamp() string
CurrentTimestamp returns SQLite current timestamp.
func (*SQLiteDialect) DataType ¶
func (d *SQLiteDialect) DataType(columnType schema.ColumnType) string
DataType returns SQLite-specific type.
func (*SQLiteDialect) DefaultValue ¶
func (d *SQLiteDialect) DefaultValue(value interface{}) string
DefaultValue returns SQLite default value.
func (*SQLiteDialect) Features ¶
func (d *SQLiteDialect) Features() Feature
Features returns SQLite capabilities supported by Rain.
func (*SQLiteDialect) LimitOffset ¶
func (d *SQLiteDialect) LimitOffset(limit, offset int) string
LimitOffset returns SQLite LIMIT/OFFSET syntax.
func (*SQLiteDialect) Placeholder ¶
func (d *SQLiteDialect) Placeholder(n int) string
Placeholder returns SQLite-style ? placeholders.
func (*SQLiteDialect) QuoteIdentifier ¶
func (d *SQLiteDialect) QuoteIdentifier(name string) string
QuoteIdentifier quotes identifiers with double quotes. Inner double quotes are escaped by doubling them.
func (*SQLiteDialect) UpsertClause ¶
func (d *SQLiteDialect) UpsertClause(table string, conflictCols []string, updateCols []string) string
UpsertClause returns SQLite upsert syntax.