
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
sqlite-wasm-wasi
Advanced tools
Use SQLite from WASM WASI. See parent.
API is similar to better-sqlite3.
Full sources. Also lock.host-wasm-js.
import { open } from 'sqlite-wasm-wasi'
const db = open('/app/example.js.db')
db.exec('drop table if exists example')
db.exec('create table example (id integer, name text, note text, ratio real, big_int integer)')
let insert = db.prepare('insert into example (id, name, note, ratio, big_int) values (?, ?, ?, ?, ?)')
let info = insert.run([1, 'hello from js', null, 3.25, 9007199254740993n])
console.log(info.changes, '== 1')
console.log(info.lastInsertRowid, '== 1')
info = insert.run([2, 'hello from js', null, 3.25, 9007199254740993n])
console.log(info.changes, '== 1')
console.log(info.lastInsertRowid, '== 2')
let select = db.prepare('select id, name, note, ratio, big_int from example where id = ?')
let row = select.one([1])
console.log(row) // >> { id: 1n, name: 'hello from js', note: null, ratio: 3.25, big_int: 9007199254740993n }
select = db.prepare('select * from example where 1 = ? order by id')
let rows = select.all([1])
console.log(rows) // >> [ ..., ... ]
// transactions
db.exec('drop table if exists txn')
db.exec('create table txn (id integer)')
insert = db.prepare('insert into txn (id) values (?)')
let insertMany = db.transaction((nums) => {
for (const num of nums) { insert.run([num]) }
})
const nums = [1, 4, 5, 6]
insertMany(nums)
select = db.prepare('select * from txn order by id')
rows = select.all()
console.log(rows) // { id: 1n }, { id: 4n }, { id: 5n }, { id: 6n }
db.close()
You need component.wasm.
If you want to build component.wasm yourself, see: parent.
Otherwise get component.wasm from node_modules/sqlite-wasm-wasi/dist/ after npm install sqlite-wasm-wasi.
You need also dist/wit/sqlite.wit. Look at justfile and all will become clear.
let stmt = db.prepare('sql') returns a "prepared statement".
Prepared statements can be run 1 or 100 or more times.
If your app is eg an HTTP server you need to be calling stmt.release() when done with it.
Rust has the Drop trait and does not need release.
open() detaults to "unix-dotfile" VFS.
Unix-dotfile VFS is exactly like default "unix" except it avoids POSIX flock() system calls.
Lock.host will be forking and trying to upstream wasmtime flock support.
MIT
FAQs
Use SQLite from WASM WASI
We found that sqlite-wasm-wasi demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.