@storecraft/database-sql-base 1.0.20 → 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.
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.20",
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)",
@@ -0,0 +1,38 @@
1
+ -- database: ../../../playground/node-libsql/data.db
2
+
3
+ with table_list as (
4
+ select name, sql, type from sqlite_master
5
+ where
6
+ type in ('table', 'view')
7
+ and name not like 'sqlite_%'
8
+ order by name
9
+ )
10
+ select p.name from table_list as tl, pragma_table_info(tl.name) as p
11
+ order by tl.name, p.cid;
12
+
13
+
14
+ with table_list as (
15
+ select name, sql, type from sqlite_master
16
+ where
17
+ type in ('table', 'view')
18
+ and name not like 'sqlite_%'
19
+ order by name
20
+ )
21
+ select p.name, tl.name from table_list as tl, pragma_table_info(tl.name) as p
22
+ order by tl.name, p.cid;
23
+
24
+
25
+ select name from pragma_table_info('auth_users')
26
+ order by name;
27
+
28
+
29
+ with table_list as (
30
+ select name, sql, type from sqlite_master
31
+ where
32
+ type in ('table', 'view')
33
+ and name not like 'sqlite_%'
34
+ order by name
35
+ )
36
+ select p.name from pragma_table_info('auth_users') as p;
37
+
38
+
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
+