explaingit

wiselibs/better-sqlite3

7,196JavaScriptAudience · developerComplexity · 2/5LicenseSetup · easy

TLDR

A fast, synchronous Node.js library for reading and writing SQLite databases, no callbacks or promises, just plain code that runs step by step, up to 15x faster than competing packages.

Mindmap

mindmap
  root((better-sqlite3))
    What it does
      Synchronous SQLite API
      Up to 15x faster inserts
      No callbacks or promises
    Tech stack
      Node.js
      SQLite
      C++ bindings
    Use cases
      Local app storage
      Bulk data inserts
      Custom SQL functions
    Audience
      Backend developers
      Desktop app builders
    Setup
      npm install
      Enable WAL mode
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Store and query app data in a local SQLite file from a Node.js backend without dealing with async callbacks or promises.

USE CASE 2

Run high-speed bulk inserts inside transactions that outperform competing sqlite packages by up to 15x.

USE CASE 3

Create user-defined SQL functions and aggregates to extend SQLite with custom logic directly from JavaScript.

USE CASE 4

Use SQLite extensions and virtual tables within a Node.js application.

Tech stack

JavaScriptNode.jsSQLiteC++

Getting it running

Difficulty · easy Time to first run · 5min
Use freely for any purpose, including commercially, as long as you keep the MIT copyright notice.

In plain English

better-sqlite3 is a JavaScript library that lets Node.js programs read and write SQLite databases. SQLite is a small, self-contained database that stores all its data in a single file on disk, making it a popular choice for applications that do not need a separate database server. What sets this library apart is its synchronous API. Most database libraries for Node.js are asynchronous, meaning your code has to wait for callbacks or promises to complete before moving on. better-sqlite3 takes a different approach: database calls finish before the next line of code runs. This sounds counterintuitive, but for a database like SQLite that processes requests one at a time anyway, the synchronous approach removes overhead and actually results in faster, simpler code. Performance benchmarks included in the documentation show better-sqlite3 running up to 11 times faster than the competing sqlite and sqlite3 packages for simple row fetches, and over 15 times faster when inserting rows inside a transaction. The library supports full transactions, user-defined functions, aggregates, virtual tables, and SQLite extensions. Installation is a single npm command, and basic usage follows a prepare-then-run pattern: you prepare a SQL statement once and can execute it many times with different parameters. For most workloads, the README recommends enabling WAL mode (a SQLite setting that improves write performance) right after opening the database. The README is clear about the library's limits. It is not a good fit for applications with very high concurrency, large numbers of simultaneous writes, or databases approaching terabyte size. For those situations, a separate database server like PostgreSQL would be a better choice. Within its intended scope, the library is widely used and actively maintained under an MIT license.

Copy-paste prompts

Prompt 1
Using better-sqlite3, write a Node.js script that creates a SQLite database, inserts 10,000 rows in a single transaction, and queries the top 100 by a score column.
Prompt 2
Show me how to define a custom SQL function in better-sqlite3 that normalizes text to lowercase before storing it.
Prompt 3
I am building a local-first desktop app with Node.js. Help me set up better-sqlite3 with WAL mode enabled and write a simple migration script.
Prompt 4
Write a performance benchmark comparing better-sqlite3 and the sqlite3 package for bulk inserts in a Node.js script.
Prompt 5
How do I back a REST API with better-sqlite3, show me prepared statements, parameterized queries, and transaction patterns for safe concurrent reads.
Open on GitHub → Explain another repo

← wiselibs on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.