go/fts5/query.go
2024-11-19 16:41:41 +01:00

37 lines
660 B
Go

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
}