Documentation
¶
Overview ¶
Package wasipg is an embedded PostgreSQL for Go: a WASI build of PostgreSQL (Electric's postgres-pglite fork, compiled with working setjmp/longjmp error recovery) executed in-process by wazero and exposed through the standard wire protocol, so any pgx/lib/pq client works. No cgo, no Docker, no native binaries.
eng, err := wasipg.Start(ctx, wasipg.Options{})
if err != nil { ... }
defer eng.Close()
conn, err := pgx.ConnectConfig(ctx, eng.PGXConfig())
An Engine is single-connection and disposable: erroring queries are recovered by PostgreSQL itself, but a wasm-level trap marks the engine dead and it must be replaced (see Pool). Data is ephemeral by default; pass Options.Dir to keep state across runs.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultBundle = Bundle{}
DefaultBundle is the pinned released bundle. Until the first release is published it is empty; Start returns a descriptive error telling the caller to either upgrade or point Options.Bundle at local artifacts.
Functions ¶
This section is empty.
Types ¶
type Bundle ¶
type Bundle struct {
// BundlePath / PGDataPath point at local tarballs. When set they
// take precedence over the URLs and no network access happens.
BundlePath string
PGDataPath string
// BundleURL / PGDataURL are fetched into CacheDir (or the user
// cache dir) on first use.
BundleURL string
BundleSHA256 string
PGDataURL string
PGDataSHA256 string
}
Bundle identifies the two artifacts an engine boots from: the module bundle (pglite.wasi + its runtime filesystem) and the pristine initdb'd data directory. Each comes either from a local path (air-gapped / vendored use) or from a URL fetched once into the user cache directory and verified against a pinned sha256. The library refuses hash-mismatched bundles.
func LocalBundle ¶
LocalBundle points at artifacts produced by ./build/build.sh in a checkout of this repository.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine is one booted, single-connection PostgreSQL instance.
func Start ¶
Start boots a PostgreSQL engine: resolves (and if necessary fetches and verifies) the bundle, extracts it into the working directory, seeds the pristine data directory, and runs the module under wazero until it is ready to accept a wire connection.
func (*Engine) Close ¶
Close shuts the engine down and releases the runtime. Ephemeral working directories are removed.
func (*Engine) ConnString ¶
ConnString returns a connection string for the engine. The host is symbolic — the dial is intercepted in-process.
func (*Engine) Dial ¶
Dial returns the engine's in-process wire connection. The engine is strictly single-connection: a second dial fails until the engine is replaced. Signature matches pgconn's DialFunc.
func (*Engine) Dir ¶
Dir returns the engine's working directory (containing the data dir and pg.log). For ephemeral engines it disappears on Close.
func (*Engine) PGXConfig ¶
func (e *Engine) PGXConfig() *pgx.ConnConfig
PGXConfig returns a pgx connection config wired to the in-process engine.
type Options ¶
type Options struct {
// Dir is the working directory holding the extracted bundle and
// the data directory. "" means an ephemeral temp dir removed on
// Close. A Dir whose data directory already exists is resumed
// (no initdb, no pgdata extraction). A Dir belongs to at most one
// live Engine: booting two engines on the same Dir is undefined
// behavior (they would share PGDATA and the wire-pump files).
Dir string
// Bundle selects the artifacts to boot. Zero value means
// DefaultBundle.
Bundle Bundle
// CacheDir overrides the cache location for fetched bundles and
// wazero's compilation cache. "" means os.UserCacheDir()/wasipg.
CacheDir string
}
Options configures Start.
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool hands out single-connection engines and replaces used or dead ones by booting fresh instances from the pristine bundle. Engines that lived through a trap are never reused — dispose-and-reboot is the recovery contract for crash-class faults.
func NewPool ¶
NewPool returns a pool that boots engines with opts. Options.Dir must be empty: pooled engines are always ephemeral.
func (*Pool) Close ¶
func (p *Pool) Close()
Close disposes all idle engines. Engines currently handed out are the caller's to close.
func (*Pool) Get ¶
Get returns a fresh engine, either prewarmed or booted on demand. The caller owns it: hand it back with Put (or Close it directly).
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
mkdata
command
Command mkdata produces the pristine initdb'd PGDATA tarball that ships alongside the bundle: it boots the bundle once in a fresh workdir (which runs in-guest initdb), shuts the engine down cleanly, and packs the resulting data directory.
|
Command mkdata produces the pristine initdb'd PGDATA tarball that ships alongside the bundle: it boots the bundle once in a fresh workdir (which runs in-guest initdb), shuts the engine down cleanly, and packs the resulting data directory. |
|
smoke
command
Command smoke is the stage-1 exit-criteria probe: boot the from-source bundle (build/out/) under wazero, connect with pgx over the socket-file wire pump, and run version/DDL/DML/catalog queries on a clean data dir.
|
Command smoke is the stage-1 exit-criteria probe: boot the from-source bundle (build/out/) under wazero, connect with pgx over the socket-file wire pump, and run version/DDL/DML/catalog queries on a clean data dir. |
|
internal
|
|
|
engine
Package engine boots the wasipg WASI PostgreSQL bundle under wazero and exposes its socket-file wire pump.
|
Package engine boots the wasipg WASI PostgreSQL bundle under wazero and exposes its socket-file wire pump. |