node

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package node adapts a native SQLite connection to the portable Chord SQLite facade. It is the Go counterpart of Pi's node:sqlite driver and the only Chord SQLite package that links a SQLite driver (modernc.org/sqlite, pure Go, CGO-free).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AggregateError

type AggregateError struct {
	Errors  []error
	Message string
}

AggregateError reports a transaction callback failure together with the rollback failure that followed it. It deliberately does not unwrap: the callback error no longer implies that the transaction rolled back.

func (*AggregateError) Error

func (aggregate *AggregateError) Error() string

type DatabaseSync

type DatabaseSync struct {
	// contains filtered or unexported fields
}

DatabaseSync is one native SQLite connection whose operations run on the caller's goroutine, the Go counterpart of node:sqlite's DatabaseSync.

func NewDatabaseSync

func NewDatabaseSync(path string, options DatabaseSyncOptions) (*DatabaseSync, error)

NewDatabaseSync opens path (or ":memory:") as one dedicated connection.

func (*DatabaseSync) Close

func (database *DatabaseSync) Close() error

Close closes the connection; later operations fail.

func (*DatabaseSync) Exec

func (database *DatabaseSync) Exec(sqlText string) error

Exec runs SQL text without bindings; it may contain several statements.

func (*DatabaseSync) ObservePrepare

func (database *DatabaseSync) ObservePrepare(observe func(sqlText string))

ObservePrepare calls observe with the SQL text of every statement Prepare compiles from now on. It stands in for a subclass overriding DatabaseSync.prepare, as Pi's storage tests count compilations. pig additive (D104): Go has no subclassing of the connection, so an observer takes the override's place.

func (*DatabaseSync) Prepare

func (database *DatabaseSync) Prepare(sqlText string) (*StatementSync, error)

Prepare compiles one statement.

type DatabaseSyncOptions

type DatabaseSyncOptions struct {
	// TimeoutMs is how long SQLite waits for a competing file lock; zero does not wait.
	TimeoutMs int
	// ReadOnly opens an existing database without write access.
	ReadOnly bool
}

DatabaseSyncOptions configures one native SQLite connection.

type NodeSqliteDatabase

type NodeSqliteDatabase struct {
	// contains filtered or unexported fields
}

NodeSqliteDatabase is the SqliteDatabase adapter backed by a native connection.

func NewNodeSqliteDatabase

func NewNodeSqliteDatabase(database *DatabaseSync) *NodeSqliteDatabase

NewNodeSqliteDatabase adapts database; the adapter owns it from now on. It is Pi's `new NodeSqliteDatabase(database: DatabaseSync)`.

func OpenNodeSqliteDatabase

func OpenNodeSqliteDatabase(path string, options NodeSqliteDatabaseOptions) (*NodeSqliteDatabase, error)

OpenNodeSqliteDatabase opens and configures a native SQLite database facade, creating the parent directory.

func (*NodeSqliteDatabase) All

func (executor *NodeSqliteDatabase) All(
	sqlText string, params ...chordsqlite.SqliteValue,
) (rows []chordsqlite.SqliteRow, err error)

func (*NodeSqliteDatabase) Close

func (adapter *NodeSqliteDatabase) Close() error

Close truncates the WAL and closes the connection. Repeated calls do nothing.

func (*NodeSqliteDatabase) EachText

func (executor *NodeSqliteDatabase) EachText(sqlText string, params []chordsqlite.SqliteValue, fn func(text []byte) error) error

EachText runs a query whose first column is text and passes each value to fn without building result rows.

func (*NodeSqliteDatabase) Exec

func (executor *NodeSqliteDatabase) Exec(sqlText string) error

func (*NodeSqliteDatabase) Get

func (executor *NodeSqliteDatabase) Get(
	sqlText string, params ...chordsqlite.SqliteValue,
) (row chordsqlite.SqliteRow, err error)

func (*NodeSqliteDatabase) Run

func (executor *NodeSqliteDatabase) Run(sqlText string, params ...chordsqlite.SqliteValue) error

func (*NodeSqliteDatabase) Transaction

func (adapter *NodeSqliteDatabase) Transaction(
	callback func(transaction chordsqlite.SqliteExecutor) error,
) (err error)

Transaction runs callback inside BEGIN IMMEDIATE ... COMMIT and rolls back when it fails or panics.

type NodeSqliteDatabaseOptions

type NodeSqliteDatabaseOptions struct {
	// WalAutoCheckpointPages is the SQLite WAL auto-checkpoint threshold. SQLite and this adapter default to 1,000
	// pages; 0 disables it.
	WalAutoCheckpointPages *int
	// BusyTimeoutMs is how long SQLite waits for a competing file lock. SQLite defaults to 0; this adapter defaults to
	// 5,000 ms.
	BusyTimeoutMs *int
}

NodeSqliteDatabaseOptions configures a file-backed SQLite connection. A nil field selects its default.

type StatementSync

type StatementSync struct {
	// contains filtered or unexported fields
}

StatementSync is one prepared statement of a DatabaseSync.

func (*StatementSync) All

func (statement *StatementSync) All(params ...any) ([]map[string]any, error)

All returns every result row.

func (*StatementSync) EachText

func (statement *StatementSync) EachText(params []any, fn func(text []byte) error) (err error)

EachText passes the first column of every result row to fn as it is read; the bytes are valid until fn returns.

func (*StatementSync) Get

func (statement *StatementSync) Get(params ...any) (map[string]any, error)

Get returns the first result row, or nil when there is none.

func (*StatementSync) Run

func (statement *StatementSync) Run(params ...any) error

Run executes the statement with positional bindings.

Jump to

Keyboard shortcuts

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