SQLite Tables Handler
A simple helper for SQLite tables development that makes fields re-definition a deadly simple operation.
;; const db = ':memory:';const whenTables = ; whenTables;
Too many times, during development, I forget some field, or I decide that the type isn't right, or something else.
With this super basic helper, that's not an issue anymore, as I can change types, add, or remove fields, as I go.
API
db
, an sqlite3.Database instanceobject
, an object with tables as keys, and fields as their values
Any more complex table/field operation can be performed a part, but behind the module, a PRAGMA
check is performed to be sure current fields are the same specified in the existent table, if any, and an automatic upgrade/migration is performed when that's not the case.
Please note renaming fields is not supported, as it'd be impossible to guess what's a new name value should be taken from, so for these operations, please alter manually the table and then update the literal object definition to use the same name.
About Clusters
If multiple forks try simulatenously to migrate one or more tables from one schema to another, disasters might happen.
To prevent such situation, I suggest the usage of id-promise.
;; ; const dbPath = './db.sqlite';const db = dbPath; const whenTables = ; whenTables;
Using id-promise
helper at least to be sure tables are ready will ensure no concurrent migrations should ever happen across forks.
See test/multi.js file as example.