{"id":46285,"library":"rtree-sql.js","title":"rtree-sql.js","description":"A fork of sql.js with R-Tree spatial indexing support. Version 1.7.0 (stable). This library compiles SQLite to JavaScript via Emscripten, enabling in-memory SQL databases in browsers and Node.js. Key differentiator: includes SQLite R-Tree extension for spatial queries, which the upstream sql.js does not enable by default. Same API as sql.js: create, query, export databases using pure JavaScript. Release cadence is sporadic, tied to upstream updates and patches for the R-Tree feature. Not to be confused with native SQLite3 bindings for Node.js; this is a pure in-memory implementation loading entire DB into memory.","status":"active","version":"1.7.0","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/danielbarela/sql.js","tags":["javascript","sql","sqlite","stand-alone","relational","database","RDBMS","data","query"],"install":[{"cmd":"npm install rtree-sql.js","lang":"bash","label":"npm"},{"cmd":"yarn add rtree-sql.js","lang":"bash","label":"yarn"},{"cmd":"pnpm add rtree-sql.js","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Default export is a factory function. CommonJS require works; ESM import may need default interop. In browsers, use window.initSqlJs after loading CDN script.","wrong":"import initSqlJs from 'rtree-sql.js';","symbol":"initSqlJs","correct":"const initSqlJs = require('rtree-sql.js');"},{"note":"Database is a class under the SQL namespace returned by initSqlJs(). You must await initSqlJs() first.","wrong":"new Database();","symbol":"SQL.Database","correct":"const db = new SQL.Database();"},{"note":"Statement objects are created via Database.prepare(), not directly instantiated.","wrong":"new SQL.Statement();","symbol":"SQL.Statement","correct":"const stmt = db.prepare('SELECT * FROM t');"}],"quickstart":{"code":"const initSqlJs = require('rtree-sql.js');\n\nasync function main() {\n  const SQL = await initSqlJs({\n    locateFile: file => `https://cdn.jsdelivr.net/npm/rtree-sql.js@1.7/dist/${file}`\n  });\n  const db = new SQL.Database();\n  db.run(\"CREATE TABLE points (id INTEGER, x REAL, y REAL);\");\n  db.run(\"INSERT INTO points VALUES (1, 1.0, 2.0);\");\n  const stmt = db.prepare(\"SELECT * FROM points;\");\n  while (stmt.step()) {\n    const row = stmt.getAsObject();\n    console.log(row);\n  }\n  stmt.free();\n  db.close();\n}\nmain();","lang":"javascript","description":"Shows how to load the library, create an in-memory database, create a table, insert data, and query using prepared statements."},"warnings":[{"fix":"Call db.export() to get Uint8Array and persist via localStorage or file download.","message":"Database is stored in memory; changes are lost unless you explicitly export the database to a Uint8Array and save it.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Ensure you await initSqlJs() at the top level before using SQL.Database.","message":"initSqlJs() must be called and awaited before creating any database. Calls before initialization will fail.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Set locateFile to point to the directory containing sql-wasm.wasm (e.g., from node_modules or CDN).","message":"The .wasm file must be served alongside the JS. In Node.js it's loaded automatically, but in browsers you must provide locateFile option.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Wrap code in async function and await initSqlJs(config).","message":"Breaking: In version 1.0, the API changed from synchronous to asynchronous init (initSqlJs returns a Promise). Older code using synchronous init will break.","severity":"breaking","affected_versions":">=1.0"},{"fix":"try { new SQL.Database(data) } catch(e) { ... }","message":"SQL.Database() constructor can throw if given invalid Uint8Array. Always catch errors.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"search_vec":"'1.7.0':14 'alon':109 'api':55 'bind':88 'browser':31 'cadenc':66 'compil':18 'confus':84 'creat':58 'data':113 'databas':29,61,111 'db':101 'default':53 'differenti':35 'emscripten':23 'enabl':24,51 'entir':100 'export':60 'extens':41 'featur':80 'fork':3 'implement':98 'in-memori':25,95 'includ':36 'index':11 'javascript':21,64,104 'key':34 'librari':17 'load':99 'memori':27,97,103 'nativ':86 'node.js':33,90 'patch':74 'pure':63,94 'queri':44,59,114 'r':8,39,78 'r-tree':7,38,77 'rdbms':112 'relat':110 'releas':65 'rtree-sql.js':1 'spatial':10,43 'sporad':68 'sql':28,105 'sql.js':5,48,57 'sqlite':19,37,106 'sqlite3':87 'stabl':15 'stand':108 'stand-alon':107 'support':12 'tie':69 'tree':9,40,79 'updat':72 'upstream':47,71 'use':62 'version':13 'via':22","created_at":"2026-06-07T12:59:11.538651+00:00","updated_at":"2026-06-07T12:59:11.538651+00:00","problems":[{"fix":"Ensure initSqlJs() is awaited: const SQL = await initSqlJs();","cause":"Calling new SQL.Database() before initSqlJs resolves or using uninitialized SQL variable.","error":"TypeError: SQL is not a constructor"},{"fix":"Run npm install rtree-sql.js and use require('rtree-sql.js').","cause":"Package not installed or import path incorrect.","error":"Error: Cannot find module 'rtree-sql.js'"},{"fix":"Always await initSqlJs() first; do not reuse a closed database.","cause":"db was created before initSqlJs completed, or db is already closed.","error":"TypeError: db.prepare is not a function"}],"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/danielbarela/sql.js","github":"ssh://git@github.com/danielbarela/sql.js","docs":null,"changelog":null,"pypi":null,"npm":"rtree-sql.js","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}}