Documentation
¶
Overview ¶
Package dialect defines the per-database adapter contract and a registry.
Index ¶
- func JSONPathString(path []string) string
- func QuoteWith(ident, open, closing string, upper bool) string
- func Register(d Dialect, aliases ...string)
- type Base
- func (Base) AddColumnKeyword() string
- func (Base) BoolLiteral(b bool) string
- func (Base) DatePart(col string, part DatePart) string
- func (Base) DriverDSN(dsn string) string
- func (Base) FullTextIndex(string, string, []string) string
- func (Base) FullTextMatch([]string, bool) string
- func (Base) JSONExtract(string, []string) string
- func (Base) LockSQL(mode LockMode) string
- func (Base) NativeEnum() bool
- func (Base) SupportsAddConstraint() bool
- func (Base) SupportsIndexes() bool
- func (Base) TransactionalDDL() bool
- type Column
- type DatePart
- type Dialect
- type Features
- type Kind
- type LockMode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func JSONPathString ¶
JSONPathString renders path as "$.a.b[0]" for databases that take a JSON path string.
Types ¶
type Base ¶
type Base struct{}
Base provides ANSI defaults; dialects embed it and override what differs.
func (Base) AddColumnKeyword ¶
func (Base) BoolLiteral ¶
func (Base) NativeEnum ¶
func (Base) SupportsAddConstraint ¶
func (Base) SupportsIndexes ¶
func (Base) TransactionalDDL ¶
type Dialect ¶
type Dialect interface {
Name() string
Dialector(dsn string) gorm.Dialector
// DriverName is the database/sql driver name; DriverDSN adapts the DSN for it.
// FromConn builds a Dialector on top of an existing pool (used for AfterCreate hooks,
// acquire timeouts and replicas).
DriverName() string
DriverDSN(dsn string) string
FromConn(conn gorm.ConnPool) gorm.Dialector
Quote(ident string) string
ColumnType(c Column) string
// AutoIncrement returns the full column definition (after the column name) for an auto-increment primary key.
AutoIncrement(big bool) string
BoolLiteral(b bool) string
AddColumnKeyword() string
RenameTable(from, to string) string
RenameColumn(table, from, to string) string
DropIndex(table, name string) string
DropConstraint(table, name string) string
DropForeign(table, name string) string
SupportsAddConstraint() bool
SupportsIndexes() bool
NativeEnum() bool
TransactionalDDL() bool
}
Dialect is implemented once per supported database family. Methods returning SQL return "" when the operation is unsupported.
type Features ¶
type Features interface {
// LockSQL is the clause appended to a SELECT, e.g. "FOR UPDATE".
LockSQL(mode LockMode) string
// JSONExtract reads the text at a JSON path (already validated: dot-separated names or indexes).
JSONExtract(col string, path []string) string
// DatePart reduces a date/time column to its date, year, month or day.
DatePart(col string, part DatePart) string
// FullTextMatch is a boolean expression with exactly one "?" for the search text.
// boolean asks for operator syntax (+word -word "phrase") where the database has it.
FullTextMatch(cols []string, boolean bool) string
// FullTextIndex is the statement that creates an index FullTextMatch can use.
FullTextIndex(table, name string, cols []string) string
}
Features are the query-building differences between databases that the ORM needs beyond Quote. Every method returns "" when the database cannot do it, and the caller turns that into an UNSUPPORTED_FEATURE error. Identifiers arrive already quoted; Base supplies ANSI defaults, so a dialect overrides only what differs.
func FeaturesOf ¶
FeaturesOf returns d's Features, or one that supports nothing when d predates them.
type Kind ¶
type Kind string
Kind is a database-agnostic column type.
const ( KindString Kind = "string" KindText Kind = "text" KindSmallInt Kind = "smallint" KindInteger Kind = "integer" KindBigInt Kind = "bigint" KindBoolean Kind = "boolean" KindFloat Kind = "float" KindDouble Kind = "double" KindDecimal Kind = "decimal" KindDate Kind = "date" KindTime Kind = "time" KindDateTime Kind = "datetime" KindStamp Kind = "timestamp" KindJSON Kind = "json" KindUUID Kind = "uuid" KindBinary Kind = "binary" KindEnum Kind = "enum" )
Directories
¶
| Path | Synopsis |
|---|---|
|
Package mysql registers MySQL and MariaDB.
|
Package mysql registers MySQL and MariaDB. |
|
Package oracle registers Oracle Database using the pure-Go go-ora driver (no cgo).
|
Package oracle registers Oracle Database using the pure-Go go-ora driver (no cgo). |
|
Package postgres registers PostgreSQL, CockroachDB and Redshift.
|
Package postgres registers PostgreSQL, CockroachDB and Redshift. |
|
Package sqlite registers SQLite using the pure-Go (no cgo) glebarez driver.
|
Package sqlite registers SQLite using the pure-Go (no cgo) glebarez driver. |
|
Package sqlserver registers Microsoft SQL Server.
|
Package sqlserver registers Microsoft SQL Server. |