UNPKG

machinomy

Version:

Micropayments powered by Ethereum

34 lines 1.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); function removeColumn(db, tableName, columnName, cb) { db.all(`PRAGMA table_info(${tableName});`, async (err, rows) => { if (err) { cb(err, null); } else { try { const sqlNamesWithTypes = rows.filter(row => row.name !== columnName) .map(row => `${row.name} ${row.type}`) .join(', '); const sqlNames = rows.filter(row => row.name !== columnName) .map(row => row.name) .join(', '); const removeColumnSql = ` CREATE TEMPORARY TABLE ${tableName + '_backup'}(${sqlNamesWithTypes}); INSERT INTO ${tableName + '_backup'} SELECT ${sqlNames} FROM ${tableName}; DROP TABLE ${tableName}; CREATE TABLE ${tableName}(${sqlNamesWithTypes}); INSERT INTO ${tableName} SELECT ${sqlNames} FROM ${tableName + '_backup'}; DROP TABLE ${tableName + '_backup'}; `; db.runSql(removeColumnSql); cb(null, null); } catch (e) { cb(e, null); } } }); } exports.default = removeColumn; //# sourceMappingURL=removeColumn.js.map