2014-04-25 03:20:23 +04:00
|
|
|
package gorm
|
2013-11-14 13:35:17 +04:00
|
|
|
|
2014-03-16 05:28:43 +04:00
|
|
|
import (
|
2014-07-02 13:47:30 +04:00
|
|
|
"fmt"
|
2014-03-16 05:28:43 +04:00
|
|
|
"reflect"
|
|
|
|
)
|
|
|
|
|
2013-11-14 13:35:17 +04:00
|
|
|
type Dialect interface {
|
2013-11-16 16:47:25 +04:00
|
|
|
BinVar(i int) string
|
2013-11-14 14:59:11 +04:00
|
|
|
SupportLastInsertId() bool
|
2014-09-16 00:03:14 +04:00
|
|
|
HasTop() bool
|
2015-03-11 12:05:58 +03:00
|
|
|
SqlTag(value reflect.Value, size int, autoIncrease bool) string
|
2014-12-08 14:03:42 +03:00
|
|
|
ReturningStr(tableName, key string) string
|
2014-07-30 10:18:15 +04:00
|
|
|
SelectFromDummyTable() string
|
2013-11-30 10:52:01 +04:00
|
|
|
Quote(key string) string
|
2014-04-25 05:08:48 +04:00
|
|
|
HasTable(scope *Scope, tableName string) bool
|
|
|
|
HasColumn(scope *Scope, tableName string, columnName string) bool
|
2015-03-02 18:02:40 +03:00
|
|
|
HasIndex(scope *Scope, tableName string, indexName string) bool
|
2014-07-29 08:02:03 +04:00
|
|
|
RemoveIndex(scope *Scope, indexName string)
|
2015-08-06 22:37:26 +03:00
|
|
|
CurrentDatabase(scope *Scope, name *string)
|
2013-11-14 13:35:17 +04:00
|
|
|
}
|
|
|
|
|
2014-04-25 03:20:23 +04:00
|
|
|
func NewDialect(driver string) Dialect {
|
2013-11-14 13:35:17 +04:00
|
|
|
var d Dialect
|
|
|
|
switch driver {
|
|
|
|
case "postgres":
|
2013-11-14 14:59:11 +04:00
|
|
|
d = &postgres{}
|
2015-03-24 20:33:51 +03:00
|
|
|
case "foundation":
|
|
|
|
d = &foundation{}
|
2013-11-14 13:35:17 +04:00
|
|
|
case "mysql":
|
2013-11-14 14:59:11 +04:00
|
|
|
d = &mysql{}
|
2013-11-14 13:35:17 +04:00
|
|
|
case "sqlite3":
|
2013-11-14 14:59:11 +04:00
|
|
|
d = &sqlite3{}
|
2014-09-17 01:49:29 +04:00
|
|
|
case "mssql":
|
|
|
|
d = &mssql{}
|
2014-07-02 13:47:30 +04:00
|
|
|
default:
|
|
|
|
fmt.Printf("`%v` is not officially supported, running under compatibility mode.\n", driver)
|
|
|
|
d = &commonDialect{}
|
2013-11-14 13:35:17 +04:00
|
|
|
}
|
2013-11-14 14:59:11 +04:00
|
|
|
return d
|
2013-11-14 13:35:17 +04:00
|
|
|
}
|