Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
sqlite-tables-handler
Advanced tools
Readme
A simple helper for SQLite tables development that makes fields re-definition a deadly simple operation.
import sqlite3 from 'sqlite3';
import sqliteHandler from 'sqlite-tables-handler';
const db = new sqlite3.Database(':memory:');
const whenTables = sqliteHandler(db, {
// tables as keys and fields definition
person: {
id: 'INTEGER NOT NULL PRIMARY KEY',
name: 'TEXT NOT NULL DEFAULT "anonymous"',
age: 'NUMBER',
// if we forgot something else we can change it later on
// age: 'NUMBER NOT NULL DEFAULT 0'
},
// fields can change during development
company: {
id: 'INTEGER NOT NULL PRIMARY KEY',
name: 'TEXT NOT NULL',
// if we forget the employee field we can add it later on
// employee: 'INTEGER NOT NULL'
}
});
whenTables.then(() => {
// ready to go
// ...
db.close();
});
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.
db
, an sqlite3.Database instanceobject
, an object with tables as keys, and fields as their valuesAny 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.
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.
import sqlite3 from 'sqlite3';
import sqliteHandler from 'sqlite-tables-handler';
import idPromise from 'id-promise';
const dbPath = './db.sqlite';
const db = new sqlite3.Database(dbPath);
const whenTables = idPromise(
'sqlite-tables-handler:' + dbPath,
(resolve, reject) => {
sqliteHandler(db, {
my_table: {
id: 'INTEGER NOT NULL PRIMARY KEY'
}
})
.then(resolve, reject);
}
);
whenTables.then(() => {
console.log('SQLite Ready');
// ...
});
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.
FAQs
A simple helper for SQLite tables development that makes fields re-definition a deadly simple operation.
The npm package sqlite-tables-handler receives a total of 83 weekly downloads. As such, sqlite-tables-handler popularity was classified as not popular.
We found that sqlite-tables-handler demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.