{"versions":{"0.0.1":{"name":"absurd-sql-optimized","version":"0.0.1","main":"./dist/index.js","scripts":{"build":"rm -rf dist && rollup -c rollup.config.js","jest":"jest","jest-debug":"jest --runInBand --useStderr","serve":"cd src/examples && ../../node_modules/.bin/webpack serve"},"devDependencies":{"@babel/plugin-transform-modules-commonjs":"^7.14.5","@jlongster/sql.js":"1.6.7","@rollup/plugin-alias":"^3.1.5","@rollup/plugin-node-resolve":"^13.0.4","babel":"^6.23.0","better-sqlite3":"^7.4.3","detect-browser":"^5.2.0","eslint":"^7.29.0","fast-check":"^2.17.0","html-webpack-plugin":"^5.3.2","jest":"^27.0.5","perf-deets":"^1.0.17","rollup":"^2.53.1","rollup-plugin-extensions":"^0.1.0","rollup-plugin-terser":"^7.0.2","rollup-plugin-web-worker-loader":"^1.6.1","uuid":"^8.3.2","webpack":"^5.41.1","webpack-cli":"^4.7.2","webpack-dev-server":"^3.11.2","worker-loader":"^3.0.8"},"dependencies":{"safari-14-idb-fix":"^1.0.4"},"gitHead":"ade37d94c78d0156da73e7bd540696b39269d9e6","description":"This is an absurd project.","_id":"absurd-sql-optimized@0.0.1","_nodeVersion":"16.16.0","_npmVersion":"8.11.0","dist":{"integrity":"sha512-v8r6mUMWXFilD/lCWK2fdBfXORn4S8mAnsa/0M+cjDchbP7NTOy6XXJnhBvVEhv6M8AS/c/IzyHi8pRtsviTAw==","shasum":"f71cca8081ae20dbe8d350983104259ebe46571d","tarball":"http://123.232.10.234:8212/nexus/content/groups/npm-public/absurd-sql-optimized/-/absurd-sql-optimized-0.0.1.tgz","fileCount":11,"unpackedSize":131457,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCQA8vN4Ykgdoq2+4PiboX5HjxnYFXfyvfoBkW2HF2ymgIhALrz5op97R91PUuL71ybHvfYNXCwl+z1erPWjJZR9Jtg"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkRONRACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrZrg/+MgOX7ggmEmVapWTQsw1KHmu0Hwq9l8r9ORGKSoKmAdDMBHZ5\r\nV6mAfxf5kCxqhZ6wgxZW1sQobrzQs4HEZVS5Udq/Qy8ocvapfTL129Z6Pdya\r\nzVD+cXeq9xXb52/odG2a1tobTNbV6N5ZRcZt46VKQUmyebBoSPJJI3YVTY4z\r\nCoYqs219T2t23xe34r461RYmAPpHqICEt3e0dF0f7EJNg8f1XDlqua9YeTmh\r\nj8TjSTi4RhEZael5wqPZuMq0As13V55Tj4h9R3p4WPeoiR0R/PV5+yoNVZe8\r\n5iCK99HXS5CXtuFbEMmXDO0EQPYmxUwKJh41Bcelb+PbkJgUKoR9JEIkLx9I\r\nKfjb4fXN4g6uLo2TtdOgCuRooretIldtEH9ty7bMr0XPzgXNwJ0N/1Ms75o6\r\nK7kF/y7CD1HaEA7MD6zw2QTvAPkbRXmM+mMoJIgqnaNM+bQlpW2T+BA6M1ua\r\n8kFxkJH9HFoKymLi3Rm5yTqCBbCulbDqZtQlHEkzJPgTKqbxdVTGhcjWyZIB\r\nG4Yj9zCffRCS0Mza6gfFEIVj4MlYJXTeQsfNa5hlGkC2NDtlewKsjjXp5zPT\r\n5SHYQWS7LsqMcSv0B2EBw8gOrEwf9Cl1iwxVccNQfQBg8HLpwEjKOSU7tI7U\r\nINJHbysQBIpMomX4JF+xpqEEWFkfd/W5kSk=\r\n=TH4i\r\n-----END PGP SIGNATURE-----\r\n","size":37119},"_npmUser":{"name":"anonymous","email":"1293499952@qq.com"},"directories":{},"maintainers":[{"name":"anonymous","email":"1293499952@qq.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/absurd-sql-optimized_0.0.1_1682236241631_0.6785573375733314"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2023-04-23T07:50:41.773Z","publish_time":1682236241773,"contributors":[]}},"dist-tags":{"latest":"0.0.1"},"name":"absurd-sql-optimized","time":{"created":"2023-04-23T07:51:12.519Z","modified":"2023-07-31T06:20:27.580Z","0.0.1":"2023-04-23T07:50:41.773Z"},"readme":"This is an absurd project.\n\nIt implements a backend for [sql.js](https://github.com/sql-js/sql.js/) (sqlite3 compiled for the web) that treats IndexedDB like a disk and stores data in blocks there. That means your sqlite3 database is persisted. And not in the terrible way of reading and writing the whole image at once -- it reads and writes your db in small chunks.\n\nIt basically stores a whole database into another database. Which is absurd.\n\n[See the demo](https://priceless-keller-d097e5.netlify.app/). You can also view an entire app using this [here](https://app-next.actualbudget.com/?wtf_source=absurd).\n\nYou should also read [this blog post](https://jlongster.com/future-sql-web) which explains the project in great detail.\n\nIf you like my work, feel free to [buy me a coffee!](https://www.buymeacoffee.com/jlongster)\n\n## How do I use it?\n\nYou can check out the [example project](https://github.com/jlongster/absurd-example-project) to get started. Or follow the steps below:\n\nFirst you install the packages:\n\n```\nyarn add @jlongster/sql.js absurd-sql\n```\n\nRight now you need to use my fork of `sql.js`, but I'm going to open a PR and hopefully get it merged. The changes are minimal.\n\nabsurd-sql **must** run in a worker. This is fine because you really shouldn't be blocking the main thread anyway. So on the main thread, do this:\n\n```js\nimport { initBackend } from 'absurd-sql/dist/indexeddb-main-thread';\n\nfunction init() {\n  let worker = new Worker(new URL('./index.worker.js', import.meta.url));\n  // This is only required because Safari doesn't support nested\n  // workers. This installs a handler that will proxy creating web\n  // workers through the main thread\n  initBackend(worker);\n}\n\ninit();\n```\n\nThen in `index.worker.js` do this:\n\n```js\nimport initSqlJs from '@jlongster/sql.js';\nimport { SQLiteFS } from 'absurd-sql';\nimport IndexedDBBackend from 'absurd-sql/dist/indexeddb-backend';\n\nasync function run() {\n  let SQL = await initSqlJs({ locateFile: file => file });\n  let sqlFS = new SQLiteFS(SQL.FS, new IndexedDBBackend());\n  SQL.register_for_idb(sqlFS);\n\n  SQL.FS.mkdir('/sql');\n  SQL.FS.mount(sqlFS, {}, '/sql');\n\n  const path = '/sql/db.sqlite';\n  if (typeof SharedArrayBuffer === 'undefined') {\n    let stream = SQL.FS.open(path, 'a+');\n    await stream.node.contents.readIfFallback();\n    SQL.FS.close(stream);\n  }\n\n  let db = new SQL.Database(path, { filename: true });\n  // You might want to try `PRAGMA page_size=8192;` too!\n  db.exec(`\n    PRAGMA journal_mode=MEMORY;\n  `);\n\n   // Your code\n}\n```\n\n## Requirements\n\nBecause this uses `SharedArrayBuffer` and the `Atomics` API, there are some requirement for code to run.\n\n* It must be run in a worker thread (you shouldn't block the main thread with queries anyway)\n* Your server must respond with the following headers:\n\n```\nCross-Origin-Opener-Policy: same-origin\nCross-Origin-Embedder-Policy: require-corp\n```\n\nThose headers are required because browsers only enable `SharedArrayBuffer` if you tell it to isolate the process. There are potential security problems if `SharedArrayBuffer` was available everywhere.\n\n## Fallback mode\n\nWe do support browsers without `SharedArrayBuffer` (only Safari). Read more about it here: https://jlongster.com/future-sql-web#fallback-mode-without-sharedarraybuffer\n\nThere are some limitations in this mode: only one tab can be writing the database at a time. The database will never be corrupted; if multiple tabs try to write it will just throw an error (in the future it should call a handler that you provide so you can notify the user).\n\n## Performance\n\nIt consistently beats IndexedDB performance up to 10x:\n\nRead performance: doing something like `SELECT SUM(value) FROM kv`:\n\n<img width=\"610\" alt=\"perf-sum-chrome\" src=\"https://user-images.githubusercontent.com/17031/129102253-8adf163a-76b6-4af8-a1cf-8e2e39012ab0.png\">\n\nWrite performance: doing a bulk insert:\n\n<img width=\"609\" alt=\"perf-writes-chrome\" src=\"https://user-images.githubusercontent.com/17031/129102454-b4c362b3-1b0a-4625-ac96-72fc276497f3.png\">\n\nThese are all on a 2015 macbook pro. Benchmark code is in `src/examples/bench`.\n\n## How does it work?\n\nRead [this blog post](https://jlongster.com/future-sql-web) for more details.\n\n## Where you can help\n\nThere are several things that could be done:\n\n* Add a bunch more tests\n* Implement a `webkitFileSystem` backend\n  * I already started it [here](https://gist.github.com/jlongster/ec00ddbb47b4b29897ab5939b8e32fbe), but initial results showed that it was way slower?\n* Bug fixes","users":{}}