新增sqlite支持

This commit is contained in:
john
2018-08-08 20:09:52 +08:00
parent a39ebd00d0
commit 44cd5275d5
4 changed files with 24 additions and 25 deletions

View File

@ -5,20 +5,20 @@
// You can obtain one at https://gitee.com/johng/gf.
// 数据库ORM.
// 默认内置支持MySQL, 其他数据库需要手动import对应的数据库引擎第三方包.
package gdb
import (
"database/sql"
"errors"
"fmt"
"time"
"errors"
"database/sql"
"gitee.com/johng/gf/g/container/gmap"
"gitee.com/johng/gf/g/container/gring"
"gitee.com/johng/gf/g/container/gtype"
"gitee.com/johng/gf/g/os/gcache"
"gitee.com/johng/gf/g/util/grand"
_ "github.com/go-sql-driver/mysql"
_ "github.com/lib/pq"
"time"
)
const (
@ -127,8 +127,8 @@ var linkMysql = &dbmysql{}
// PostgreSQL接口对象
var linkPgsql = &dbpgsql{}
//Sqlite接口对象
//@author wxkj<wxscz@qq.com>
// Sqlite接口对象
// @author wxkj<wxscz@qq.com>
var linkSqlite = &dbsqlite{}
// 数据库查询缓存对象map使用数据库连接名称作为键名键值为查询缓存对象
@ -209,14 +209,14 @@ func getConfigNodeByPriority(cg ConfigGroup) *ConfigNode {
func newDb(masterNode *ConfigNode, slaveNode *ConfigNode, groupName string) (*Db, error) {
var link Link
switch masterNode.Type {
case "mysql":
link = linkMysql
case "pgsql":
link = linkPgsql
case "sqlite":
link = linkSqlite
default:
return nil, errors.New(fmt.Sprintf("unsupported db type '%s'", masterNode.Type))
case "mysql":
link = linkMysql
case "pgsql":
link = linkPgsql
case "sqlite":
link = linkSqlite
default:
return nil, errors.New(fmt.Sprintf("unsupported db type '%s'", masterNode.Type))
}
master, err := link.Open(masterNode)
if err != nil {

View File

@ -13,7 +13,9 @@ import (
"database/sql"
)
// postgresql的适配
// PostgreSQL的适配.
// 使用时需要import:
// _ "github.com/lib/pq"
// @todo 需要完善replace和save的操作覆盖
// 数据库链接对象

View File

@ -3,7 +3,7 @@
// 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://gitee.com/johng/gf.
//@author wxkj<wxscz@qq.com>
// @author wxkj<wxscz@qq.com>
package gdb
@ -11,6 +11,9 @@ import (
"database/sql"
)
// 使用时需要import:
// _ "github.com/mattn/go-sqlite3"
// 数据库链接对象
type dbsqlite struct {
Db
@ -21,11 +24,6 @@ func (db *dbsqlite) Open(c *ConfigNode) (*sql.DB, error) {
if c.Linkinfo != "" {
source = c.Linkinfo
} else {
//path, err := os.Getwd()
//if err != nil {
// return nil, err
//}
//先这样吧
source = c.Name
}
if db, err := sql.Open("sqlite3", source); err == nil {

View File

@ -10,12 +10,11 @@ import (
"fmt"
"errors"
"strings"
"database/sql"
_ "github.com/lib/pq"
_ "github.com/go-sql-driver/mysql"
"gitee.com/johng/gf/g/util/gconv"
"reflect"
"database/sql"
"gitee.com/johng/gf/g/os/gtime"
"gitee.com/johng/gf/g/util/gconv"
_ "github.com/go-sql-driver/mysql"
)
// 数据库事务对象