
This is useful for adding backup functionality to SQLite as seen here: https://github.com/mattn/go-sqlite3/blob/master/_example/hook/hook.go In that sample, "sqlite3_with_hook_example" is the name of the driver to be registered. I used "sqlite3hook" in my fork as a generic name. Otherwise gorm will use SQLite in compatibility mode.
39 lines
800 B
Go
39 lines
800 B
Go
package gorm
|
|
|
|
import (
|
|
"fmt"
|
|
"reflect"
|
|
"time"
|
|
)
|
|
|
|
var timeType = reflect.TypeOf(time.Time{})
|
|
|
|
type Dialect interface {
|
|
BinVar(i int) string
|
|
SupportLastInsertId() bool
|
|
SqlTag(value reflect.Value, size int) string
|
|
PrimaryKeyTag(value reflect.Value, size int) string
|
|
ReturningStr(key string) string
|
|
Quote(key string) string
|
|
HasTable(scope *Scope, tableName string) bool
|
|
HasColumn(scope *Scope, tableName string, columnName string) bool
|
|
}
|
|
|
|
func NewDialect(driver string) Dialect {
|
|
var d Dialect
|
|
switch driver {
|
|
case "postgres":
|
|
d = &postgres{}
|
|
case "mysql":
|
|
d = &mysql{}
|
|
case "sqlite3":
|
|
d = &sqlite3{}
|
|
case "sqlite3hook":
|
|
d = &sqlite3{}
|
|
default:
|
|
fmt.Printf("`%v` is not officially supported, running under compatibility mode.\n", driver)
|
|
d = &commonDialect{}
|
|
}
|
|
return d
|
|
}
|