node

package
v0.4.1 Latest Latest
Warning

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

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

Documentation

Overview

Package node adapts a native SQLite connection to the portable durable SQLite facade. It is the Go counterpart of Pi's node:sqlite adapter and the only durable storage 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

func OpenNodeSqliteStorage

func OpenNodeSqliteStorage(path string, options NodeSqliteStorageOptions) (*durablesqlite.SqliteStorage, error)

OpenNodeSqliteStorage opens or creates file-backed durable storage.

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 Connection

type Connection interface {
	Exec(sql string) error
	Prepare(sql string) (*StatementSync, error)
	Close() error
}

Connection is the native connection surface NodeSqliteDatabase drives.

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) 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 Connection) *NodeSqliteDatabase

NewNodeSqliteDatabase adapts database; the adapter owns it from now on.

func OpenNodeSqliteDatabase

func OpenNodeSqliteDatabase(path string, options NodeSqliteStorageOptions) (*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 ...durablesqlite.SqliteValue,
) (rows []durablesqlite.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) Exec

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

func (*NodeSqliteDatabase) Get

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

func (*NodeSqliteDatabase) Run

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

func (*NodeSqliteDatabase) Transaction

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

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

type NodeSqliteStorageOptions

type NodeSqliteStorageOptions 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
}

NodeSqliteStorageOptions configures a file-backed durable storage 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) 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