sql-js
БесплатноБез исполняемых скриптовНе проверенsql.js is SQLite compiled to WebAssembly, so a browser page or a Node.js script can create, load, query and export a real SQLite database with no server and…
от TerminalSkills★ 221 звезда на GitHubОб этом скилле
sql.js — SQLite in WebAssembly for the browser and Node.js
Overview
sql.js runs the SQLite engine (3.54 in the 1.15 package) as WebAssembly. A database lives entirely in memory: you create an empty one or hand it the bytes of an existing .sqlite file, run SQL against it, and call db.export() to get the bytes back. Nothing is written to disk or to browser storage by the library. Saving, loading and sharing the bytes is the application's job.
That makes it a good fit for: reading a user-supplied SQLite file without uploading it, shipping a small read-only dataset with a web page, unit-testing SQL in Node without native compilation, and quick in-memory scratch databases. It is a poor fit for large databases (everything is held in RAM) or for server code where a native binding such as better-sqlite3 can work on files directly.
Instructions
Installation
npm install sql.js
ls node_modules/sql.js/dist
dist/ holds the builds. The ones to know:
| File | Use |
|---|---|
sql-wasm.js + sql-wasm.wasm |
Default build. Node loads the .wasm next to the script automatically; browsers need it served and located. |
sql-wasm-browser.js + .wasm |
Browser-only build (selected by the package's browser export). |
sql-wasm-inline.js |
One file with the WebAssembly embedded: no locateFile, larger JS. |
worker.sql-wasm.js, worker.sql-wasm-inline.js |
Web Worker builds driven by postMessage. |
*-debug.js |
Development builds with assertions. |
Start in Node.js
const initSqlJs = require("sql.js");
async function main() {
const SQL = await initSqlJs(); // loading is asynchronous
const db = new SQL.Database(); // empty in-memory database
db.run("CREATE TABLE orders (id INTEGER PRIMARY KEY, customer TEXT NOT NULL, total REAL, placed TEXT)");
db.run("INSERT INTO orders (customer, total, placed) VALUES (?, ?, ?)", ["Dana Ruiz", 129.5, "2026-10-01"]);
console.log(db.exec("SELECT count(*) AS n FROM orders"));
}
main();
require("sql.js") returns the initSqlJs function itself. Version 0.x loaded synchronously; any snippet that does new SQL.Database() right after require is outdated.
Start in the browser
Serve sql-wasm.js and sql-wasm.wasm from your own site (copy them out of node_modules/sql.js/dist), then point locateFile at the folder:
<script src="/vendor/sql-wasm.js"></script>
<script>
initSqlJs({ locateFile: (file) => `/vendor/${file}` }).then((SQL) => {
const db = new SQL.Database();
db.run("CREATE TABLE notes (id INTEGER PRIMARY KEY, body TEXT)");
console.log(db.exec("SELECT sqlite_version()")[0].values);
});
</script>
If you would rather not host the .wasm, use sql-wasm-inline.js and call initSqlJs() with no arguments. With a bundler (Vite, webpack) import the package and make sure the .wasm file is emitted as an asset and reachable by locateFile; a 404 on sql-wasm.wasm is the most common failure.
Run SQL
// run: execute statements, returns the Database, no results
db.run("INSERT INTO orders (customer, total, placed) VALUES (?, ?, ?)", ["Omar Haddad", 42, "2026-10-02"]);
db.run("UPDATE orders SET total = total * 1.2 WHERE placed < '2026-10-02'");
console.log(db.getRowsModified()); // rows changed by the last statement
// exec: run one or more statements, returns [{columns, values}] per statement that returns rows
const res = db.exec("SELECT customer, SUM(total) AS spent FROM orders GROUP BY customer ORDER BY spent DESC");
// [{ columns: ["customer","spent"], values: [["Dana Ruiz", 155.4], ["Omar Haddad", 42]] }]
exec returns an empty array when nothing returns rows, so check res.length before reading res[0]. exec has no parameter binding in its simple form; never build SQL by string concatenation from user input. Use run with ? parameters or a prepared statement.
Prepared statements
const stmt = db.prepare("SELECT * FROM orders WHERE customer = :who AND total > :min");
stmt.bind({ ":who": "Dana Ruiz", ":min": 100 });
while (stmt.step()) {
console.log(stmt.getAsObject()); // { id: 1, customer: 'Dana Ruiz', total: 155.4, placed: '2026-10-01' }
}
stmt.free(); // always free, or WebAssembly memory leaks
Related methods: stmt.bind([...]) for positional parameters, stmt.get() for the current row as an array, stmt.getColumnNames(), stmt.reset() to restart the statement (it also clears all bindings, so bind again before the next step()), and stmt.run(values) for repeated inserts:
const insert = db.prepare("INSERT INTO orders (customer, total, placed) VALUES ($c, $t, $p)");
for (const o of incoming) insert.run({ $c: o.customer, $t: o.total, $p: o.placed });
insert.free();
For a batch, wrap the loop in db.run("BEGIN") / db.run("COMMIT").
Save and load the database file
const fs = require("fs");
// save
const bytes = db
Установить sql-js в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл sql-js?
sql.js is SQLite compiled to WebAssembly, so a browser page or a Node.js script can create, load, query and export a real SQLite database with no server and no native module. Use when a user wants to "open a .sqlite file in the browser", "run SQL on the client", "query SQLite in Node without native bindings", "export a database to a file", or "add custom SQL functions in JavaScript". Covers initSqlJs, exec, prepared statements, export, and how persistence must be handled.
Как установить скилл sql-js?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл sql-js запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic