gf/g/database/gdb/gdb_sqlite.go

49 lines
1.2 KiB
Go
Raw Normal View History

// Copyright 2017 gf Author(https://github.com/gogf/gf). All Rights Reserved.
2018-08-08 09:09:28 +08:00
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
// You can obtain one at https://github.com/gogf/gf.
2018-08-08 20:09:52 +08:00
// @author wxkj<wxscz@qq.com>
2018-08-08 09:09:28 +08:00
package gdb
import (
"database/sql"
)
2018-08-08 20:09:52 +08:00
// 使用时需要import:
// _ "github.com/gogf/gf/third/github.com/mattn/go-sqlite3"
2018-08-08 20:09:52 +08:00
2018-10-26 22:08:52 +08:00
// Sqlite接口对象
// @author wxkj<wxscz@qq.com>
2018-08-08 09:09:28 +08:00
// 数据库链接对象
2018-12-14 18:35:51 +08:00
type dbSqlite struct {
*dbBase
2018-08-08 09:09:28 +08:00
}
func (db *dbSqlite) Open(config *ConfigNode) (*sql.DB, error) {
2018-08-08 09:09:28 +08:00
var source string
if config.Linkinfo != "" {
source = config.Linkinfo
2018-08-08 09:09:28 +08:00
} else {
source = config.Name
2018-08-08 09:09:28 +08:00
}
if db, err := sql.Open("sqlite3", source); err == nil {
return db, nil
} else {
return nil, err
}
}
2018-12-14 18:35:51 +08:00
// 获得关键字操作符
func (db *dbSqlite) getChars () (charLeft string, charRight string) {
return "`", "`"
2018-08-08 09:09:28 +08:00
}
// 在执行sql之前对sql进行进一步处理
// @todo 需要增加对Save方法的支持可使用正则来实现替换
// @todo 将ON DUPLICATE KEY UPDATE触发器修改为两条SQL语句(INSERT OR IGNORE & UPDATE)
2018-12-14 18:35:51 +08:00
func (db *dbSqlite) handleSqlBeforeExec(query string) string {
return query
2018-10-26 22:08:52 +08:00
}