@mlagie/sql-connector 1.3.2 → 1.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mlagie/sql-connector",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.3",
|
|
4
4
|
"description": "Le module sql-connector permet de gérer les connexions à une base de données MySQL, de définir des schémas de tables, et d'interagir avec les données de manière simple et efficace.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const { getConnexion } = require("../db/connexion");
|
|
1
2
|
const formatObject = require("../utils/formatObject");
|
|
2
3
|
const generateCondition = require("../utils/generateCondition");
|
|
3
4
|
|
|
@@ -42,7 +43,7 @@ class ModelInstance {
|
|
|
42
43
|
async updateOne(model) {
|
|
43
44
|
const sql_request = `UPDATE ${this.name} SET ${generateCondition(formatObject(model), true)} WHERE ${generateCondition(formatObject(this.data[0] != undefined ? this.data[0] : this.data), false, this.schema)}`;
|
|
44
45
|
|
|
45
|
-
await
|
|
46
|
+
await getConnexion().promise().query(sql_request).catch((err) => {
|
|
46
47
|
error(`Error executing query: ${err}`);
|
|
47
48
|
throw err;
|
|
48
49
|
});
|
|
@@ -59,7 +60,7 @@ class ModelInstance {
|
|
|
59
60
|
const sql_request = `DELETE FROM ${this.name} WHERE ${generateCondition(formatObject(filter))}`;
|
|
60
61
|
|
|
61
62
|
return new Promise((resolve, reject) => {
|
|
62
|
-
|
|
63
|
+
getConnexion().promise().query(sql_request).then((rows) => {
|
|
63
64
|
|
|
64
65
|
if (rows[1] != undefined) return resolve(0);
|
|
65
66
|
|
|
@@ -80,7 +81,7 @@ class ModelInstance {
|
|
|
80
81
|
const sql_request = `DELETE FROM ${this.name} WHERE ${generateCondition(formatObject(this.data[0] != undefined ? this.data[0] : this.data))}`;
|
|
81
82
|
|
|
82
83
|
return new Promise((resolve, reject) => {
|
|
83
|
-
|
|
84
|
+
getConnexion().promise().query(sql_request).then((rows) => {
|
|
84
85
|
if (rows[1] != undefined) return resolve(0);
|
|
85
86
|
|
|
86
87
|
resolve(1);
|
|
@@ -99,7 +100,7 @@ class ModelInstance {
|
|
|
99
100
|
*/
|
|
100
101
|
async customRequest(custom) {
|
|
101
102
|
return new Promise(async (resolve, reject) => {
|
|
102
|
-
await
|
|
103
|
+
await getConnexion().promise().query(custom).then((rows) => {
|
|
103
104
|
if (rows.length == 0) return resolve(0);
|
|
104
105
|
|
|
105
106
|
resolve(new ModelInstance(this.name, Object.values(rows[0]), this.schema));
|