better-sqlite3

The fastest and simplest library for SQLite3 in Node.js.

What is better-sqlite3?

The fastest and simplest library for SQLite3 in Node.js.

Overview of better-sqlite3

What it is

better-sqlite3 is a Node.js library for SQLite3. It provides a synchronous API for interacting with SQLite databases, aiming for high performance and simplicity. The library supports full transactions, user-defined functions, aggregates, virtual tables, and extensions. It is designed to be faster and more efficient than asynchronous alternatives like node-sqlite3, particularly for CPU-bound or serialized database operations. Prebuilt binaries are available for major platforms and architectures, and it requires a currently supported Node.js version.

Key features

  • Full transaction support
  • High performance, efficiency, and safety
  • Easy-to-use synchronous API (the README claims better concurrency than an asynchronous API)
  • Support for user-defined functions, aggregates, virtual tables, and extensions
  • 64-bit integers (invisible until needed)
  • Worker thread support (for large/slow queries)

Use cases

better-sqlite3 is suitable for applications that need fast, synchronous SQLite access in Node.js. It is appropriate for most typical database workloads, such as reading and writing rows, performing joins, and using transactions. The README notes that it may not be appropriate for high-volume concurrent reads returning many megabytes of data (e.g., videos), high-volume concurrent writes (e.g., a social media site), or databases near the terabyte range. For such scenarios, a full-fledged RDBMS like PostgreSQL is recommended.

Getting started

bashnpm install better-sqlite3After installation, use the library as shown in the README:jsconst db = require('better-sqlite3')('foobar.db', options);const row = db.prepare('SELECT * FROM users WHERE id = ?').get(userId);console.log(row.firstName, row.lastName, row.email);It is generally recommended to set the WAL pragma for performance:jsdb.pragma('journal_mode = WAL');

License and pricing

The license is MIT. The project is open source and free to use. The README mentions that the project accepts support via GitHub sponsors, Patreon backers, and PayPal donations, but there is no stated pricing for the software itself.

Based on the project's public README and repository metadata.

Add this badge to your README

Featured on YunoDB Badge styles & help

Maintain this project? Show that it is featured on YunoDB.

Markdown[![Featured on YunoDB](https://yunodb.com/badge/wiselibsbetter-sqlite3.svg)](https://yunodb.com/tools/wiselibsbetter-sqlite3?utm_source=github&utm_medium=badge)
HTML<a href="https://yunodb.com/tools/wiselibsbetter-sqlite3?utm_source=github&utm_medium=badge"><img src="https://yunodb.com/badge/wiselibsbetter-sqlite3.svg" alt="Featured on YunoDB" height="20"></a>