{"schemaVersion":1,"id":"better-sqlite3","name":"better-sqlite3","locale":"en","canonicalUrl":"https://base.akulich.dev/en/library/better-sqlite3/","officialUrl":"https://github.com/WiseLibs/better-sqlite3","isCatalog":false,"description":"A Node.js SQLite binding with a synchronous API and transaction support: it embeds a local SQL database in server or desktop applications.","tasks":["Embed SQLite in a Node.js application","Connect synchronous queries and a transaction for a related write operation"],"categoryIds":["backend"],"subcategoryIds":["backend.databases"],"tags":["better-sqlite3","database","Development"],"aliases":["WiseLibs/better-sqlite3","better-sqlite3","sqlite3-node"],"platforms":[],"stack":[],"compatibility":null,"pricing":"free","freeUsage":"Code and local use under MIT.","paidUsage":"Computing resources, self-hosting, and external services are paid for separately if used.","license":"MIT for better-sqlite3 code: use, modification, distribution, and sale are permitted with the copyright notice and permission text retained. Code is provided without warranties; dependencies and third-party services have their own terms.","selectionGuide":{"purpose":"Embed SQLite in a Node.js application","chooseWhen":["Embed SQLite in a Node.js application","Connect synchronous queries and a transaction for a related write operation"],"considerInstead":[],"requirements":["A Node.js version supported at installation time.","Install the package in a supported Node.js environment and check the native binding for your build. Define the SQL schema, prepared statement parameters, read/write patterns, and backup recovery."],"limitations":["Costs and limits of free use: Computing resources, self-hosting, and external services are paid for separately if used.","Terms of use: MIT for better-sqlite3 code: use, modification, distribution, and sale are permitted with the copyright notice and permission text retained. Code is provided without warranties; dependencies and third-party services have their own terms.","The README separately warns about heavy write concurrency and very large databases."],"faq":[{"question":"What can you use for free in better-sqlite3?","answer":"Code and local use under MIT."},{"question":"What additional costs might arise with better-sqlite3?","answer":"Computing resources, self-hosting, and external services are paid for separately if used."},{"question":"What terms of use matter for better-sqlite3?","answer":"MIT for better-sqlite3 code: use, modification, distribution, and sale are permitted with the copyright notice and permission text retained. Code is provided without warranties; dependencies and third-party services have their own terms."},{"question":"How do you get started with better-sqlite3?","answer":"Define tables and prepare SQL queries for the selected scenario. The README demonstrates Database and prepare(...).get(...) with a bound parameter; use query parameters for your own inputs. Connect synchronous queries and a transaction for a related write operation. db.transaction creates a synchronous function: normal completion commits, and an exception rolls back. Do not put async/await inside it; the API explicitly warns of premature transaction completion. Check schema changes, indexes, and data recovery. The API describes db.backup as a Promise producing a SQLite backup file; a possible check opens the restored copy and compares reference queries. Successfully creating a file does not replace a recovery test."},{"question":"When might better-sqlite3 be unsuitable?","answer":"The README highlights heavy concurrent writes, many reads returning megabytes of data, and databases around a terabyte. For these situations, the author suggests a full server database; check this general guidance against project load."},{"question":"What should I check when updating better-sqlite3?","answer":"Both the library API and bundled SQLite may change. The README recommends reading both projects' release notes; slow queries can be moved to worker threads."},{"question":"Why is an async function unsuitable for db.transaction?","answer":"The documentation says transaction functions do not work with async functions: after the first await, the function returns control and the transaction ends before asynchronous code. Perform required asynchronous operations separately, then synchronous writes in a coordinated transaction."},{"question":"How can I test rollback and a backup?","answer":"The API describes rollback on an exception from the transaction function and db.backup returning a Promise. A possible test deliberately triggers an error in a related change, checks for no partial write, then opens the backup as a SQLite database and compares data. With SQLite errors, account for SQLite possibly having already rolled back the transaction."},{"question":"Does every SQLite task require a separate server database?","answer":"better-sqlite3 opens a SQLite file or :memory: inside Node.js. This can support a local application, test store, or small server scenario; the README separately warns about heavy concurrent writes and large result sets. Test the choice against your load model."}],"related":[],"sources":["https://github.com/WiseLibs/better-sqlite3","https://raw.githubusercontent.com/WiseLibs/better-sqlite3/HEAD/README.md","https://raw.githubusercontent.com/WiseLibs/better-sqlite3/HEAD/LICENSE","https://www.open-source-tools.com/","https://raw.githubusercontent.com/WiseLibs/better-sqlite3/HEAD/docs/api.md"]},"selectionCheckedAt":null,"applicationGuide":{"goal":"Embed SQLite in a Node.js application.","inputs":["A schema, test dataset, and queries.","A supported database or runtime."],"steps":["Define tables and prepare SQL queries for the selected scenario. The README demonstrates Database and prepare(...).get(...) with a bound parameter; use query parameters for your own inputs.","Connect synchronous queries and a transaction for a related write operation. db.transaction creates a synchronous function: normal completion commits, and an exception rolls back. Do not put async/await inside it; the API explicitly warns of premature transaction completion.","Check schema changes, indexes, and data recovery. The API describes db.backup as a Promise producing a SQLite backup file; a possible check opens the restored copy and compares reference queries. Successfully creating a file does not replace a recovery test."],"checks":["Query results match the reference data.","Check access permissions, backup recovery, and load before production use."]},"sources":["https://github.com/WiseLibs/better-sqlite3","https://raw.githubusercontent.com/WiseLibs/better-sqlite3/HEAD/README.md","https://raw.githubusercontent.com/WiseLibs/better-sqlite3/HEAD/LICENSE","https://www.open-source-tools.com/","https://raw.githubusercontent.com/WiseLibs/better-sqlite3/HEAD/docs/api.md"],"checkedAt":"2026-10-06","reviewScope":"The purpose, current repository license, and separate terms for code, services, and models have been reviewed. The product was not run, and no security audit was performed.","relatedIds":[],"dataVersion":"cbbe7123b47a5ae80983","type":"Database / data tool","kind":"tool","pricingNote":"Code and local use under MIT. Computing resources, self-hosting, and external services are paid for separately if used.","notes":null,"labeledSources":[{"url":"https://github.com/WiseLibs/better-sqlite3","label":"Official source"},{"url":"https://raw.githubusercontent.com/WiseLibs/better-sqlite3/HEAD/README.md","label":"Official source"},{"url":"https://raw.githubusercontent.com/WiseLibs/better-sqlite3/HEAD/LICENSE","label":"License"},{"url":"https://www.open-source-tools.com/","label":"Catalog / discovery source"},{"url":"https://raw.githubusercontent.com/WiseLibs/better-sqlite3/HEAD/docs/api.md","label":"Database, transaction, parameters, and backup"}],"licenseGuides":[{"id":"mit","title":"MIT — permissive license","scope":null,"summary":"You can use, modify, distribute, and sell the code, including in a closed-source commercial product. When sharing copies or substantial portions of the code, retain the license text and copyright notice. You do not need to open-source your entire project; the author provides no warranties.","url":"https://opensource.org/license/mit"}],"entryIds":[],"composition":null}