Skip to main content
Version: 1.8.0

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()
ConstructorName()
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

DialectPlaceholder
PostgreSQL$1, $2
MySQL / MariaDB?
SQLite?
SQL Server@p1, @p2
Oracle:1, :2

Returning and Insert IDs

DialectPreferred generated-ID path
PostgreSQLRETURNING
SQLiteRETURNING
MariaDBRETURNING
MySQLLastInsertId
SQL ServerSCOPE_IDENTITY()
OracleRETURNING ... INTO handling in Quark write path

Upsert

DialectShape
PostgreSQLON CONFLICT (...) DO UPDATE SET ...
SQLiteON CONFLICT (...) DO UPDATE SET ...
MySQL / MariaDBON DUPLICATE KEY UPDATE ...
SQL ServerMERGE built by Quark's CRUD layer.
OracleMERGE 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.