@storecraft/database-sql-base 1.0.21 → 1.0.22

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.
Files changed (3) hide show
  1. package/migrate.js +0 -35
  2. package/package.json +1 -1
  3. package/utils.js +33 -0
package/migrate.js CHANGED
@@ -107,38 +107,3 @@ export async function migrateToLatest(db_driver, release_db_upon_completion=true
107
107
  if(release_db_upon_completion)
108
108
  await db.destroy();
109
109
  }
110
-
111
-
112
- /**
113
- * @description Just for education and debugging, do not use !!!
114
- * @param {string} stmt
115
- * @param {any[] | Record<string, any>} params
116
- */
117
- export const prepare_and_bind = (stmt='', params=[]) => {
118
- const params_object = Array.isArray(params) ?
119
- params.reduce((a, v, idx) => ({ ...a, [idx+1]: v}), {}) :
120
- params;
121
-
122
- let current = 0;
123
- let result = ''
124
- let index_run = 1;
125
- for (let m of stmt.matchAll(/\?[0-9]*/g)) {
126
- result += stmt.slice(current, m.index);
127
-
128
- const match_string = m[0];
129
- let index_access = match_string.length > 1 ?
130
- Number(match_string.slice(1)) :
131
- index_run;
132
-
133
- result += "'" + params_object[index_access] + "'";
134
-
135
- current = m.index + m[0].length;
136
- index_run+=1;
137
- }
138
-
139
- result += stmt.slice(current);
140
-
141
- return result;
142
- }
143
-
144
-
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storecraft/database-sql-base",
3
- "version": "1.0.21",
3
+ "version": "1.0.22",
4
4
  "description": "Official SQL Database driver for storecraft",
5
5
  "license": "MIT",
6
6
  "author": "Tomer Shalev (https://github.com/store-craft)",
package/utils.js ADDED
@@ -0,0 +1,33 @@
1
+ /**
2
+ * @description Just for education and debugging, do not use !!!
3
+ * @param {string} stmt
4
+ * @param {any[] | Record<string, any>} params
5
+ */
6
+ export const prepare_and_bind = (stmt='', params=[]) => {
7
+ const params_object = Array.isArray(params) ?
8
+ params.reduce((a, v, idx) => ({ ...a, [idx+1]: v}), {}) :
9
+ params;
10
+
11
+ let current = 0;
12
+ let result = ''
13
+ let index_run = 1;
14
+ for (let m of stmt.matchAll(/\?[0-9]*/g)) {
15
+ result += stmt.slice(current, m.index);
16
+
17
+ const match_string = m[0];
18
+ let index_access = match_string.length > 1 ?
19
+ Number(match_string.slice(1)) :
20
+ index_run;
21
+
22
+ result += "'" + params_object[index_access] + "'";
23
+
24
+ current = m.index + m[0].length;
25
+ index_run+=1;
26
+ }
27
+
28
+ result += stmt.slice(current);
29
+
30
+ return result;
31
+ }
32
+
33
+