Installations
npm install @farjs/better-sqlite3-migrate
Developer Guide
Typescript
Yes
Module System
ESM
Min. Node Version
>=18
Node Version
20.18.0
NPM Version
10.8.2
Releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (98.41%)
TypeScript (1.59%)
validate.email 🚀
Verify real, reachable, and deliverable emails with instant MX records, SMTP checks, and disposable email detection.
Developer
farjs
Download Statistics
Total Downloads
790
Last Day
9
Last Week
35
Last Month
81
Last Year
790
GitHub Statistics
MIT License
14 Commits
1 Branches
1 Contributors
Updated on Mar 08, 2025
Bundle Size
736.00 B
Minified
307.00 B
Minified + Gzipped
Package Meta Information
Latest Version
2.0.0
Package Id
@farjs/better-sqlite3-migrate@2.0.0
Unpacked Size
12.53 kB
Size
4.56 kB
File Count
8
NPM Version
10.8.2
Node Version
20.18.0
Published on
Nov 03, 2024
Total Downloads
Cumulative downloads
Total Downloads
790
Last Day
350%
9
Compared to previous day
Last Week
169.2%
35
Compared to previous week
Last Month
-8%
81
Compared to previous month
Last Year
0%
790
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
1
Dev Dependencies
6
@farjs/better-sqlite3-migrate
Automates Sqlite DB schema versioning.
Uses wrapper around better-sqlite3 and bun:sqlite to allow cross- runtime/engine usage.
How to use it
1. Add SQL Migrations Scripts
Add your SQL
migrations scripts under dedicated project sub-folder, for ex. ./migrations
.
See example SQL migrations scripts:
2. Generate bundle.json
migrations file
To generate singe migrations bundle file you can use sql-bundle
script and run it as part of build process.
For example, in your package.json
:
1"scripts": { 2 "sql-bundle": "npx sql-bundle ./migrations" 3}
Then run it as follows:
1npm run sql-bundle
bundle.json
file will be (re)generated in the same ./migrations
folder.
3. Exclude bundle.json
file from git
Since it can be easily generated from the input SQL
migrations files there is no need to commit this file.
You can exclude it by adding the following line to your
.gitignore
file:
1migrations/bundle.json
4. Load and run migrations bundle
The final setup is to actually load and apply migrations on your Sqlite
DB during app startup:
1import Database from "@farjs/better-sqlite3-wrapper"; 2import { readBundle, runBundle } from "@farjs/better-sqlite3-migrate"; 3 4// connect to your DB 5const db = new Database(":memory:"); 6 7const bundleUrl = new URL("./migrations/bundle.json", import.meta.url); 8 9// load migrations bundle 10const bundle = await readBundle(bundleUrl); 11 12// apply it 13await runBundle(db, bundle);
This will create (or update existing) schema_versions
DB table with the all SQL migrations that were applied.
So, next time it will only apply new SQL migrations, that were not applied before (not exist in schema_versions
table yet).

No vulnerabilities found.

No security vulnerabilities found.