On this page

SQLite Store

The SQLite store provides persistent rate limit storage using a local SQLite database. Perfect for single-server deployments that need data to survive restarts.

Installation

The SQLite store requires better-sqlite3 as a peer dependency:

npm install better-sqlite3
# or: pnpm add better-sqlite3
# or: yarn add better-sqlite3

No installation needed! Bun includes bun:sqlite natively. There are no peer dependencies to install — just import and use.

Usage

import { hitlimit } from '@joint-ops/hitlimit'
import { sqliteStore } from '@joint-ops/hitlimit/stores/sqlite'

app.use(hitlimit({
  limit: 100,
  window: '1m',
  store: sqliteStore({
    path: './rate-limits.db'
  })
}))
import { hitlimit } from '@joint-ops/hitlimit-bun'
import { sqliteStore } from '@joint-ops/hitlimit-bun/stores/sqlite'

const limiter = hitlimit({
  limit: 100,
  window: '1m',
  store: sqliteStore({
    path: './rate-limits.db'
  })
})

Options

OptionTypeDefaultDescription
pathstring':memory:'Path to SQLite database file
tableNamestring'hitlimit'Name of the rate limit table
cleanupIntervalnumber60000Interval (ms) to clean expired entries

Full Configuration

sqliteStore({
  path: './data/rate-limits.db',
  tableName: 'api_limits',
  cleanupInterval: 300000  // Clean every 5 minutes
})
OptionTypeDefaultDescription
pathstring':memory:'Path to SQLite database file. Use ':memory:' for in-memory storage.

The Bun SQLite store keeps the API minimal — only the path option is exposed. Table creation, cleanup, and WAL mode are all handled internally.

Characteristics

  • Speed: Fast — local file I/O with WAL mode (~404K ops/sec)
  • Persistence: Data survives restarts
  • Scalability: Single server only
  • Dependencies: Requires better-sqlite3
  • Speed: 372K ops/sec (~2.7μs latency) — near-memory performance
  • Zero dependencies: Uses native bun:sqlite, no packages to install
  • WAL mode: Write-Ahead Logging enabled automatically for concurrent read/write performance
  • Synchronous operations: Uses isSync = true for maximum Bun performance

When to Use

  • Single-server production deployments
  • When rate limits must persist across restarts
  • Edge or embedded environments where Redis is not available
  • Serverless functions with persistent storage

Database Schema

The store automatically creates the following table:

CREATE TABLE IF NOT EXISTS hitlimit (
  key TEXT PRIMARY KEY,
  count INTEGER NOT NULL,
  reset_at INTEGER NOT NULL
)