{"id":46438,"library":"sql.js-fts5","title":"sql.js","description":"sql.js is a pure JavaScript SQLite library compiled with Emscripten, allowing SQL database operations directly in the browser or Node.js without native dependencies. Current stable version is 1.11.0 (as of early 2025), with regular releases. It supports full SQLite syntax, prepared statements, transaction support, and exports database as Uint8Array. Unlike native SQLite bindings (e.g., better-sqlite3), sql.js works entirely in memory and requires loading a .wasm file. It is ideal for client-side web apps, offline tools, and scenarios where native modules cannot be used. The library is MIT licensed and community-maintained.","status":"active","version":"1.4.0","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/sql-js/sql.js","tags":["javascript","sql","sqlite","stand-alone","relational","database","RDBMS","data","query"],"install":[{"cmd":"npm install sql.js-fts5","lang":"bash","label":"npm"},{"cmd":"yarn add sql.js-fts5","lang":"bash","label":"yarn"},{"cmd":"pnpm add sql.js-fts5","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Default export is a factory function. ESM import is not supported; use CommonJS or dynamic import.","wrong":"import initSqlJs from 'sql.js';","symbol":"initSqlJs","correct":"const initSqlJs = require('sql.js');"},{"note":"Database is a property of the initialized module, not a standalone export.","wrong":"const db = new Database();","symbol":"Database","correct":"const db = new SQL.Database();"},{"note":"Statement objects are created via Database.prepare(), not directly instantiated.","wrong":"const stmt = new SQL.Statement(db);","symbol":"Statement","correct":"const stmt = db.prepare('SELECT ?');"}],"quickstart":{"code":"const initSqlJs = require('sql.js');\nconst SQL = await initSqlJs({\n  locateFile: file => `https://sql.js.org/dist/${file}`\n});\nconst db = new SQL.Database();\ndb.run('CREATE TABLE test (id int, name text)');\ndb.run('INSERT INTO test VALUES (?,?)', [1, 'hello']);\nconst stmt = db.prepare('SELECT * FROM test');\nwhile (stmt.step()) console.log(stmt.getAsObject());\ndb.close();","lang":"javascript","description":"Shows asynchronous initialization, database creation, prepared statements, and query execution."},"warnings":[{"fix":"Provide locateFile in initSqlJs config pointing to the .wasm file, or copy the file from node_modules.","message":"WASM binary must be loaded separately; locateFile is required in browsers","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Call db.export() to get Uint8Array, and save it to disk or localStorage.","message":"Database exists only in memory; changes are lost unless explicitly exported","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"For file persistence, use native SQLite bindings like better-sqlite3.","message":"In-memory only, no direct file write support","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Call stmt.free() after use, especially in long-running applications.","message":"Statement object must be freed manually to avoid memory leaks","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Create separate Database instances per worker or use structured cloning.","message":"Thread-safety: not safe to share a Database across Web Workers without cloning","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'1.11.0':29 '2025':33 'allow':12 'alon':103 'app':78 'better':57 'better-sqlite3':56 'bind':54 'browser':19 'cannot':86 'client':75 'client-sid':74 'communiti':96 'community-maintain':95 'compil':9 'current':25 'data':107 'databas':14,48,105 'depend':24 'direct':16 'e.g':55 'earli':32 'emscripten':11 'entir':61 'export':47 'file':69 'full':39 'ideal':72 'javascript':6,98 'librari':8,90 'licens':93 'load':66 'maintain':97 'memori':63 'mit':92 'modul':85 'nativ':23,52,84 'node.js':21 'offlin':79 'oper':15 'prepar':42 'pure':5 'queri':108 'rdbms':106 'regular':35 'relat':104 'releas':36 'requir':65 'scenario':82 'side':76 'sql':13,99 'sql.js':1,2,59 'sqlite':7,40,53,100 'sqlite3':58 'stabl':26 'stand':102 'stand-alon':101 'statement':43 'support':38,45 'syntax':41 'tool':80 'transact':44 'uint8array':50 'unlik':51 'use':88 'version':27 'wasm':68 'web':77 'without':22 'work':60","created_at":"2026-06-07T12:59:55.972888+00:00","updated_at":"2026-06-07T12:59:55.972888+00:00","problems":[{"fix":"Wait for initSqlJs to complete and pass the module to an async function.","cause":"Using SQL.Database before initSqlJs resolves","error":"TypeError: Cannot read property 'Database' of undefined"},{"fix":"Provide locateFile option in initSqlJs config pointing to the .wasm file.","cause":"locateFile not configured or incorrect path","error":"Error: cannot locate the wasm file"},{"fix":"Do not reuse closed database; create a new instance if needed.","cause":"Trying to use a database after calling db.close()","error":"Error: Database is closed"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"http://github.com/sql-js/sql.js","github":"ssh://git@github.com/sql-js/sql.js","docs":null,"changelog":null,"pypi":null,"npm":"sql.js-fts5","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}