fts5
This commit is contained in:
36
fts5/query.go
Normal file
36
fts5/query.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package fts5
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type preparer interface {
|
||||
Prepare(string) (*sql.Stmt, error)
|
||||
}
|
||||
|
||||
func prepareInsertStmt(
|
||||
db preparer,
|
||||
columnNames []string,
|
||||
) (*sql.Stmt, error) {
|
||||
insertQuery := fmt.Sprintf(`INSERT INTO search(rowid,%s) VALUES (?%s)`,
|
||||
strings.Join(columnNames, ","),
|
||||
strings.Repeat(",?", len(columnNames)))
|
||||
return db.Prepare(insertQuery)
|
||||
}
|
||||
|
||||
func execInsertStmt(
|
||||
stmt *sql.Stmt,
|
||||
colNames []string,
|
||||
id int64,
|
||||
data map[string]string,
|
||||
) error {
|
||||
values := make([]any, len(colNames)+1)
|
||||
values[0] = id
|
||||
for i, col := range colNames {
|
||||
values[i+1] = data[col]
|
||||
}
|
||||
_, err := stmt.Exec(values...)
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user