{"modulePath":"github.com/HyperparameterSI/golet","version":"v0.1.18","isLatest":true,"isStandardLibrary":false,"goos":"linux","goarch":"amd64","docs":"# package sqlite\n\nPackage 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.\n\nRegister the plugin only when the web frontend uses @golet-plugins/sqlite:\n\n\tgolet.Use(sqlite.Plugin)\n\nThe 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.\n\n## Variables\n\n```go\nvar ErrClosed = errors.New(\"sqlite: database is closed\")\n```\nErrClosed is returned when an operation uses a closed database.\n\n```go\nvar Plugin = New(Options{})\n```\nPlugin is the page plugin with default options. It loads the native library only when a page opens its first database.\n\n## Functions\n\n```go\nfunc Load() error\n```\nLoad loads the plugin's SQLite, a native module, once. Open calls it lazily, so binding the plugin and generating clients need no library.\n\n```go\nfunc New(opts Options) golet.Plugin\n```\nNew returns a plugin with options. Connections belong to their page, close when it navigates away or its window closes, and close on app quit.\n\n## Types\n\n```go\ntype DB struct {\n\t// contains filtered or unexported fields\n}\n```\nDB 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.\n\n```go\nfunc Open(ctx context.Context, path string, opts OpenOptions) (*DB, error)\n```\nOpen 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.\n\n```go\nfunc (d *DB) Close() error\n```\nClose cancels in-flight operations, waits for their statements to be finalized, and closes the connection. Repeated calls are harmless.\n\n```go\nfunc (d *DB) Execute(ctx context.Context, sql string, args ...any) (result Result, err error)\n```\nExecute 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.\n\n```go\nfunc (d *DB) Query(ctx context.Context, sql string, args ...any) (rows Rows, err error)\n```\nQuery runs exactly one statement and copies its rows. It also supports statements with RETURNING. For large results, select a bounded page.\n\n```go\nfunc (d *DB) Transaction(ctx context.Context, statements []Statement) (results []Result, err error)\n```\nTransaction 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.\n\n```go\ntype Error struct {\n\tCode         int\n\tExtendedCode int\n\tMessage      string\n}\n```\nError is an SQLite error. Code is the primary result code; ExtendedCode distinguishes such errors as unique, foreign-key and not-null constraints.\n\n```go\nfunc (e *Error) Error() string\n```\n\n```go\ntype OpenOptions struct {\n\t// ReadOnly opens an existing database without allowing writes.\n\tReadOnly bool\n\t// BusyTimeout is how long an operation waits for another connection's\n\t// lock: five seconds when zero, no wait when negative. Cancellation\n\t// stops the wait early.\n\tBusyTimeout time.Duration\n}\n```\nOpenOptions configure a connection. Foreign keys are enabled by default.\n\n```go\ntype Options struct {\n\t// Directory holds the page's database files, golet.PathUserData when\n\t// empty. Pages may open file names here, or \":memory:\", not paths.\n\tDirectory string\n\t// BusyTimeout follows OpenOptions.BusyTimeout.\n\tBusyTimeout time.Duration\n}\n```\nOptions configure the page plugin. Go's Open accepts its own path and OpenOptions and does not use these options.\n\n```go\ntype Result struct {\n\tChanges      int64 `json:\"changes\"`\n\tLastInsertID int64 `json:\"lastInsertId\"`\n}\n```\nResult describes a statement. Changes counts directly affected rows; LastInsertID is SQLite's last inserted rowid on this connection.\n\n```go\ntype Rows struct {\n\tColumns []string `json:\"columns\"`\n\tValues  [][]any  `json:\"rows\"`\n}\n```\nRows holds columns and their values in order, preserving duplicate column names. Values are nil, int64, float64, string or \\[]byte. BLOBs are copied before the next step, so they remain valid after the statement closes.\n\n```go\ntype Statement struct {\n\tSQL  string\n\tArgs []any\n}\n```\nStatement is one parameterized statement in a transaction.\n\n","path":"github.com/HyperparameterSI/golet/backend/plugins/sqlite","name":"sqlite","synopsis":"Package sqlite is Golet's SQLite plugin.","isRedistributable":true}
