array

package
v0.35.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 16, 2026 License: MIT Imports: 4 Imported by: 1

Documentation

Overview

Package array provides the array table-valued SQL function.

https://sqlite.org/carray.html

Example
package main

import (
	"fmt"
	"log"

	"github.com/ncruces/go-sqlite3"
	"github.com/ncruces/go-sqlite3/ext/array"
	"github.com/ncruces/go-sqlite3/ext/rtree"
)

func main() {
	sqlite3.AutoExtension(array.Register)
	sqlite3.AutoExtension(rtree.Register)

	db, err := sqlite3.Open(":memory:")
	if err != nil {
		log.Fatal(err)
	}
	defer db.Close()

	stmt, _, err := db.Prepare(`
		SELECT name
		FROM pragma_function_list
		WHERE name like 'geopoly%' AND narg IN array(?)`)
	if err != nil {
		log.Fatal(err)
	}
	defer stmt.Close()

	err = stmt.BindPointer(1, [...]int{2, 3, 4})
	if err != nil {
		log.Fatal(err)
	}

	for stmt.Step() {
		fmt.Printf("%s\n", stmt.ColumnText(0))
	}
	if err := stmt.Err(); err != nil {
		log.Fatal(err)
	}
}
Output:
geopoly_regular
geopoly_overlap
geopoly_contains_point
geopoly_within
Example (Driver)
package main

import (
	"errors"
	"fmt"
	"log"

	"github.com/ncruces/go-sqlite3"
	"github.com/ncruces/go-sqlite3/driver"
	"github.com/ncruces/go-sqlite3/ext/array"
	"github.com/ncruces/go-sqlite3/ext/rtree"
)

func main() {
	db, err := driver.Open("file:/test.db?vfs=memdb", func(c *sqlite3.Conn) error {
		return errors.Join(
			array.Register(c),
			rtree.Register(c))
	})
	if err != nil {
		log.Fatal(err)
	}
	defer db.Close()

	rows, err := db.Query(`
		SELECT name
		FROM pragma_function_list
		WHERE name like 'geopoly%' AND narg IN array(?)`,
		sqlite3.Pointer([]int{2, 3, 4}))
	if err != nil {
		log.Fatal(err)
	}
	defer rows.Close()

	for rows.Next() {
		var name string
		err := rows.Scan(&name)
		if err != nil {
			log.Fatal(err)
		}
		fmt.Printf("%s\n", name)
	}
	if err := rows.Err(); err != nil {
		log.Fatal(err)
	}
}
Output:
geopoly_regular
geopoly_overlap
geopoly_contains_point
geopoly_within

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(db *sqlite3.Conn) error

Register registers the array single-argument, table-valued SQL function. The argument must be bound to a Go slice or array of ints, floats, bools, strings or byte slices, using sqlite3.BindPointer or sqlite3.Pointer.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL