Documentation
¶
Overview ¶
Package dialect adapts SQL rendering — identifiers, placeholders, type mapping, autoincrement syntax, LIMIT/OFFSET — to one database engine.
Built-in implementations: SQLite, MySQL, Postgres (registered via init). Custom types registered via RegisterCustomType take precedence over the dialect's built-in MapType lookup.
Index ¶
- Variables
- func Names() []string
- func Register(name string, d Dialect)
- func RegisterCustomType(rt reflect.Type, sqlType string)
- func RegisterE(name string, d Dialect) error
- type Dialect
- type MySQL
- type Postgres
- func (Postgres) AutoIncrement() string
- func (Postgres) AutoIncrementInlinePK() bool
- func (Postgres) LimitOffset(limit, offset int) string
- func (Postgres) MapType(t reflect.Type) (string, error)
- func (Postgres) Name() string
- func (Postgres) Placeholder(i int) string
- func (Postgres) QuoteIdent(s string) string
- type SQLite
Constants ¶
This section is empty.
Variables ¶
var ( ErrDialectNotSupported = errors.New("dialect: not supported") ErrTypeNotSupported = errors.New("dialect: type not supported") ErrDialectRegistered = errors.New("dialect: already registered") )
ErrDialectNotSupported is returned by Get for an unregistered dialect name. ErrTypeNotSupported is returned by a dialect's MapType for a Go type it cannot map to a SQL column type. ErrDialectRegistered is returned by RegisterE when name is already registered.
Functions ¶
func Register ¶
Register adds a Dialect under name. It panics if name is already registered, mirroring database/sql.Register. Library code that prefers an error over a panic should call RegisterE.
func RegisterCustomType ¶
RegisterCustomType maps a Go type to a SQL column type name. Registered types take precedence over the dialect's built-in MapType lookup. This allows mapping [16]byte to BINARY(16), *big.Int to DECIMAL, or any custom type.
Types ¶
type Dialect ¶
type Dialect interface {
Name() string
Placeholder(i int) string
QuoteIdent(s string) string
MapType(t reflect.Type) (string, error)
AutoIncrement() string
// AutoIncrementInlinePK reports whether an autoincrement column must carry
// PRIMARY KEY inline on its column definition (SQLite: INTEGER PRIMARY KEY
// AUTOINCREMENT). When true the table-level PRIMARY KEY constraint is
// omitted for the autoincrement column; when false it is emitted as a
// separate constraint.
AutoIncrementInlinePK() bool
LimitOffset(limit, offset int) string
}
Dialect adapts SQL rendering — identifiers, placeholders, type mapping, autoincrement syntax, LIMIT/OFFSET — to one database engine. The three built-in implementations (SQLite, MySQL, Postgres) register themselves in init via dialect.Register and are reachable through dialect.Get.
type MySQL ¶
type MySQL struct{}
MySQL adapts SQL rendering for MySQL-compatible databases.
func (MySQL) AutoIncrement ¶
func (MySQL) AutoIncrementInlinePK ¶
func (MySQL) LimitOffset ¶
func (MySQL) Placeholder ¶
func (MySQL) QuoteIdent ¶
type Postgres ¶
type Postgres struct{}
Postgres adapts SQL rendering for PostgreSQL-compatible databases.
func (Postgres) AutoIncrement ¶
func (Postgres) AutoIncrementInlinePK ¶
func (Postgres) LimitOffset ¶
func (Postgres) Placeholder ¶
func (Postgres) QuoteIdent ¶
type SQLite ¶
type SQLite struct{}
SQLite adapts SQL rendering for SQLite databases.