In this issue, we'd like to run kvdb/sqlbase (the kvdb-over-SQL walletdb backend) in a GOOS=js GOARCH=wasm build, so that walletdb-backed code can persist into a browser SQLite database, e.g. an OPFS-backed SQLite compiled to WASM and exposed through database/sql.
The sqlbase translation layer itself is already driver-agnostic: it speaks plain database/sql and keys off Config.DriverName / Config.Dsn, so in principle it runs on any registered driver, including a browser SQLite one. The blocker is purely how the package is gated and wired, not the logic.
- The real sqlbase files (
db.go, readwrite_bucket.go, readwrite_cursor.go, readwrite_tx.go, schema.go) are tagged kvdb_postgres || (kvdb_sqlite && !<exotic arches>). Without one of those tags you get no_sql.go, whose Init is a no-op stub, so a plain js/wasm build never compiles the actual bucket/cursor implementation.
- The obvious way to flip them on,
-tags kvdb_sqlite, also pulls in kvdb/sqlite/db.go, which blank-imports modernc.org/sqlite to register the driver. modernc has no js/wasm target (the arch carve-outs already baked into that build tag are modernc's platform matrix), so that path can't compile for the browser at all.
- There's also a native coupling inside the shared layer:
sqlbase/db_conn_set.go blank-imports github.com/jackc/pgx/v4/stdlib, which isn't needed when the caller supplies its own driver.
What would help is a way to compile the sqlbase translation layer under js/wasm against a caller-registered driver, decoupled from the modernc registration. A few shapes that would work:
- Separate the concrete driver registration (the
modernc.org/sqlite blank import in kvdb/sqlite) from the sqlbase translation layer, so the latter builds without forcing a native driver into the binary.
- Add a build path (allow the sqlbase files to compile under
js && wasm, or a dedicated tag) where NewSqlBackend works purely off Config.DriverName with no driver force-registered.
- Move the
pgx/v4/stdlib blank import out of the shared db_conn_set.go and behind the postgres-specific tag.
The concrete win: a wasm consumer registers a browser SQLite driver via sql.Register(...), hands its name and DSN to sqlbase.Config, and gets back a working walletdb.DB (buckets, cursors, txns) with no native-driver baggage in the binary.
In this issue, we'd like to run
kvdb/sqlbase(the kvdb-over-SQLwalletdbbackend) in aGOOS=js GOARCH=wasmbuild, so thatwalletdb-backed code can persist into a browser SQLite database, e.g. an OPFS-backed SQLite compiled to WASM and exposed throughdatabase/sql.The sqlbase translation layer itself is already driver-agnostic: it speaks plain
database/sqland keys offConfig.DriverName/Config.Dsn, so in principle it runs on any registered driver, including a browser SQLite one. The blocker is purely how the package is gated and wired, not the logic.db.go,readwrite_bucket.go,readwrite_cursor.go,readwrite_tx.go,schema.go) are taggedkvdb_postgres || (kvdb_sqlite && !<exotic arches>). Without one of those tags you getno_sql.go, whoseInitis a no-op stub, so a plainjs/wasmbuild never compiles the actual bucket/cursor implementation.-tags kvdb_sqlite, also pulls inkvdb/sqlite/db.go, which blank-importsmodernc.org/sqliteto register the driver. modernc has nojs/wasmtarget (the arch carve-outs already baked into that build tag are modernc's platform matrix), so that path can't compile for the browser at all.sqlbase/db_conn_set.goblank-importsgithub.com/jackc/pgx/v4/stdlib, which isn't needed when the caller supplies its own driver.What would help is a way to compile the sqlbase translation layer under
js/wasmagainst a caller-registered driver, decoupled from the modernc registration. A few shapes that would work:modernc.org/sqliteblank import inkvdb/sqlite) from the sqlbase translation layer, so the latter builds without forcing a native driver into the binary.js && wasm, or a dedicated tag) whereNewSqlBackendworks purely offConfig.DriverNamewith no driver force-registered.pgx/v4/stdlibblank import out of the shareddb_conn_set.goand behind the postgres-specific tag.The concrete win: a wasm consumer registers a browser SQLite driver via
sql.Register(...), hands its name and DSN tosqlbase.Config, and gets back a workingwalletdb.DB(buckets, cursors, txns) with no native-driver baggage in the binary.