Skip to content

dialects

Geofrey Ernest edited this page Aug 2, 2017 · 2 revisions

Dialects

ngorm has support for multiple databases with the concept of dialects.

Aything that implements the following interface is a valid dialect

type Dialect interface {
    // GetName get dialect's name
    GetName() string

    // SetDB set db for dialect
    SetDB(db model.SQLCommon)

    // BindVar return the placeholder for actual values in SQL statements, in many dbs it is "?", Postgres using $1
    BindVar(i int) string
    // Quote quotes field name to avoid SQL parsing exceptions by using a reserved word as a field name
    Quote(key string) string

    // DataTypeOf return data's sql type
    DataTypeOf(field *model.StructField) (string, error)

    // HasIndex check has index or not
    HasIndex(tableName string, indexName string) bool
    // HasForeignKey check has foreign key or not
    HasForeignKey(tableName string, foreignKeyName string) bool
    // RemoveIndex remove index
    RemoveIndex(tableName string, indexName string) error
    // HasTable check has table or not
    HasTable(tableName string) bool
    // HasColumn check has column or not
    HasColumn(tableName string, columnName string) bool

    // LimitAndOffsetSQL return generated SQL with Limit and Offset, as mssql has special case
    LimitAndOffsetSQL(limit, offset interface{}) string
    // SelectFromDummyTable return select values, for most dbs, `SELECT values` just works, mysql needs `SELECT value FROM DUAL`
    SelectFromDummyTable() string
    // LastInsertIdReturningSuffix most dbs support LastInsertId, but postgres needs to use `RETURNING`
    LastInsertIDReturningSuffix(tableName, columnName string) string

    // BuildForeignKeyName returns a foreign key name for the given table, field and reference
    BuildForeignKeyName(tableName, field, dest string) string

    // CurrentDatabase return current database name
    CurrentDatabase() string

    PrimaryKey([]string) string

    QueryFieldName(string) string
}
Clone this wiki locally