[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-3380":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":16,"stars7d":17,"stars30d":18,"stars90d":16,"forks30d":16,"starsTrendScore":19,"compositeScore":20,"rankGlobal":10,"rankLanguage":10,"license":21,"archived":22,"fork":22,"defaultBranch":23,"hasWiki":24,"hasPages":24,"topics":25,"createdAt":10,"pushedAt":10,"updatedAt":32,"readmeContent":33,"aiSummary":34,"trendingCount":16,"starSnapshotCount":16,"syncStatus":35,"lastSyncTime":36,"discoverSource":37},3380,"sql.js","sql-js\u002Fsql.js","sql-js","A javascript library to run SQLite on the web.  ","http:\u002F\u002Fsql.js.org",null,"JavaScript",13626,1107,228,128,0,5,19,4,73.53,"Other",false,"master",true,[26,27,28,29,30,31],"database","emscripten","javascript","sql","sqlite","wasm","2026-06-12 04:00:17","\u003Cimg src=\"https:\u002F\u002Fuser-images.githubusercontent.com\u002F552629\u002F76405509-87025300-6388-11ea-86c9-af882abb00bd.png\" width=\"40\" height=\"40\" \u002F>\n\n# SQLite compiled to JavaScript\n\n[![CI status](https:\u002F\u002Fgithub.com\u002Fsql-js\u002Fsql.js\u002Fworkflows\u002FCI\u002Fbadge.svg)](https:\u002F\u002Fgithub.com\u002Fsql-js\u002Fsql.js\u002Factions)\n[![npm](https:\u002F\u002Fimg.shields.io\u002Fnpm\u002Fv\u002Fsql.js)](https:\u002F\u002Fwww.npmjs.com\u002Fpackage\u002Fsql.js)\n[![CDNJS version](https:\u002F\u002Fimg.shields.io\u002Fcdnjs\u002Fv\u002Fsql.js.svg)](https:\u002F\u002Fcdnjs.com\u002Flibraries\u002Fsql.js)\n\n*sql.js* is a javascript SQL database. It allows you to create a relational database and query it entirely in the browser. You can try it in [this online demo](https:\u002F\u002Fsql.js.org\u002Fexamples\u002FGUI\u002F). It uses a [virtual database file stored in memory](https:\u002F\u002Femscripten.org\u002Fdocs\u002Fporting\u002Ffiles\u002Ffile_systems_overview.html), and thus **doesn't persist the changes** made to the database. However, it allows you to **import** any existing sqlite file, and to **export** the created database as a [JavaScript typed array](https:\u002F\u002Fdeveloper.mozilla.org\u002Fen-US\u002Fdocs\u002FWeb\u002FJavaScript\u002FTyped_arrays).\n\n*sql.js* uses [emscripten](https:\u002F\u002Femscripten.org\u002Fdocs\u002Fintroducing_emscripten\u002Fabout_emscripten.html) to compile [SQLite](http:\u002F\u002Fsqlite.org\u002Fabout.html) to webassembly (or to javascript code for compatibility with older browsers). It includes [contributed math and string extension functions](https:\u002F\u002Fwww.sqlite.org\u002Fcontrib?orderby=date).\n\nsql.js can be used like any traditional JavaScript library. If you are building a native application in JavaScript (using Electron for instance), or are working in node.js, you will likely prefer to use [a native binding of SQLite to JavaScript](https:\u002F\u002Fwww.npmjs.com\u002Fpackage\u002Fsqlite3). A native binding will not only be faster because it will run native code, but it will also be able to work on database files directly instead of having to load the entire database in memory, avoiding out of memory errors and further improving performances.\n\nSQLite is public domain, sql.js is MIT licensed.\n\n## API documentation\nA [full API documentation](https:\u002F\u002Fsql.js.org\u002Fdocumentation\u002F) for all the available classes and methods is available.\nIt is generated from comments inside the source code, and is thus always up to date.\n\n## Usage\n\nBy default, *sql.js* uses [wasm](https:\u002F\u002Fdeveloper.mozilla.org\u002Fen-US\u002Fdocs\u002FWebAssembly), and thus needs to load a `.wasm` file in addition to the javascript library. You can find this file in `.\u002Fnode_modules\u002Fsql.js\u002Fdist\u002Fsql-wasm.wasm` after installing sql.js from npm, and instruct your bundler to add it to your static assets or load it from [a CDN](https:\u002F\u002Fcdnjs.com\u002Flibraries\u002Fsql.js). Then use the [`locateFile`](https:\u002F\u002Femscripten.org\u002Fdocs\u002Fapi_reference\u002Fmodule.html#Module.locateFile) property of the configuration object passed to `initSqlJs` to indicate where the file is. If you use an asset builder such as webpack, you can automate this. See [this demo of how to integrate sql.js with webpack (and react)](https:\u002F\u002Fgithub.com\u002Fsql-js\u002Freact-sqljs-demo).\n\n```javascript\nconst initSqlJs = require('sql.js');\n\u002F\u002F or if you are in a browser:\n\u002F\u002F const initSqlJs = window.initSqlJs;\n\nconst SQL = await initSqlJs({\n  \u002F\u002F Required to load the wasm binary asynchronously. Of course, you can host it wherever you want\n  \u002F\u002F You can omit locateFile completely when running in node\n  locateFile: file => `https:\u002F\u002Fsql.js.org\u002Fdist\u002F${file}`\n});\n\n\u002F\u002F Create a database\nconst db = new SQL.Database();\n\u002F\u002F NOTE: You can also use new SQL.Database(data) where\n\u002F\u002F data is an Uint8Array representing an SQLite database file\n\n\n\u002F\u002F Execute a single SQL string that contains multiple statements\nlet sqlstr = \"CREATE TABLE hello (a int, b char); \\\nINSERT INTO hello VALUES (0, 'hello'); \\\nINSERT INTO hello VALUES (1, 'world');\";\ndb.run(sqlstr); \u002F\u002F Run the query without returning anything\n\n\u002F\u002F Prepare an sql statement\nconst stmt = db.prepare(\"SELECT * FROM hello WHERE a=:aval AND b=:bval\");\n\n\u002F\u002F Bind values to the parameters and fetch the results of the query\nconst result = stmt.getAsObject({':aval' : 1, ':bval' : 'world'});\nconsole.log(result); \u002F\u002F Will print {a:1, b:'world'}\n\n\u002F\u002F Bind other values\nstmt.bind([0, 'hello']);\nwhile (stmt.step()) console.log(stmt.get()); \u002F\u002F Will print [0, 'hello']\n\u002F\u002F free the memory used by the statement\nstmt.free();\n\u002F\u002F You can not use your statement anymore once it has been freed.\n\u002F\u002F But not freeing your statements causes memory leaks. You don't want that.\n\nconst res = db.exec(\"SELECT * FROM hello\");\n\u002F*\n[\n  {columns:['a','b'], values:[[0,'hello'],[1,'world']]}\n]\n*\u002F\n\n\u002F\u002F You can also use JavaScript functions inside your SQL code\n\u002F\u002F Create the js function you need\nfunction add(a, b) {return a+b;}\n\u002F\u002F Specifies the SQL function's name, the number of it's arguments, and the js function to use\ndb.create_function(\"add_js\", add);\n\u002F\u002F Run a query in which the function is used\ndb.run(\"INSERT INTO hello VALUES (add_js(7, 3), add_js('Hello ', 'world'));\"); \u002F\u002F Inserts 10 and 'Hello world'\n\n\u002F\u002F You can create custom aggregation functions, by passing a name\n\u002F\u002F and a set of functions to `db.create_aggregate`:\n\u002F\u002F\n\u002F\u002F - an `init` function. This function receives no argument and returns\n\u002F\u002F   the initial value for the state of the aggregate function.\n\u002F\u002F - a `step` function. This function takes two arguments\n\u002F\u002F    - the current state of the aggregation\n\u002F\u002F    - a new value to aggregate to the state\n\u002F\u002F  It should return a new value for the state.\n\u002F\u002F - a `finalize` function. This function receives a state object, and\n\u002F\u002F   returns the final value of the aggregate. It can be omitted, in which case\n\u002F\u002F   the final value of the state will be returned directly by the aggregate function.\n\u002F\u002F\n\u002F\u002F Here is an example aggregation function, `json_agg`, which will collect all\n\u002F\u002F input values and return them as a JSON array:\ndb.create_aggregate(\n  \"json_agg\",\n  {\n    init: () => [],\n    step: (state, val) => [...state, val],\n    finalize: (state) => JSON.stringify(state),\n  }\n);\n\ndb.exec(\"SELECT json_agg(column1) FROM (VALUES ('hello'), ('world'))\");\n\u002F\u002F -> The result of the query is the string '[\"hello\",\"world\"]'\n\n\u002F\u002F Export the database to an Uint8Array containing the SQLite database file\nconst binaryArray = db.export();\n```\n\n## Demo\nThere are a few examples [available here](https:\u002F\u002Fsql-js.github.io\u002Fsql.js\u002Findex.html). The most full-featured is the [Sqlite Interpreter](https:\u002F\u002Fsql-js.github.io\u002Fsql.js\u002Fexamples\u002FGUI\u002Findex.html).\n\n## Examples\nThe test files provide up to date example of the use of the api.\n### Inside the browser\n#### Example **HTML** file:\n```html\n\u003Cmeta charset=\"utf8\" \u002F>\n\u003Chtml>\n  \u003Cscript src='\u002Fdist\u002Fsql-wasm.js'>\u003C\u002Fscript>\n  \u003Cscript>\n    config = {\n      locateFile: filename => `\u002Fdist\u002F${filename}`\n    }\n    \u002F\u002F The `initSqlJs` function is globally provided by all of the main dist files if loaded in the browser.\n    \u002F\u002F We must specify this locateFile function if we are loading a wasm file from anywhere other than the current html page's folder.\n    initSqlJs(config).then(function(SQL){\n      \u002F\u002FCreate the database\n      const db = new SQL.Database();\n      \u002F\u002F Run a query without reading the results\n      db.run(\"CREATE TABLE test (col1, col2);\");\n      \u002F\u002F Insert two rows: (1,111) and (2,222)\n      db.run(\"INSERT INTO test VALUES (?,?), (?,?)\", [1,111,2,222]);\n\n      \u002F\u002F Prepare a statement\n      const stmt = db.prepare(\"SELECT * FROM test WHERE col1 BETWEEN $start AND $end\");\n      stmt.getAsObject({$start:1, $end:1}); \u002F\u002F {col1:1, col2:111}\n\n      \u002F\u002F Bind new values\n      stmt.bind({$start:1, $end:2});\n      while(stmt.step()) { \u002F\u002F\n        const row = stmt.getAsObject();\n        console.log('Here is a row: ' + JSON.stringify(row));\n      }\n    });\n  \u003C\u002Fscript>\n  \u003Cbody>\n    Output is in Javascript console\n  \u003C\u002Fbody>\n\u003C\u002Fhtml>\n```\n\n#### Creating a database from a file chosen by the user\n`SQL.Database` constructor takes an array of integer representing a database file as an optional parameter.\nThe following code uses an HTML input as the source for loading a database:\n```javascript\ndbFileElm.onchange = () => {\n  const f = dbFileElm.files[0];\n  const r = new FileReader();\n  r.onload = function() {\n    const Uints = new Uint8Array(r.result);\n    db = new SQL.Database(Uints);\n  }\n  r.readAsArrayBuffer(f);\n}\n```\nSee : https:\u002F\u002Fsql-js.github.io\u002Fsql.js\u002Fexamples\u002FGUI\u002Fgui.js\n\n#### Loading a database from a server\n\n##### using fetch\n\n```javascript\nconst sqlPromise = initSqlJs({\n  locateFile: file => `https:\u002F\u002Fpath\u002Fto\u002Fyour\u002Fdist\u002Ffolder\u002Fdist\u002F${file}`\n});\nconst dataPromise = fetch(\"\u002Fpath\u002Fto\u002Fdatabase.sqlite\").then(res => res.arrayBuffer());\nconst [SQL, buf] = await Promise.all([sqlPromise, dataPromise])\nconst db = new SQL.Database(new Uint8Array(buf));\n```\n\n##### using XMLHttpRequest\n\n```javascript\nconst xhr = new XMLHttpRequest();\n\u002F\u002F For example: https:\u002F\u002Fgithub.com\u002Flerocha\u002Fchinook-database\u002Fraw\u002Fmaster\u002FChinookDatabase\u002FDataSources\u002FChinook_Sqlite.sqlite\nxhr.open('GET', '\u002Fpath\u002Fto\u002Fdatabase.sqlite', true);\nxhr.responseType = 'arraybuffer';\n\nxhr.onload = e => {\n  const uInt8Array = new Uint8Array(xhr.response);\n  const db = new SQL.Database(uInt8Array);\n  const contents = db.exec(\"SELECT * FROM my_table\");\n  \u002F\u002F contents is now [{columns:['col1','col2',...], values:[[first row], [second row], ...]}]\n};\nxhr.send();\n```\nSee: https:\u002F\u002Fgithub.com\u002Fsql-js\u002Fsql.js\u002Fwiki\u002FLoad-a-database-from-the-server\n\n\n### Use from node.js\n\n`sql.js` is [hosted on npm](https:\u002F\u002Fwww.npmjs.org\u002Fpackage\u002Fsql.js). To install it, you can simply run `npm install sql.js`.\nAlternatively, you can simply download `sql-wasm.js` and `sql-wasm.wasm`, from the download link below.\n\n#### read a database from the disk:\n```javascript\nconst fs = require('fs');\nconst initSqlJs = require('sql-wasm.js');\nconst filebuffer = fs.readFileSync('test.sqlite');\n\ninitSqlJs().then(function(SQL){\n  \u002F\u002F Load the db\n  const db = new SQL.Database(filebuffer);\n});\n\n```\n\n#### write a database to the disk\nYou need to convert the result of `db.export` to a buffer\n```javascript\nconst fs = require(\"fs\");\n\u002F\u002F [...] (create the database)\nconst data = db.export();\nconst buffer = Buffer.from(data);\nfs.writeFileSync(\"filename.sqlite\", buffer);\n```\n\nSee : https:\u002F\u002Fgithub.com\u002Fsql-js\u002Fsql.js\u002Fblob\u002Fmaster\u002Ftest\u002Ftest_node_file.js\n\n### Use as web worker\nIf you don't want to run CPU-intensive SQL queries in your main application thread,\nyou can use the *more limited* WebWorker API.\n\nYou will need to download `worker.sql-wasm.js` and `worker.sql-wasm.wasm` from the [release page](https:\u002F\u002Fgithub.com\u002Fsql-js\u002Fsql.js\u002Freleases).\n\nExample:\n```html\n\u003Cscript>\n  const worker = new Worker(\"\u002Fdist\u002Fworker.sql-wasm.js\");\n  worker.onmessage = () => {\n    console.log(\"Database opened\");\n    worker.onmessage = event => {\n      console.log(event.data); \u002F\u002F The result of the query\n    };\n\n    worker.postMessage({\n      id: 2,\n      action: \"exec\",\n      sql: \"SELECT age,name FROM test WHERE id=$id\",\n      params: { \"$id\": 1 }\n    });\n  };\n\n  worker.onerror = e => console.log(\"Worker error: \", e);\n  worker.postMessage({\n    id:1,\n    action:\"open\",\n    buffer:buf, \u002F*Optional. An ArrayBuffer representing an SQLite Database file*\u002F\n  });\n\u003C\u002Fscript>\n```\n### Enabling BigInt support\nIf you need ```BigInt``` support, it is partially supported since most browsers now supports it including Safari.Binding ```BigInt``` is still not supported, only getting ```BigInt``` from the database is supported for now.\n\n```html\n\u003Cscript>\n  const stmt = db.prepare(\"SELECT * FROM test\");\n  const config = {useBigInt: true};\n  \u002F*Pass optional config param to the get function*\u002F\n  while (stmt.step()) console.log(stmt.get(null, config));\n\n  \u002F*OR*\u002F\n  const results = db.exec(\"SELECT * FROM test\", config);\n  console.log(results[0].values)\n\u003C\u002Fscript>\n```\nOn WebWorker, you can just add ```config``` param before posting a message. With this, you wont have to pass config param on ```get``` function.\n\n```html\n\u003Cscript>\n  worker.postMessage({\n    id:1,\n    action:\"exec\",\n    sql: \"SELECT * FROM test\",\n    config: {useBigInt: true}, \u002F*Optional param*\u002F\n  });\n\u003C\u002Fscript>\n```\n\nSee [examples\u002FGUI\u002Fgui.js](examples\u002FGUI\u002Fgui.js) for a full working example.\n\n## Flavors\u002Fversions Targets\u002FDownloads\n\nThis library includes both WebAssembly and asm.js versions of Sqlite. (WebAssembly is the newer, preferred way to compile to JavaScript, and has superceded asm.js. It produces smaller, faster code.) Asm.js versions are included for compatibility.\n\n## Upgrading from 0.x to 1.x\n\nVersion 1.0 of sql.js must be loaded asynchronously, whereas asm.js was able to be loaded synchronously.\n\nSo in the past, you would:\n```html\n\u003Cscript src='js\u002Fsql.js'>\u003C\u002Fscript>\n\u003Cscript>\n  const db = new SQL.Database();\n  \u002F\u002F...\n\u003C\u002Fscript>\n```\nor:\n```javascript\nconst SQL = require('sql.js');\nconst db = new SQL.Database();\n\u002F\u002F...\n```\n\nVersion 1.x:\n```html\n\u003Cscript src='dist\u002Fsql-wasm.js'>\u003C\u002Fscript>\n\u003Cscript>\n  initSqlJs({ locateFile: filename => `\u002Fdist\u002F${filename}` }).then(function(SQL){\n    const db = new SQL.Database();\n    \u002F\u002F...\n  });\n\u003C\u002Fscript>\n```\nor:\n```javascript\nconst initSqlJs = require('sql-wasm.js');\ninitSqlJs().then(function(SQL){\n  const db = new SQL.Database();\n  \u002F\u002F...\n});\n```\n\n`NOTHING` is now a reserved word in SQLite, whereas previously it was not. This could cause errors like `Error: near \"nothing\": syntax error`\n\n### Downloading\u002FUsing: ###\nAlthough asm.js files were distributed as a single Javascript file, WebAssembly libraries are most efficiently distributed as a pair of files, the `.js`  loader and the `.wasm` file, like `sql-wasm.js` and `sql-wasm.wasm`. The `.js` file is responsible for loading the `.wasm` file. You can find these files on our [release page](https:\u002F\u002Fgithub.com\u002Fsql-js\u002Fsql.js\u002Freleases)\n\n\n\n\n## Versions of sql.js included in the distributed artifacts\nYou can always find the latest published artifacts on https:\u002F\u002Fgithub.com\u002Fsql-js\u002Fsql.js\u002Freleases\u002Flatest.\n\nFor each [release](https:\u002F\u002Fgithub.com\u002Fsql-js\u002Fsql.js\u002Freleases\u002F), you will find a file called `sqljs.zip` in the *release assets*. It will contain:\n - `sql-wasm.js` : The Web Assembly version of Sql.js. Minified and suitable for production. Use this. If you use this, you will need to include\u002Fship `sql-wasm.wasm` as well.\n - `sql-wasm-debug.js` : The Web Assembly, Debug version of Sql.js. Larger, with assertions turned on. Useful for local development. You will need to include\u002Fship `sql-wasm-debug.wasm` if you use this.\n - `sql-asm.js` : The older asm.js version of Sql.js. Slower and larger. Provided for compatibility reasons.\n - `sql-asm-memory-growth.js` : Asm.js doesn't allow for memory to grow by default, because it is slower and de-optimizes. If you are using sql-asm.js and you see this error (`Cannot enlarge memory arrays`), use this file.\n - `sql-asm-debug.js` : The _Debug_ asm.js version of Sql.js. Use this for local development.\n - `worker.*` - Web Worker versions of the above libraries. More limited API. See [examples\u002FGUI\u002Fgui.js](examples\u002FGUI\u002Fgui.js) for a good example of this.\n\n## Compiling\u002FContributing\n\nGeneral consumers of this library don't need to read any further. (The compiled files are available via the [release page](https:\u002F\u002Fgithub.com\u002Fsql-js\u002Fsql.js\u002Freleases).)\n\nIf you want to compile your own version of SQLite for WebAssembly, or want to contribute to this project, see [CONTRIBUTING.md](CONTRIBUTING.md).\n","sql.js 是一个用于在浏览器中运行 SQLite 的 JavaScript 库。它通过 Emscripten 将 SQLite 编译为 WebAssembly 或纯 JavaScript 代码，以支持旧版浏览器，并提供了丰富的数学和字符串扩展函数。核心功能包括创建、查询内存中的关系型数据库，以及导入导出 SQLite 文件。由于数据存储于内存中，因此不会持久化修改，但非常适合需要在客户端进行临时数据处理的应用场景，如在线数据分析工具或基于 Web 的报表生成器。此外，sql.js 还适用于构建不需要直接访问本地文件的轻量级前端应用。",2,"2026-06-11 02:53:55","top_language"]