statement

package
v0.35.2 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2026 License: MIT Imports: 7 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
package main

import (
	"fmt"
	"log"

	"github.com/ncruces/go-sqlite3"
	"github.com/ncruces/go-sqlite3/ext/statement"
)

func main() {
	sqlite3.AutoExtension(statement.Register)

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

	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) error

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