statement

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: May 24, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package statement defines table-valued functions using SQL.

It can be used to create "parametrized views": pre-packaged queries that can be parametrized at query execution time.

https://github.com/0x09/sqlite-statement-vtab

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

statement.Register(db)

err = db.Exec(`
		CREATE VIRTUAL TABLE split_date USING statement((
			SELECT
				strftime('%Y', :date) AS year,
				strftime('%m', :date) AS month,
				strftime('%d', :date) AS day
		))`)
if err != nil {
	log.Fatal(err)
}

stmt, _, err := db.Prepare(`SELECT * FROM split_date('2022-02-22')`)
if err != nil {
	log.Fatal(err)
}
defer stmt.Close()

if stmt.Step() {
	fmt.Printf("Twosday was %d-%d-%d", stmt.ColumnInt(0), stmt.ColumnInt(1), stmt.ColumnInt(2))
}
if err := stmt.Reset(); err != nil {
	log.Fatal(err)
}
Output:

Twosday was 2022-2-22

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(db *sqlite3.Conn)

Register registers the statement virtual table.

Types

This section is empty.

Jump to

Keyboard shortcuts

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