[feat] Sqlite3Grammar 调整
This commit is contained in:
parent
71def3bd03
commit
9ec1f7b888
15
builder.go
15
builder.go
@ -323,10 +323,8 @@ func Clone(original *Builder) *Builder {
|
|||||||
}
|
}
|
||||||
} else if original.Connection.Config.Driver == DriverSqlite3 {
|
} else if original.Connection.Config.Driver == DriverSqlite3 {
|
||||||
newBuilder.Grammar = &Sqlite3Grammar{
|
newBuilder.Grammar = &Sqlite3Grammar{
|
||||||
MysqlGrammar: &MysqlGrammar{
|
|
||||||
Prefix: original.Grammar.GetTablePrefix(),
|
Prefix: original.Grammar.GetTablePrefix(),
|
||||||
Builder: &newBuilder,
|
Builder: &newBuilder,
|
||||||
},
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
panic("不支持的数据库类型")
|
panic("不支持的数据库类型")
|
||||||
@ -338,7 +336,8 @@ func (b *Builder) Clone() *Builder {
|
|||||||
return Clone(b)
|
return Clone(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*CloneWithout
|
/*
|
||||||
|
CloneWithout
|
||||||
CloneWithoutClone the query without the given properties.
|
CloneWithoutClone the query without the given properties.
|
||||||
*/
|
*/
|
||||||
func CloneWithout(original *Builder, without ...string) *Builder {
|
func CloneWithout(original *Builder, without ...string) *Builder {
|
||||||
@ -1261,6 +1260,7 @@ func (b *Builder) OrWhereNotIn(params ...interface{}) *Builder {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
WhereNull Add a "where null" clause to the query.
|
WhereNull Add a "where null" clause to the query.
|
||||||
|
|
||||||
params takes in below order:
|
params takes in below order:
|
||||||
1. column string
|
1. column string
|
||||||
2. boolean string in [2]string{"and","or"}
|
2. boolean string in [2]string{"and","or"}
|
||||||
@ -1351,7 +1351,6 @@ WhereBetween Add a where between statement to the query.
|
|||||||
1. WhereBetween(column string,values []interface{"min","max"})
|
1. WhereBetween(column string,values []interface{"min","max"})
|
||||||
2. WhereBetween(column string,values []interface{"min","max"},"and/or")
|
2. WhereBetween(column string,values []interface{"min","max"},"and/or")
|
||||||
3. WhereBetween(column string,values []interface{"min","max","and/or",true/false})
|
3. WhereBetween(column string,values []interface{"min","max","and/or",true/false})
|
||||||
|
|
||||||
*/
|
*/
|
||||||
func (b *Builder) WhereBetween(params ...interface{}) *Builder {
|
func (b *Builder) WhereBetween(params ...interface{}) *Builder {
|
||||||
paramsLength := len(params)
|
paramsLength := len(params)
|
||||||
@ -1994,7 +1993,6 @@ func (b *Builder) DoesntExist() (notExists bool, err error) {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
Aggregate Execute an aggregate function on the database.
|
Aggregate Execute an aggregate function on the database.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
func (b *Builder) Aggregate(dest interface{}, fn string, column ...string) (result sql.Result, err error) {
|
func (b *Builder) Aggregate(dest interface{}, fn string, column ...string) (result sql.Result, err error) {
|
||||||
b.Dest = dest
|
b.Dest = dest
|
||||||
@ -2308,7 +2306,6 @@ When Apply the callback if the given "value" is truthy.
|
|||||||
|
|
||||||
1. When(true,func(builder *Builder))
|
1. When(true,func(builder *Builder))
|
||||||
2. When(true,func(builder *Builder),func(builder *Builder)) //with default callback
|
2. When(true,func(builder *Builder),func(builder *Builder)) //with default callback
|
||||||
|
|
||||||
*/
|
*/
|
||||||
func (b *Builder) When(boolean bool, cb ...func(builder *Builder)) *Builder {
|
func (b *Builder) When(boolean bool, cb ...func(builder *Builder)) *Builder {
|
||||||
if boolean {
|
if boolean {
|
||||||
@ -2323,7 +2320,8 @@ func (b *Builder) Value(dest interface{}, column string) (sql.Result, error) {
|
|||||||
return b.First(dest, column)
|
return b.First(dest, column)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*Reset
|
/*
|
||||||
|
Reset
|
||||||
reset bindings and components
|
reset bindings and components
|
||||||
*/
|
*/
|
||||||
func (b *Builder) Reset(targets ...string) *Builder {
|
func (b *Builder) Reset(targets ...string) *Builder {
|
||||||
@ -2382,7 +2380,8 @@ func (b *Builder) After(callback func(builder *Builder, t string, res sql.Result
|
|||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
/*ApplyBeforeQueryCallBacks
|
/*
|
||||||
|
ApplyBeforeQueryCallBacks
|
||||||
Invoke the "before query" modification callbacks.
|
Invoke the "before query" modification callbacks.
|
||||||
*/
|
*/
|
||||||
func (b *Builder) ApplyBeforeQueryCallBacks(t string, items ...map[string]any) {
|
func (b *Builder) ApplyBeforeQueryCallBacks(t string, items ...map[string]any) {
|
||||||
|
2
db.go
2
db.go
@ -31,8 +31,6 @@ func Open(config map[string]DBConfig) *DB {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
db.Connection("default")
|
|
||||||
|
|
||||||
Engine = &db
|
Engine = &db
|
||||||
|
|
||||||
return Engine
|
return Engine
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
package db
|
package db
|
||||||
|
|
||||||
type Sqlite3Grammar struct {
|
type Sqlite3Grammar = MysqlGrammar
|
||||||
*MysqlGrammar
|
|
||||||
}
|
|
||||||
|
36
sqlite3_test.go
Normal file
36
sqlite3_test.go
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
package db
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
var conn *Connection
|
||||||
|
|
||||||
|
func TestMain(m *testing.M) {
|
||||||
|
database := Open(map[string]DBConfig{
|
||||||
|
"sqlite3": {
|
||||||
|
Driver: "sqlite3",
|
||||||
|
File: ":memory:",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
conn = database.Connection("sqlite3")
|
||||||
|
|
||||||
|
// 执行测试
|
||||||
|
code := m.Run()
|
||||||
|
|
||||||
|
// 退出测试
|
||||||
|
os.Exit(code)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSqliteQuery(t *testing.T) {
|
||||||
|
dest := []map[string]any{}
|
||||||
|
|
||||||
|
t.Log(conn.Select("select 1 as a, 2 as b", nil, &dest))
|
||||||
|
t.Log("result: ", dest)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSqliteBuilder(t *testing.T) {
|
||||||
|
t.Log(conn.Query().FromSub("select 1 as a, 2 as b", "tb").ToSql())
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user