feat: 新增 DuckDB 方言支持及 SQLite3 自动注册 IF 函数
- 新增 dialect/duckdb 方言,支持 DuckDB SQL 语法 - 新增 schema/dialect/duckdb DDL 操作支持 - dialect/sqlite3: 注册 sqlite3_with_if 驱动,连接时自动注册 IF() 函数 - engine: MakeConnection 对 sqlite3 自动使用带 IF 支持的驱动 - engine: 新增 DBConfig DuckDB 配置项及相关 Option 函数 - 统一各方言测试引用路径
This commit is contained in:
@@ -1,12 +1,18 @@
|
||||
package sqlite3
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"time"
|
||||
|
||||
"git.fsdpf.net/go/db"
|
||||
"git.fsdpf.net/go/db/exp"
|
||||
gosqlite3 "github.com/mattn/go-sqlite3"
|
||||
)
|
||||
|
||||
// DriverWithIF 是注册了 IF() 函数的 SQLite3 驱动名称。
|
||||
// 使用该驱动名打开连接时,可在 SQL 中直接使用 IF(condition, trueVal, falseVal)。
|
||||
const DriverWithIF = "sqlite3_with_if"
|
||||
|
||||
func DialectOptions() *db.SQLDialectOptions {
|
||||
opts := db.DefaultDialectOptions()
|
||||
|
||||
@@ -72,5 +78,15 @@ func DialectOptions() *db.SQLDialectOptions {
|
||||
}
|
||||
|
||||
func init() {
|
||||
sql.Register(DriverWithIF, &gosqlite3.SQLiteDriver{
|
||||
ConnectHook: func(conn *gosqlite3.SQLiteConn) error {
|
||||
return conn.RegisterFunc("IF", func(cond int64, trueVal, falseVal interface{}) interface{} {
|
||||
if cond != 0 {
|
||||
return trueVal
|
||||
}
|
||||
return falseVal
|
||||
}, true)
|
||||
},
|
||||
})
|
||||
db.RegisterDialect("sqlite3", DialectOptions())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user