Skip to main content

SqljsAdapter

SqljsAdapter is the Adapter implementation shipped by @sqb/sqljs, running SQLite compiled to WebAssembly via sql.js. It self-registers with AdapterRegistry as a side effect of importing @sqb/sqljs — see the SQLite (WebAssembly / sql.js) adapter guide for setup and configuration.

import '@sqb/sqljs';

Constructor

new SqljsAdapter()

Takes no arguments. You normally never construct this directly — importing @sqb/sqljs registers a shared instance with AdapterRegistry for you.

Properties

PropertyTypeDescription
driver'sqljs'The driver name, matched against ClientConfiguration.driver.
dialect'sqlite'The dialect name — shared with @sqb/sqlite, since both generate standard SQLite SQL. Select this adapter with driver: 'sqljs' if both are registered in the same process.
featuresAdapter.Features{ cursor: true }.

Methods

connect()

connect(config: ClientConfiguration): Promise<Adapter.Connection>

Requires config.database (throws if missing). Resolves it to an absolute file path, unless it matches :memory: (optionally suffixed, e.g. :memory:name), in which case a fresh in-memory sql.js database is created instead. For a file path, the file's contents are read up-front via fs.readFile and loaded into an in-memory sql.js Database. Non-memory databases are cached and reference-counted by resolved path, so multiple connections to the same file share one sql.js Database instance. Returns a SqljsConnection wrapping the opened (or reused) database.

Other exports

closeMemoryDatabase()

function closeMemoryDatabase(name?: string): Promise<void>

Force-closes and evicts a cached in-memory database (:memory: by default, or the given :memory:name variant) from the adapter's internal cache.

See also