@mlagie/sql-connector 1.1.3-beta → 1.1.4-beta
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 +1 -1
- package/src/models/Model.js +23 -0
- package/src/utils/reservedKeywords.js +0 -24
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mlagie/sql-connector",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.4-beta",
|
|
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": {
|
package/src/models/Model.js
CHANGED
|
@@ -22,6 +22,29 @@ function generateValueSQL(value) {
|
|
|
22
22
|
}).join(", ");
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
const reservedKeywords = ['ADD', 'ALL', 'ALTER', 'AND', 'AS', 'ASC', 'BETWEEN', 'BY', 'CASE', 'CHECK', 'COLUMN', 'CONSTRAINT', 'CREATE', 'CURRENT_DATE', 'CURRENT_TIME', 'CURRENT_TIMESTAMP', 'DEFAULT', 'DELETE', 'DESC', 'DISTINCT', 'DROP', 'ELSE', 'END', 'ESCAPE', 'EXCEPT', 'EXISTS', 'FOR', 'FOREIGN', 'FROM', 'FULL', 'GROUP', 'HAVING', 'IN', 'INNER', 'INSERT', 'INTERSECT', 'INTO', 'IS', 'JOIN', 'LEFT', 'LIKE', 'LIMIT', 'NOT', 'NULL', 'ON', 'OR', 'ORDER', 'OUTER', 'PRIMARY', 'REFERENCES', 'RIGHT', 'SELECT', 'SET', 'SOME', 'TABLE', 'THEN', 'UNION', 'UNIQUE', 'UPDATE', 'VALUES', 'WHEN', 'WHERE'];
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Checks if a table name is a reserved keyword.
|
|
29
|
+
*
|
|
30
|
+
* @param {string} tableName Le nom de la table à vérifier.
|
|
31
|
+
* @returns {boolean} `true` si le nom de la table est un mot-clé réservé, sinon `false`.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* const isReserved = ifReservedKeywords('SELECT');
|
|
35
|
+
* console.log(isReserved); // true
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* const isReserved = ifReservedKeywords('myTable');
|
|
39
|
+
* console.log(isReserved); // false
|
|
40
|
+
*/
|
|
41
|
+
function ifReservedKeywords(tableName) {
|
|
42
|
+
if (reservedKeywords.includes(tableName.toUpperCase())) {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
|
|
25
48
|
/**
|
|
26
49
|
* Represents a database model.
|
|
27
50
|
* @class
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
const reservedKeywords = ['ADD', 'ALL', 'ALTER', 'AND', 'AS', 'ASC', 'BETWEEN', 'BY', 'CASE', 'CHECK', 'COLUMN', 'CONSTRAINT', 'CREATE', 'CURRENT_DATE', 'CURRENT_TIME', 'CURRENT_TIMESTAMP', 'DEFAULT', 'DELETE', 'DESC', 'DISTINCT', 'DROP', 'ELSE', 'END', 'ESCAPE', 'EXCEPT', 'EXISTS', 'FOR', 'FOREIGN', 'FROM', 'FULL', 'GROUP', 'HAVING', 'IN', 'INNER', 'INSERT', 'INTERSECT', 'INTO', 'IS', 'JOIN', 'LEFT', 'LIKE', 'LIMIT', 'NOT', 'NULL', 'ON', 'OR', 'ORDER', 'OUTER', 'PRIMARY', 'REFERENCES', 'RIGHT', 'SELECT', 'SET', 'SOME', 'TABLE', 'THEN', 'UNION', 'UNIQUE', 'UPDATE', 'VALUES', 'WHEN', 'WHERE'];
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Checks if a table name is a reserved keyword.
|
|
5
|
-
*
|
|
6
|
-
* @param {string} tableName Le nom de la table à vérifier.
|
|
7
|
-
* @returns {boolean} `true` si le nom de la table est un mot-clé réservé, sinon `false`.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* const isReserved = ifReservedKeywords('SELECT');
|
|
11
|
-
* console.log(isReserved); // true
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* const isReserved = ifReservedKeywords('myTable');
|
|
15
|
-
* console.log(isReserved); // false
|
|
16
|
-
*/
|
|
17
|
-
function ifReservedKeywords(tableName) {
|
|
18
|
-
if (reservedKeywords.includes(tableName.toUpperCase())) {
|
|
19
|
-
return true;
|
|
20
|
-
}
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
module.exports = { ifReservedKeywords }
|