feat: 新增 SQLite3 虚拟表框架及方言扩展
- 新增 dialect/sqlite3/vtab 包,提供干净的虚拟表接口(Module/Table/Cursor) - 适配层自动将 BestIndex 约束与 Filter 值绑定(ConstraintInfo.Value),无需手动编解码 IdxStr - 支持 OpLIMIT/OpOFFSET 约束下推 - 新增 SupportsDistinct 方言选项,控制 SELECT 级和表达式级 DISTINCT 生成 - sqlite3 方言注册 IF() 函数支持
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
|
||||
"git.fsdpf.net/go/db"
|
||||
sqlite3dialect "git.fsdpf.net/go/db/dialect/sqlite3"
|
||||
sqlite3vtab "git.fsdpf.net/go/db/dialect/sqlite3/vtab"
|
||||
)
|
||||
|
||||
type Engine struct {
|
||||
@@ -48,6 +49,8 @@ func (e Engine) MakeConnection(cfg DBConfig) (db *sql.DB) {
|
||||
case "mysql":
|
||||
case "sqlite3":
|
||||
driverName = sqlite3dialect.DriverWithIF
|
||||
case "vtable":
|
||||
driverName = sqlite3vtab.DriverName
|
||||
case "sqlserver":
|
||||
case "postgres":
|
||||
case "duckdb":
|
||||
|
||||
@@ -88,7 +88,7 @@ func (c *DBConfig) ToDSN() string {
|
||||
return c.toMySQLDSN()
|
||||
case "pgsql":
|
||||
return c.toPostgreSQLDSN()
|
||||
case "sqlite3":
|
||||
case "sqlite3", "vtable":
|
||||
return c.toSQLiteDSN()
|
||||
case "sqlserver":
|
||||
return c.toSQLServerDSN()
|
||||
@@ -328,6 +328,7 @@ func NewDBConfig(driver string, options ...Option) DBConfig {
|
||||
"sqlite3": true,
|
||||
"sqlserver": true,
|
||||
"duckdb": true,
|
||||
"vtable": true,
|
||||
}
|
||||
if !validDrivers[driver] {
|
||||
panic(fmt.Sprintf("Unsupported driver: %s", driver))
|
||||
@@ -363,7 +364,7 @@ func NewDBConfig(driver string, options ...Option) DBConfig {
|
||||
if config.Password == "" {
|
||||
panic(fmt.Sprintf("Password is required for %s driver", config.Driver))
|
||||
}
|
||||
case "sqlite3":
|
||||
case "sqlite3", "vtable":
|
||||
if config.SQLite.File == "" {
|
||||
panic("File is required for sqlite3 driver")
|
||||
}
|
||||
@@ -429,7 +430,7 @@ func WithWriteHosts(hosts []string) Option {
|
||||
}
|
||||
}
|
||||
|
||||
// MySQL 专用选项
|
||||
// WithMySQLCollation MySQL 专用选项
|
||||
func WithMySQLCollation(collation string) Option {
|
||||
return func(c *DBConfig) {
|
||||
if c.Driver != "mysql" {
|
||||
@@ -461,7 +462,7 @@ func WithPgSslmode(sslmode string) Option {
|
||||
// SQLite 专用选项
|
||||
func WithSQLiteFile(file string) Option {
|
||||
return func(c *DBConfig) {
|
||||
if c.Driver != "sqlite3" {
|
||||
if c.Driver != "sqlite3" && c.Driver != "vtable" {
|
||||
panic("WithSQLiteFile is only valid for sqlite3 driver")
|
||||
}
|
||||
c.SQLite.File = file
|
||||
@@ -470,7 +471,7 @@ func WithSQLiteFile(file string) Option {
|
||||
|
||||
func WithSQLiteJournal(journal string) Option {
|
||||
return func(c *DBConfig) {
|
||||
if c.Driver != "sqlite3" {
|
||||
if c.Driver != "sqlite3" && c.Driver != "vtable" {
|
||||
panic("WithSQLiteJournal is only valid for sqlite3 driver")
|
||||
}
|
||||
c.SQLite.Journal = journal
|
||||
|
||||
Reference in New Issue
Block a user