sqlite-express
Advanced tools
Comparing version 2.0.2 to 2.0.3
@@ -6,9 +6,6 @@ module.exports = (db, table, where) => { | ||
db.run(`DELETE FROM ${table} WHERE ${colCondition} = ?`, valueCondition, function (err) { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve({ deletedRows: this.changes }); | ||
} | ||
if (err) {reject(err);} | ||
else{resolve({ deletedRows: this.changes });} | ||
}); | ||
}); | ||
}; |
@@ -1,2 +0,3 @@ | ||
const signs = require('./signos'); | ||
const signs = require('./submodules/signos'); | ||
const is = require('./submodules/is'); | ||
module.exports = (db, table, data) => { | ||
@@ -7,8 +8,4 @@ return new Promise((resolve, reject) => { | ||
values.forEach((value, index) => { | ||
if (esObjeto(value)) { | ||
values[index] = JSON.stringify(value); | ||
} | ||
if (esBooleano(value)) { | ||
values[index] = value.toString(); | ||
} | ||
if (is.o(value)) {values[index] = JSON.stringify(value);} | ||
if (is.b(value)) {values[index] = value.toString();} | ||
}); | ||
@@ -25,10 +22,2 @@ | ||
}); | ||
function esObjeto(parametro) { | ||
return typeof parametro === 'object' && parametro !== null; | ||
} | ||
function esBooleano(parametro) { | ||
return typeof parametro === 'boolean'; | ||
} | ||
}; |
@@ -1,7 +0,7 @@ | ||
const signs = require('./signos'); | ||
const signs = require('./submodules/signos'); | ||
const is = require('./submodules/is'); | ||
module.exports = async (db, table, col, where) => { | ||
let whereString = ""; | ||
let signsString; | ||
let whereData; | ||
let signsString, whereData; | ||
@@ -12,3 +12,3 @@ if (where !== undefined) { | ||
if (Array.isArray(whereData)) { | ||
if (is.a(whereData)){ | ||
signsString = `IN (${signs(whereData.length)})`; | ||
@@ -23,7 +23,4 @@ whereString = `WHERE ${whereColumn} ${signsString}`; | ||
db.all(`SELECT ${col} FROM ${table} ${whereString}`, whereData, function(err, rows) { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(procecedRows(rows)); | ||
} | ||
if (err) {reject(err);} | ||
else {resolve(procecedRows(rows));} | ||
}); | ||
@@ -37,5 +34,3 @@ }); | ||
rows.forEach(row=>{ | ||
Object.keys(row).forEach(prop =>{if(esJSON(row[prop])){row[prop]=JSON.parse(row[prop])}}) | ||
}) | ||
rows.forEach(row=>{Object.keys(row).forEach(prop =>{if(is.j(row[prop])){row[prop]=JSON.parse(row[prop])}})}) | ||
@@ -46,13 +41,2 @@ if(oneColumn){rows = rows.map(row => row[Object.keys(row)[0]])}; | ||
} | ||
function esJSON(cadena) { | ||
if (typeof cadena !== 'string') { | ||
return false; | ||
} | ||
try { | ||
JSON.parse(cadena); | ||
} catch (error) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
}; | ||
}; |
const select = require('./select'); | ||
module.exports = async(db, table, update, where) => { | ||
const whereConstructor = require('./submodules/where'); | ||
const is = require('./submodules/is') | ||
module.exports = async(db, table, update, where, conect) => { | ||
let placeHolders = []; | ||
@@ -11,24 +12,15 @@ let upCols = Object.keys(update); | ||
upArray.push(`${upCol} = ?`); | ||
let dataInsert = update[upCol]; | ||
if(esFuncion(dataInsert)){ | ||
if(is.f(dataInsert)){ | ||
let originalData = await select(db, table, upCol, where); | ||
dataInsert = dataInsert(originalData); | ||
} | ||
if(esBooleano(dataInsert)){dataInsert = dataInsert.toString()}; | ||
if(esObjeto(dataInsert)){dataInsert = JSON.stringify(dataInsert)}; | ||
if(is.b(dataInsert)){dataInsert = dataInsert.toString()}; | ||
if(is.o(dataInsert)){dataInsert = JSON.stringify(dataInsert)}; | ||
placeHolders.push(dataInsert); | ||
} | ||
let whereCols = Object.keys(where); | ||
let whereArray =[]; | ||
whereCols.forEach(whereCol => { | ||
whereArray.push(`${whereCol} = ?`); | ||
placeHolders.push(where[whereCol]); | ||
}); | ||
db.run(`UPDATE ${table} SET ${upArray.join()} WHERE ${whereArray.join(' AND ')}`, placeHolders, function(err) { | ||
conect = conect === undefined ? 'AND' : conect; | ||
placeHolders = [...placeHolders, ...whereConstructor.placeHolders(where)]; | ||
db.run(`UPDATE ${table} SET ${upArray.join()} ${whereConstructor.query(where, conect)}`, placeHolders, function(err) { | ||
if (err) { | ||
@@ -40,5 +32,2 @@ console.error(err.message); | ||
}); | ||
function esFuncion(parametro) {return typeof parametro === 'function';}; | ||
function esObjeto(parametro) {return typeof parametro === 'object' && parametro !== null;}; | ||
function esBooleano(parametro) {return typeof parametro === 'boolean';}; | ||
}; | ||
}; |
{ | ||
"name": "sqlite-express", | ||
"version": "2.0.2", | ||
"version": "2.0.3", | ||
"description": "functions for sqlite3", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
sqliteExpress = require('./index'); | ||
const whereConstructor = require('./modules/submodules/where') | ||
@@ -7,8 +8,13 @@ const db = sqliteExpress.createDB('data.db'); | ||
//sqliteExpress.delete(db, 'personas', {nombre : 'x'});sqliteExpress.delete(db, 'personas', {nombre : 'y'}) | ||
let hola = async()=>{ | ||
console.log(await sqliteExpress.select(db, 'personas', 'ciudad', {nombre : 'gabriel'})) | ||
console.log(await sqliteExpress.select(db, 'personas', 'ciudad', {nombre : 'gabrie'})) | ||
} | ||
hola() | ||
//for(i=0;i<10;i++){sqliteExpress.insert(db, 'personas', {nombre : 'x', edad : i, ciudad : []});sqliteExpress.insert(db, 'personas', {nombre : 'y', edad : i, ciudad : []})} | ||
//sqliteExpress.update(db, 'personas', {ciudad : (x)=>{return [...x, 'santiago']}}, {edad : 5, nombre : 'y', AND : {ciudad : []}}, 'OR'); | ||
//PARECE QUE HACE FALTA UN MONTón | ||
sqliteExpress.update(db, 'personas', {ciudad : 'holis'}, {edad : 5}) |
Sorry, the diff of this file is not supported yet
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
22694
14