Files
db/dialect/duckdb/duckdb.go
T

46 lines
1.1 KiB
Go

package duckdb
import (
_ "github.com/marcboeker/go-duckdb"
"git.fsdpf.net/go/db"
"git.fsdpf.net/go/db/exp"
)
func DialectOptions() *db.SQLDialectOptions {
do := db.DefaultDialectOptions()
// DuckDB uses PostgreSQL-style placeholders ($1, $2, etc.)
do.PlaceHolderFragment = []byte("$")
do.IncludePlaceholderNum = true
// DuckDB supports most PostgreSQL features
do.SupportsReturn = true
do.SupportsOrderByOnUpdate = false
do.SupportsLimitOnUpdate = false
do.SupportsOrderByOnDelete = false
do.SupportsLimitOnDelete = false
do.SupportsConflictUpdateWhere = true
do.SupportsInsertIgnoreSyntax = false
do.SupportsConflictTarget = true
do.SupportsWithCTE = true
do.SupportsWithCTERecursive = true
do.SupportsDistinctOn = true
do.SupportsWindowFunction = true
// Use double quotes for identifiers (PostgreSQL-style)
do.QuoteRune = '"'
// regexp_matches(col, pattern) 做部分匹配,等价于 MySQL REGEXP
do.BooleanFunctionLookup = map[exp.BooleanOperation][]byte{
exp.RegexpLikeOp: []byte("REGEXP_MATCHES"),
exp.RegexpILikeOp: []byte("REGEXP_MATCHES"),
}
return do
}
func init() {
db.RegisterDialect("duckdb", DialectOptions())
}