Virtual table API.

This commit is contained in:
Nuno Cruces
2023-11-22 13:11:23 +00:00
parent 97d4248176
commit 83c15f2ddc
8 changed files with 53 additions and 74 deletions

View File

@@ -8,26 +8,21 @@ import (
"github.com/ncruces/go-sqlite3"
)
// Register registers the single-argument array table-valued SQL function.
// Register registers the array single-argument, table-valued SQL function.
// The argument must be an [sqlite3.Pointer] to a Go slice or array
// of ints, floats, bools, strings or blobs.
//
// https://sqlite.org/carray.html
func Register(db *sqlite3.Conn) {
sqlite3.CreateModule(db, "array", array{})
sqlite3.CreateModule[array](db, "array", nil,
func(db *sqlite3.Conn, arg ...string) (array, error) {
err := db.DeclareVtab(`CREATE TABLE x(value, array HIDDEN)`)
return array{}, err
})
}
type array struct{}
func (array) Connect(c *sqlite3.Conn, arg ...string) (_ array, err error) {
err = c.DeclareVtab(`CREATE TABLE x(value, array HIDDEN)`)
return
}
func (array) Disconnect() error {
return nil
}
func (array) BestIndex(idx *sqlite3.IndexInfo) error {
for i, cst := range idx.Constraint {
if cst.Column == 1 && cst.Op == sqlite3.INDEX_CONSTRAINT_EQ && cst.Usable {