db-delivery
Advanced tools
Comparing version 0.7.4 to 0.7.5
{ | ||
"name": "db-delivery", | ||
"version": "0.7.4", | ||
"version": "0.7.5", | ||
"description": "Micro node module for working with sqlite and mysql.", | ||
@@ -17,8 +17,9 @@ "main": "index.js", | ||
"dependencies": { | ||
"sqlite": "^4.0.14", | ||
"mysql": "^2.18.1", | ||
"sqlite": "^4.0.17", | ||
"sqlite3": "^5.0.0" | ||
}, | ||
"devDependencies": { | ||
"jest": "^26.4.2" | ||
"jest": "^26.6.3" | ||
} | ||
} |
@@ -18,3 +18,8 @@ class DB { | ||
// ToDo implement the mysql connection method | ||
createMysqlConnection(params) { } | ||
createMysqlConnection(options) { | ||
// console.log(options); | ||
let MysqlConnection = require('./mysql-conection'); | ||
return new MysqlConnection(options); | ||
} | ||
} | ||
@@ -21,0 +26,0 @@ |
@@ -28,2 +28,3 @@ class Query { | ||
values(vals) { | ||
if (!Array.isArray(vals)) throw new Error('Expected an Array object as a parameter not ' + typeof vals); | ||
this.query += `VALUES (`; | ||
@@ -39,2 +40,23 @@ vals.forEach(val => { | ||
update(table) { | ||
this.query = `UPDATE ${table} `; | ||
return this; | ||
} | ||
set(columns, values) { | ||
if (!Array.isArray(columns) || !Array.isArray(values)) { | ||
throw new Error(`Type error Expected two parameters of arrays found ${typeof columns} and ${typeof values}`); | ||
} | ||
this.query += 'SET '; | ||
for (let i = 0; i < columns.length; i++) { | ||
this.query += `${columns[i]}=?`; | ||
this.params.push(values[i]); | ||
if (i < columns.length - 1) { | ||
this.query += ', '; | ||
} | ||
this.query += ' '; | ||
} | ||
return this; | ||
} | ||
where(column, operator, criteria) { | ||
@@ -87,4 +109,12 @@ this.query += `WHERE ${column} ${operator.toUpperCase()} ? `; | ||
orderBy(column) { | ||
orderBy(column, type = null) { | ||
this.query += `ORDER BY ${column}`; | ||
switch (type) { | ||
case 'a': | ||
this.query += ` ASC`; | ||
break; | ||
case 'd': | ||
this.query += ` DESC`; | ||
break; | ||
} | ||
return this; | ||
@@ -91,0 +121,0 @@ } |
@@ -74,4 +74,16 @@ const fs = require('fs'); | ||
} | ||
updateRecord(sql, params) { | ||
return new Promise((resolve, reject) => { | ||
this.conn.run(sql, params, function (err) { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(this.changes); | ||
} | ||
}) | ||
}); | ||
} | ||
} | ||
module.exports = SqliteConnection; |
8323
247
3
+ Addedmysql@^2.18.1
+ Addedbignumber.js@9.0.0(transitive)
+ Addedcore-util-is@1.0.3(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedmysql@2.18.1(transitive)
+ Addedprocess-nextick-args@2.0.1(transitive)
+ Addedreadable-stream@2.3.7(transitive)
+ Addedsafe-buffer@5.1.2(transitive)
+ Addedsqlstring@2.3.1(transitive)
+ Addedstring_decoder@1.1.1(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedstring_decoder@1.3.0(transitive)
Updatedsqlite@^4.0.17