sqlite-express
Advanced tools
Comparing version 2.0.15 to 2.0.16
const consoleQuery = require('./submodules/consoleQuery'); | ||
const is = require('./submodules/is') | ||
module.exports = (arg1, table, where) => { | ||
let db; | ||
if(is.db(arg1)){ | ||
db = arg1; | ||
}else{ | ||
({db, table, where} = arg1); | ||
} | ||
return new Promise((resolve, reject) => { | ||
let colCondition = Object.keys(where)[0]; | ||
let valueCondition = where[colCondition]; | ||
let finalQuery = `DELETE FROM ${table} WHERE ${colCondition} = ?`; | ||
consoleQuery(finalQuery, valueCondition) | ||
db.run(finalQuery, valueCondition, function (err) { | ||
if (err) {reject(err);} | ||
else{resolve({ deletedRows: this.changes });} | ||
}); | ||
const is = require('./submodules/is'); | ||
const whereConstructor = require('./submodules/where'); | ||
module.exports = (arg1, table, where, conector) => { | ||
let db; | ||
if(is.db(arg1)){ | ||
db = arg1; | ||
}else{ | ||
({db, table, where, conector='AND'} = arg1); | ||
} | ||
return new Promise((resolve, reject) => { | ||
let finalQuery = `DELETE FROM ${table} ${whereConstructor.query(where, conector)}`; | ||
let placeHolders = whereConstructor.placeHolders(where, conector); | ||
consoleQuery(finalQuery, placeHolders) | ||
db.run(finalQuery, placeHolders, function (err) { | ||
if (err) {reject(err);} | ||
else{resolve({ deletedRows: this.changes });} | ||
}); | ||
}; | ||
}); | ||
}; |
@@ -1,10 +0,35 @@ | ||
module.exports = (str, arr)=>{ | ||
const colors = { | ||
reset: '\x1b[0m', | ||
blue: '\x1b[34m', | ||
green: '\x1b[32m', | ||
magenta: '\x1b[35m', | ||
yellow: '\x1b[33m', | ||
red: '\x1b[31m', | ||
cyan: '\x1b[36m', | ||
white: '\x1b[37m', | ||
gray: '\x1b[90m', | ||
brightBlue: '\x1b[94m' | ||
}; | ||
module.exports = (str, arr = []) => { | ||
let index = 0; | ||
const newStr = str.replace(/\?/g, () => { | ||
let newStr = str.replace(/\?/g, () => { | ||
if (index < arr.length) { | ||
return arr[index++]; | ||
return arr[index++]; | ||
} | ||
return '?'; | ||
}); | ||
console.log(`the query generated is: ${newStr}`); | ||
} | ||
newStr = newStr | ||
.replace(/\bCREATE\b/gi, `${colors.cyan}CREATE${colors.reset}`) | ||
.replace(/\bSELECT\b/gi, `${colors.blue}SELECT${colors.reset}`) | ||
.replace(/\bDELETE\b/gi, `${colors.red}DELETE${colors.reset}`) | ||
.replace(/\bUPDATE\b/gi, `${colors.brightBlue}UPDATE${colors.reset}`) | ||
.replace(/\sWHERE\s/gi, `${colors.gray}\nWHERE\n\t${colors.reset}`) | ||
.replace(/\sCASE\s/gi, `${colors.green}\nCASE ${colors.reset}`) | ||
.replace(/\sWHEN\s/gi, `${colors.magenta}\n\tWHEN ${colors.reset}`) | ||
.replace(/\sELSE\s/gi, `${colors.yellow}\n\tELSE ${colors.reset}`) | ||
.replace(/\sEND\s/gi, `${colors.red}\nEND ${colors.reset}`); | ||
console.log(`the query generated is:\n${newStr}\n\n`); | ||
} |
@@ -1,2 +0,3 @@ | ||
const is = require('./submodules/is') | ||
const is = require('./submodules/is'); | ||
const consoleQuery = require('./submodules/consoleQuery'); | ||
module.exports = (arg1, name, columns) => { | ||
@@ -12,5 +13,5 @@ let db; | ||
let partCols = array.map(col => `${col[0]} ${col[1]}`); | ||
let string = partCols.join(','); | ||
let string = partCols.join(', '); | ||
let finalQuery = `CREATE TABLE IF NOT EXISTS ${name} (${string})`; | ||
console.log(`the query generated is: ${finalQuery}`); | ||
consoleQuery(finalQuery); | ||
db.run(finalQuery, function(err) { | ||
@@ -17,0 +18,0 @@ if (err) { |
@@ -25,7 +25,6 @@ const select = require('./select'); | ||
let originalData = await select(db, table, `ROWID, ${upCol}`, where, conector); | ||
console.log(originalData) | ||
arrCase.push('CASE'); | ||
let arrDataInsert = []; | ||
originalData.forEach(row=>{ | ||
arrCase.push(`WHEN ROWID = ${Object.keys(row)[0]} THEN ?`); | ||
arrCase.push(`WHEN ROWID = ${row[Object.keys(row)[0]]} THEN ?`); | ||
arrDataInsert.push(strngifyData(dataInsert(parseData(row[upCol])))); | ||
@@ -32,0 +31,0 @@ }) |
{ | ||
"name": "sqlite-express", | ||
"version": "2.0.15", | ||
"version": "2.0.16", | ||
"description": "functions for sqlite3", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22062
14
268