sqlitefile

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2021 License: BSD-3-Clause, ISC Imports: 7 Imported by: 0

Documentation

Overview

Package sqlitefile provides functions for executing SQLite statements from a file.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Exec

func Exec(conn *sqlite.Conn, fsys fs.FS, filename string, opts *ExecOptions) error

Exec executes the single statement in the given SQL file. Exec is implemented using Conn.Prepare, so subsequent calls to Exec with the same statement will reuse the cached statement object.

func ExecScript

func ExecScript(conn *sqlite.Conn, fsys fs.FS, filename string, opts *ExecOptions) (err error)

ExecScript executes a script of SQL statements from a file.

The script is wrapped in a SAVEPOINT transaction, which is rolled back on any error.

func ExecTransient

func ExecTransient(conn *sqlite.Conn, fsys fs.FS, filename string, opts *ExecOptions) error

ExecTransient executes the single statement in the given SQL file without caching the underlying query.

func PrepareTransient

func PrepareTransient(conn *sqlite.Conn, fsys fs.FS, filename string) (*sqlite.Stmt, error)

PrepareTransient prepares an SQL statement from a file that is not cached by the Conn. Subsequent calls with the same query will create new Stmts. The caller is responsible for calling Finalize on the returned Stmt when the Stmt is no longer needed.

Types

type ExecOptions

type ExecOptions struct {
	// Args is the set of positional arguments to bind to the statement. The first
	// element in the slice is ?1. See https://sqlite.org/lang_expr.html for more
	// details.
	Args []interface{}
	// Named is the set of named arguments to bind to the statement. Keys must
	// start with ':', '@', or '$'. See https://sqlite.org/lang_expr.html for more
	// details.
	Named map[string]interface{}
	// ResultFunc is called for each result row. If ResultFunc returns an error
	// then iteration ceases and Exec returns the error value.
	ResultFunc func(stmt *sqlite.Stmt) error
}

ExecOptions is the set of optional arguments for the functions in this package.

Jump to

Keyboard shortcuts

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