feat(database): 添加ClickHouse数据库驱动支持
- 新增ClickHouse数据库驱动实现 - 更新数据库驱动注册包,添加对MySQL、PostgreSQL、SQL Server、Oracle、SQLite和ClickHouse的支持 - 修改Database函数返回类型从gdb.DB到DB - 添加go.mod和go.sum依赖管理文件
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// 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.
|
||||
|
||||
// Package sqlite implements database.Driver for SQLite database.
|
||||
package sqlite
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
_ "modernc.org/sqlite"
|
||||
|
||||
"git.magicany.cc/black1552/gin-base/database"
|
||||
)
|
||||
|
||||
// Driver is the driver for SQLite database.
|
||||
type Driver struct {
|
||||
*database.Core
|
||||
}
|
||||
|
||||
const (
|
||||
quoteChar = "`"
|
||||
)
|
||||
|
||||
func init() {
|
||||
if err := database.Register("sqlite", New()); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// New creates and returns a driver that implements database.Driver for SQLite.
|
||||
func New() database.Driver {
|
||||
return &Driver{}
|
||||
}
|
||||
|
||||
// New creates and returns a database object for SQLite.
|
||||
func (d *Driver) New(core *database.Core, node *database.ConfigNode) (database.DB, error) {
|
||||
return &Driver{
|
||||
Core: core,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// GetChars returns the security char for SQLite.
|
||||
func (d *Driver) GetChars() (charLeft string, charRight string) {
|
||||
return quoteChar, quoteChar
|
||||
}
|
||||
|
||||
// Open creates and returns an underlying sql.DB object for SQLite.
|
||||
func (d *Driver) Open(config *database.ConfigNode) (*sql.DB, error) {
|
||||
// For SQLite, use the Name field as the database file path
|
||||
dbName := config.Name
|
||||
if dbName == "" {
|
||||
dbName = ":memory:"
|
||||
}
|
||||
return sql.Open("sqlite", dbName)
|
||||
}
|
||||
Reference in New Issue
Block a user