Registry / database / sqlite-tables-handler

sqlite-tables-handler

JSON →
library0.2.0jsnpmunverified

A library for SQLite table schema migration during development, allowing addition, removal, and type changes of columns automatically. Version 0.2.0. It provides a single function that takes an sqlite3 Database instance and a schema object, and ensures the tables match the definitions by using PRAGMA checks and automatic ALTER TABLE operations. Unlike ORMs, it focuses on rapid prototyping with minimal configuration, but does not support renaming columns. Ideal for iterative development where schema evolves frequently.

npm install sqlite-tables-handler
INSTALL
IMPORT
SIG · SQLITE-TABLES-HAND
S
sqlite-tables-handler
databasejavascriptv0.2.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default (sqliteHandler)
import sqliteHandler from 'sqlite-tables-handler';
const sqliteHandler = require('sqlite-tables-handler').default;
Package uses ESM default export; React/CommonJS users must use default import.
sqliteHandler (if using named export equiv)
import sqlite3 from 'sqlite3'; import sqliteHandler from 'sqlite-tables-handler';
import { sqliteHandler } from 'sqlite-tables-handler';
There is no named export; only default export exists.
type definitions (TypeScript)
import type { Schema, SqliteHandler } from 'sqlite-tables-handler';
TypeScript types are not provided; consider declaring module manually.

Creates SQLite tables from a schema object, runs a query, and logs results.

import sqlite3 from 'sqlite3'; import sqliteHandler from 'sqlite-tables-handler'; const db = new sqlite3.Database(':memory:'); const whenTables = sqliteHandler(db, { person: { id: 'INTEGER NOT NULL PRIMARY KEY', name: 'TEXT NOT NULL DEFAULT "anonymous"', age: 'NUMBER' }, company: { id: 'INTEGER NOT NULL PRIMARY KEY', name: 'TEXT NOT NULL' } }); whenTables.then(() => { db.serialize(() => { db.run('INSERT INTO person (name, age) VALUES (?, ?)', ['Alice', 30]); db.run('INSERT INTO company (name) VALUES (?)', ['Acme']); db.each('SELECT * FROM person', (err, row) => { if (!err) console.log(row); }); }); db.close(); });
Debug
Known issues
gotchaRenaming columns is not supported and will not be detected; attempt may cause data loss or unexpected behavior.
fix
Manually rename the column using SQLite ALTER TABLE, update the schema to reflect new name.
affects: >=0.0
gotchaConcurrent schema migrations across multiple processes/forks can cause race conditions and DB corruption.
fix
Use a locking mechanism like id-promise to ensure only one process migrates at a time (see README).
affects: >=0.0
breakingAll fields in schema must be provided; if schema is missing a column that exists in the table, the column is dropped.
fix
Ensure schema object includes all desired columns; to drop a column, simply remove it from the schema.
affects: >=0.0
gotchaSchema changes are destructive: dropping a column (removing from schema) will cause data loss in that column.
fix
Backup database before altering schema; the library does not warn before dropping columns.
affects: >=0.0
Errors
Common errors & fixes
TypeError: sqliteHandler is not a function
Using named import instead of default import.
fix
Use import sqliteHandler from 'sqlite-tables-handler';
Error: Cannot find module 'sqlite-tables-handler'
Package not installed.
fix
npm install sqlite-tables-handler
TypeError: db is not a Database object
Passing a wrong object as first argument.
fix
Pass an instance of sqlite3.Database: const db = new sqlite3.Database(':memory:');
Upgrade
Version history
0.2.0latest on npm
Audit
Dependencies
sqlite3requiredRequired to interact with SQLite database; the library expects an sqlite3 Database instance.
Agent activity
15 hits · last 30 days
node
10
Meta
1
Amazon
1
OpenAI (training)
1
Resources
sqlite-tables-handler — npm install sqlite-tables-handler · libregistry