Documentation
¶
Overview ¶
Package sqlite is Golet's SQLite plugin. SQLite runs in a native module written in Zig (internal/sqlitecore), published prebuilt for each platform: no cgo, Zig, Bun or compiler is needed to build or run an app.
Register the plugin only when the web frontend uses @golet-plugins/sqlite:
golet.Use(sqlite.Plugin)
The frontend uses open from @golet-plugins/sqlite. It opens named databases in the app's user-data directory, executes parameterized SQL, queries rows and runs batches in transactions. Go and native UI apps call Open directly and close their own connections; no golet.Use is needed.
Index ¶
- Variables
- func Load() error
- func New(opts Options) golet.Plugin
- type DB
- func (d *DB) Close() error
- func (d *DB) Execute(ctx context.Context, sql string, args ...any) (result Result, err error)
- func (d *DB) Query(ctx context.Context, sql string, args ...any) (rows Rows, err error)
- func (d *DB) Transaction(ctx context.Context, statements []Statement) (results []Result, err error)
- type Error
- type OpenOptions
- type Options
- type Result
- type Rows
- type Statement
Constants ¶
This section is empty.
Variables ¶
var ErrClosed = errors.New("sqlite: database is closed")
ErrClosed is returned when an operation uses a closed database.
var Plugin = New(Options{})
Plugin is the page plugin with default options. It loads the native library only when a page opens its first database.
Functions ¶
Types ¶
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB is a connection to the plugin's SQLite library. It is safe from any goroutine; operations serialize on the connection and may be canceled while waiting for it. Use Transaction for atomic groups of statements.
func Open ¶
Open opens path (or ":memory:") with SQLite, which the plugin compiles with Zig into a native module, without cgo. It creates a missing file unless ReadOnly. The parent directory must already exist. Close the returned connection when done.
func (*DB) Close ¶
Close cancels in-flight operations, waits for their statements to be finalized, and closes the connection. Repeated calls are harmless.
func (*DB) Execute ¶
Execute runs exactly one statement with positional parameters. Supported values are nil, bool, integers, finite floats, strings, []byte and json.Number. SQL text may not contain NUL. Transaction control, ATTACH and VACUUM INTO are rejected; use Transaction for groups of statements.
func (*DB) Query ¶
Query runs exactly one statement and copies its rows. It also supports statements with RETURNING. For large results, select a bounded page.
func (*DB) Transaction ¶
Transaction runs statements under BEGIN IMMEDIATE, without interleaving other operations on this connection. Any error, including cancellation, rolls back the batch. Results are returned only after COMMIT succeeds.
type Error ¶
Error is an SQLite error. Code is the primary result code; ExtendedCode distinguishes such errors as unique, foreign-key and not-null constraints.
type OpenOptions ¶
type OpenOptions struct {
// ReadOnly opens an existing database without allowing writes.
ReadOnly bool
// BusyTimeout is how long an operation waits for another connection's
// lock: five seconds when zero, no wait when negative. Cancellation
// stops the wait early.
BusyTimeout time.Duration
}
OpenOptions configure a connection. Foreign keys are enabled by default.
type Options ¶
type Options struct {
// Directory holds the page's database files, golet.PathUserData when
// empty. Pages may open file names here, or ":memory:", not paths.
Directory string
// BusyTimeout follows OpenOptions.BusyTimeout.
BusyTimeout time.Duration
}
Options configure the page plugin. Go's Open accepts its own path and OpenOptions and does not use these options.
type Result ¶
Result describes a statement. Changes counts directly affected rows; LastInsertID is SQLite's last inserted rowid on this connection.
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
sqlitecore
Package sqlitecore is the plugin's SQLite: a native module implemented in Zig, which compiles SQLite's amalgamation into the module's library for every platform.
|
Package sqlitecore is the plugin's SQLite: a native module implemented in Zig, which compiles SQLite's amalgamation into the module's library for every platform. |