feat: 新增 BooleanFunctionLookup 支持函数式操作符

- sqlgen: 新增 BooleanFunctionLookup,生成 FUNC(LHS, RHS) 格式,优先级高于 BooleanOperatorLookup
- dialect/duckdb: 使用 regexp_matches 替代 ~ 实现部分匹配,等价于 MySQL REGEXP
- sqlgen/expression_sql_generator_test: 补充 BooleanFunctionLookup 测试用例,修正 encode_error 前缀
- sqlgen/sql_dialect_options_test: 验证 BooleanFunctionLookup 默认为 nil
- dialect/duckdb_test: 新增 regexp_matches SQL 生成测试
This commit is contained in:
2026-05-21 13:34:04 +08:00
parent 1288c4919c
commit 37581f3a65
6 changed files with 74 additions and 3 deletions
+26
View File
@@ -107,6 +107,32 @@ func TestJoinSQL(t *testing.T) {
assert.Contains(t, sql, `ON ("users"."id" = "orders"."user_id")`)
}
func TestRegexpSQL(t *testing.T) {
db := dbv2.Dialect("duckdb")
// RegexpLike → regexp_matches(col, pattern)
ds := db.From("docs").Where(dbv2.C("content").RegexpLike("简介"))
sql, _, err := ds.ToSQL()
assert.NoError(t, err)
assert.Equal(t, `SELECT * FROM "docs" WHERE regexp_matches("content", '简介')`, sql)
// RegexpILike → 同样生成 regexp_matches
ds = db.From("docs").Where(dbv2.C("content").RegexpILike("简介"))
sql, _, err = ds.ToSQL()
assert.NoError(t, err)
assert.Equal(t, `SELECT * FROM "docs" WHERE regexp_matches("content", '简介')`, sql)
}
func TestRegexpPreparedSQL(t *testing.T) {
db := dbv2.Dialect("duckdb")
ds := db.From("docs").Prepared(true).Where(dbv2.C("content").RegexpLike("简介"))
sql, args, err := ds.ToSQL()
assert.NoError(t, err)
assert.Equal(t, `SELECT * FROM "docs" WHERE regexp_matches("content", $1)`, sql)
assert.Equal(t, []interface{}{"简介"}, args)
}
func TestWindowFunction(t *testing.T) {
db := dbv2.Dialect("duckdb")