1 Star 0 Fork 15

unsafe-rust/gosql

forked from fifsky/gosql 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
dialect.go 1.19 KB
一键复制 编辑 原始数据 按行查看 历史
fifsky 提交于 2019-10-16 16:19 . support postgres sql quotes,fix #15
package gosql
import (
"fmt"
)
// Dialect interface contains behaviors that differ across SQL database
type Dialect interface {
// GetName get dialect's name
GetName() string
// Quote quotes field name to avoid SQL parsing exceptions by using a reserved word as a field name
Quote(key string) string
}
type commonDialect struct {
}
func (commonDialect) GetName() string {
return "common"
}
func (commonDialect) Quote(key string) string {
return fmt.Sprintf(`"%s"`, key)
}
var dialectsMap = map[string]Dialect{}
// RegisterDialect register new dialect
func RegisterDialect(name string, dialect Dialect) {
dialectsMap[name] = dialect
}
// GetDialect gets the dialect for the specified dialect name
func GetDialect(name string) (dialect Dialect, ok bool) {
dialect, ok = dialectsMap[name]
return
}
func mustGetDialect(name string) Dialect {
if dialect, ok := dialectsMap[name]; ok {
return dialect
}
panic(fmt.Sprintf("`%v` is not officially supported", name))
return nil
}
func newDialect(name string) Dialect {
if value, ok := GetDialect(name); ok {
return value
}
fmt.Printf("`%v` is not officially supported, running under compatibility mode.\n", name)
return &commonDialect{}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/unsafe-rust/gosql.git
git@gitee.com:unsafe-rust/gosql.git
unsafe-rust
gosql
gosql
master

搜索帮助