{"_id":"@aphro/absurd-sql","name":"@aphro/absurd-sql","dist-tags":{"latest":"0.0.53"},"versions":{"0.0.53":{"name":"@aphro/absurd-sql","version":"0.0.53","main":"./dist/index.js","devDependencies":{"@aphro/sql.js":"^1.7.0","@babel/plugin-transform-modules-commonjs":"^7.14.5","@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"},"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"},"description":"This is an absurd project.","_id":"@aphro/absurd-sql@0.0.53","_integrity":"sha512-VK+ZY9TvamiUFRxPHjdMSDsHiMyObhdxVwdJD+oQxUPpJqu2zPFsacYOCKSnBoq8wzYudyB0GIE/KvOd6nYyqw==","_resolved":"/private/var/folders/7f/dkx7mm_53cv0bs3kl15x9x1c0000gn/T/a16ba9cb29d0fb9af708b0ed748f2d43/aphro-absurd-sql-0.0.53.tgz","_from":"file:aphro-absurd-sql-0.0.53.tgz","_nodeVersion":"18.2.0","_npmVersion":"8.10.0","dist":{"integrity":"sha512-VK+ZY9TvamiUFRxPHjdMSDsHiMyObhdxVwdJD+oQxUPpJqu2zPFsacYOCKSnBoq8wzYudyB0GIE/KvOd6nYyqw==","shasum":"86e90c1a3f8b622ccda9d30cecb8d9612d24226a","tarball":"https://registry.npmjs.org/@aphro/absurd-sql/-/absurd-sql-0.0.53.tgz","fileCount":40,"unpackedSize":47614391,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDM1KwZlSxk2lL9d+bli4rJJn54EyTwmNidy9yv24mTtQIgCMgyLc8Qu56DPoiTM8GJNUlpS16C1v4AcjFvKSnqz1k="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJio2roACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqiOBAAhM0/37t+osaxYSNHlAD7lqui0kwaOfSVWzNMTDE+dqRTS4h8\r\n7wAQ1tfDIM4R71/5YvR67DPLeb4TlITOZlrUx0buhHn/ZR/MvPghfSInMbQx\r\nPjfzqLyEmWokAsfAGqmu2izweGbHQwVNR0+BP4u//2kgAgxdH6mj0ANyoBqP\r\nZol7qu+PtXW1UyN200uq9B7xQzP5e8bMKG/t+dUuqM5luJU4PJ6o7qUuepJO\r\n8Vk3CY31JId+SaYpjXTKmnXW9OtpjvwUTvNDN7lY9TizV2zGNWsCNXsYfJFH\r\n5NCUyQrw3/4dPPaTjntnKQZ+2H5kGu7scRUKKAPigp5bzF+9WTfJNGfaMA56\r\nehjpcCPOPSH+ZHI9/VS9vUQyamsfqZ8GmQ0p1vS4vFQPn+9AzYRFnn8CmODH\r\n1GLjoK+OvpEtlNBLktKExpI9TWQu5gvEtFrFIvXV1AXyVZe7j+f/LFlnY++V\r\n8QF1jfaoAopLkCt6FQA7Wdx01qr+WGSYAg3eHMXLTfIev7gUOJ57SAZ/X1KS\r\n04nIJJsCg5D9JiLjVs4Jmoq548ECAemy/XryPMQu013YTQdLUItiN7agj3+1\r\n4+2XHp8IB/9w24c2Zq7MFOej3bL6pHFS9n/MEgs4ElKLY+pIg9GbuLZJNOd0\r\nqPZwXJ/c/hWpK0WHRmTwuqI6O1IJYSY6hQo=\r\n=VOWt\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"tantaman","email":"matt.crinklaw@gmail.com"},"directories":{},"maintainers":[{"name":"tantaman","email":"matt.crinklaw@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/absurd-sql_0.0.53_1654876903926_0.6781492763560437"},"_hasShrinkwrap":false}},"time":{"created":"2022-06-10T16:01:43.837Z","0.0.53":"2022-06-10T16:01:44.311Z","modified":"2022-06-10T16:01:44.471Z"},"maintainers":[{"name":"tantaman","email":"matt.crinklaw@gmail.com"}],"description":"This is an absurd project.","readme":"\nThis 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\n","readmeFilename":"README.md"}