Dialects API Reference
A dialect is the one place a database's quirks live: placeholder syntax, identifier quoting, upsert form, pagination, and DDL. Quark picks one for you from the driver name, so most applications never touch this API.
You need it in two cases — overriding a mis-detected dialect, and registering a dialect of your own. See Dialects for the engine-by-engine support table.
Built-In Constructors
postgres := quark.PostgreSQL()
mysql := quark.MySQL()
mariadb := quark.MariaDB()
sqlite := quark.SQLite()
mssql := quark.MSSQL()
oracle := quark.Oracle()
| Constructor | Name() |
|---|---|
quark.PostgreSQL() | postgres |
quark.MySQL() | mysql |
quark.MariaDB() | mariadb |
quark.SQLite() | sqlite |
quark.MSSQL() | mssql |
quark.Oracle() | oracle |
Interface
type Dialect interface {
Name() string
Placeholder(index int) string
Quote(identifier string) string
Placeholders(n int) []string
LimitOffset(limit, offset int) string
SupportsReturning() bool
Returning(columns ...string) string
SupportsLastInsertID() bool
LastInsertIDQuery(table, pkColumn string) string
CurrentTimestamp() string
BuildRoutineQuery(routine string, argCount int) string
BuildProcedureCall(procedure string, argCount int) string
JSONExtract(column, path string) (sql string, args []any, err error)
AlterTableAddColumn(table, column, dataType string) string
AlterTableDropColumn(table, column string) string
AlterTableAlterColumn(table, column, newDataType string) string
RenameColumn(table, oldName, newName string) string
RenameTable(oldName, newName string) string
SupportsTransactionalDDL() bool
LockSuffix(opts LockOptions) (tableHint, suffix string, err error)
UpsertSQL(conflictCols, updateCols []string, argOffset int) string
}
Placeholder Examples
| Dialect | Placeholder |
|---|---|
| PostgreSQL | $1, $2 |
| MySQL / MariaDB | ? |
| SQLite | ? |
| SQL Server | @p1, @p2 |
| Oracle | :1, :2 |
Returning and Insert IDs
| Dialect | Preferred generated-ID path |
|---|---|
| PostgreSQL | RETURNING |
| SQLite | RETURNING |
| MariaDB | RETURNING |
| MySQL | LastInsertId |
| SQL Server | SCOPE_IDENTITY() |
| Oracle | RETURNING ... INTO handling in Quark write path |
Upsert
| Dialect | Shape |
|---|---|
| PostgreSQL | ON CONFLICT (...) DO UPDATE SET ... |
| SQLite | ON CONFLICT (...) DO UPDATE SET ... |
| MySQL / MariaDB | ON DUPLICATE KEY UPDATE ... |
| SQL Server | MERGE built by Quark's CRUD layer. |
| Oracle | MERGE built by Quark's CRUD layer. |
Detection
d, err := quark.DetectDialect("postgres")
d, err = quark.DetectDialectByName("mariadb")
DetectDialectByName first checks custom dialect registrations, then falls back
to built-in detection.
Custom Dialects
quark.RegisterDialect("cockroach", myDialect)
d, err := quark.DetectDialectByName("cockroach")
if err != nil {
return err
}
client, err := quark.New("pgx", dsn, quark.WithDialect(d))
Custom dialects must implement the full Dialect interface. A partial dialect
will fail at compile time if assigned to a quark.Dialect variable.