@storecraft/database-sql-base 1.0.9 → 1.0.10

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 (2) hide show
  1. package/package.json +2 -1
  2. package/src/utils.query.js +19 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storecraft/database-sql-base",
3
- "version": "1.0.9",
3
+ "version": "1.0.10",
4
4
  "description": "Official SQL Database driver for storecraft",
5
5
  "license": "MIT",
6
6
  "author": "Tomer Shalev (https://github.com/store-craft)",
@@ -33,6 +33,7 @@
33
33
  "database-sql-base:test:postgres": "node ./tests/runner.postgres-local.test.js",
34
34
  "database-sql-base:test:mysql": "node ./tests/runner.mysql-local.test.js",
35
35
  "test": "npm run database-sql-base:test:sqlite && npm run database-sql-base:test:postgres && npm run database-sql-base:test:mysql",
36
+ "sc-publish": "npm publish",
36
37
  "prepublishOnly": "npm version patch --force"
37
38
  },
38
39
  "dependencies": {
@@ -128,6 +128,21 @@ export const query_vql_to_eb = (eb, root, table_name) => {
128
128
  }
129
129
 
130
130
 
131
+ /**
132
+ *
133
+ * @param {[k: string, v: any]} kv
134
+ * @returns {[k: string, v: any]}
135
+ */
136
+ const transform_boolean_to_0_or_1 = (kv) => {
137
+ if(typeof kv[1] === 'boolean') {
138
+ return [
139
+ kv[0],
140
+ kv[1] ? 1 : 0
141
+ ]
142
+ }
143
+ return kv;
144
+ }
145
+
131
146
  /**
132
147
  * Convert an API Query into mongo dialect, also sanitize.
133
148
  *
@@ -145,15 +160,15 @@ export const query_to_eb = (eb, q={}, table_name) => {
145
160
 
146
161
  // compute index clauses
147
162
  if(q.startAt) {
148
- clauses.push(query_cursor_to_eb(eb, q.startAt, asc ? '>=' : '<='));
163
+ clauses.push(query_cursor_to_eb(eb, q.startAt, asc ? '>=' : '<=', transform_boolean_to_0_or_1));
149
164
  } else if(q.startAfter) {
150
- clauses.push(query_cursor_to_eb(eb, q.startAfter, asc ? '>' : '<'));
165
+ clauses.push(query_cursor_to_eb(eb, q.startAfter, asc ? '>' : '<', transform_boolean_to_0_or_1));
151
166
  }
152
167
 
153
168
  if(q.endAt) {
154
- clauses.push(query_cursor_to_eb(eb, q.endAt, asc ? '<=' : '>='));
169
+ clauses.push(query_cursor_to_eb(eb, q.endAt, asc ? '<=' : '>=', transform_boolean_to_0_or_1));
155
170
  } else if(q.endBefore) {
156
- clauses.push(query_cursor_to_eb(eb, q.endBefore, asc ? '<' : '>'));
171
+ clauses.push(query_cursor_to_eb(eb, q.endBefore, asc ? '<' : '>', transform_boolean_to_0_or_1));
157
172
  }
158
173
 
159
174
  // compute VQL clauses