-
-
Notifications
You must be signed in to change notification settings - Fork 168
SQLite
Roman edited this page Mar 20, 2025
·
8 revisions
It supports sqlite3
, better-sqlite3
and knex
. Set storeType option to make it work with better-sqlite3
or knex
.
const sqlite3 = require('sqlite3').verbose();
const { RateLimiterSQLite } = require('rate-limiter-flexible');
const db = new sqlite3.Database('./rate_limiter.sqlite')
const opts = {
storeClient: db,
tableName: 'rate_limiter_flexible',
points: 5, // Number of points
duration: 1, // Per second(s)
};
const rateLimiter = new RateLimiterSQLite(opts)
rateLimiter.consume(userEmail, 2)
.then((rateLimiterRes) => {
// 2 points consumed
})
.catch((rej) => {
// there are no more points to consume
});
Check rateLimiterRes object description.
SQLite requires a rate limiter table be created before the limiter instance can be used.
You can provide a callback as the second constructor parameter when creating a new instance: new RateLimiterMySQL(opts, ready)
. Once the table is created the ready
callback will be called.
Alternatively, you can create a table for rate limiter before limiter initialization, then set tableCreated
rate limiter option to true
.
Get started
Middlewares and plugins
Migration from other packages
Limiters:
- Valkey Glide
- IoValkey
- Redis
- Memory
- DynamoDB
- Prisma
- Etcd
- MongoDB (with sharding support)
- PostgreSQL
- MySQL
- SQLite
- BurstyRateLimiter
- Cluster
- PM2 Cluster
- Memcached
- RateLimiterUnion
- RateLimiterQueue
Wrappers:
- RLWrapperBlackAndWhite Black and White lists
Knowledge base:
- Block Strategy in memory
- Insurance Strategy
- Comparative benchmarks
- Smooth out traffic peaks
-
Usage example
- Minimal protection against password brute-force
- Login endpoint protection
- Websocket connection prevent flooding
- Dynamic block duration
- Different limits for authorized users
- Different limits for different parts of application
- Block Strategy in memory
- Insurance Strategy
- Third-party API, crawler, bot rate limiting