Skip to content

v0.1.0

Latest

Choose a tag to compare

@kenshaw kenshaw released this 28 Nov 23:48
· 1 commit to main since this release

The first release of sqlite3wasm, a database/sql driver for SQLite that needs no cgo. It is made for Go programs that run in a web browser.

SQLite 3.54.1 is built for WebAssembly with zig and embedded in the package. In a program built with GOOS=js GOARCH=wasm, the engine of the browser runs SQLite next to the Go program, so no WebAssembly runs inside other WebAssembly. On every other target, wazero runs the same module. That build is for go test ./... and is not meant for production. The package also builds with TinyGo.

  • Every database is in memory. :memory: belongs to one connection. Any other name is a memdb database that every connection of one sql.DB shares.
  • Preload(name, data) gives a named database its starting content, so that a page can load a database file before a client such as usql opens it.
  • Conn.Deserialize and Conn.Serialize load and save the bytes of a database. Conn.AutoCommit says whether a connection is in a transaction.
  • An error from SQLite is a *sqlite3wasm.Error with the primary and the extended result code, and has ErrVerbose for usql.
  • A context with a deadline stops a long statement, in a browser too.
  • The data source name is [sqlite3wasm:]name[?pragma=...]. dburl v0.59.0 names this driver for the scheme sqlite3wasm when it is built with -tags sqlite3wasm.

The tests run on wazero and in headless Chrome with chromedp. The only dependency of the package is wazero, and a browser build does not link it.