@storecraft/database-sql-base 1.2.5 → 1.3.0

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": "@storecraft/database-sql-base",
3
- "version": "1.2.5",
3
+ "version": "1.3.0",
4
4
  "description": "Official SQL Database driver for storecraft",
5
5
  "license": "MIT",
6
6
  "author": "Tomer Shalev (https://github.com/store-craft)",
@@ -10,7 +10,11 @@ import {
10
10
  regular_upsert_me, where_id_or_handle_table,
11
11
  with_media, with_tags,
12
12
  count_regular,
13
- with_search
13
+ with_search,
14
+ products_with_collections,
15
+ products_with_discounts,
16
+ products_with_variants,
17
+ products_with_related_products
14
18
  } from './con.shared.js'
15
19
  import { sanitize, sanitize_array } from './utils.funcs.js'
16
20
  import { query_to_eb, withQuery, withSort } from './utils.query.js'
@@ -145,6 +149,17 @@ const list = (driver) => {
145
149
  const list_collection_products = (driver) => {
146
150
  return async (handle_or_id, query={}) => {
147
151
 
152
+ const expand = query.expand ?? ['*'];
153
+ const expand_collections = expand.includes('*') ||
154
+ expand.includes('collections');
155
+ const expand_discounts = expand.includes('*') ||
156
+ expand.includes('discounts');
157
+ // @ts-ignore
158
+ const expand_variants = expand.includes('*') ||
159
+ expand.includes('variants');
160
+ const expand_related_products = expand.includes('*') ||
161
+ expand.includes('related_products');
162
+
148
163
  const items = await withSort(
149
164
  driver.client
150
165
  .selectFrom('products')
@@ -158,7 +173,27 @@ const list_collection_products = (driver) => {
158
173
  eb => [
159
174
  with_media(eb, eb.ref('products.id'), driver.dialectType),
160
175
  with_tags(eb, eb.ref('products.id'), driver.dialectType),
161
- ]
176
+
177
+ expand_collections &&
178
+ products_with_collections(
179
+ eb, eb.ref('products.id'), driver.dialectType
180
+ ),
181
+
182
+ expand_discounts &&
183
+ products_with_discounts(
184
+ eb, eb.ref('products.id'), driver.dialectType
185
+ ),
186
+
187
+ expand_variants &&
188
+ products_with_variants(
189
+ eb, eb.ref('products.id'), driver.dialectType
190
+ ),
191
+
192
+ expand_related_products &&
193
+ products_with_related_products(
194
+ eb, eb.ref('products.id'), driver.dialectType
195
+ ),
196
+ ].filter(Boolean)
162
197
  )
163
198
  .where(
164
199
  (eb) => eb.and(
@@ -155,6 +155,8 @@ const list = (driver) => {
155
155
  const list_customer_orders = (driver) => {
156
156
  return async (id, query) => {
157
157
 
158
+ console.dir({ id, query }, { depth: 5 });
159
+
158
160
  const items = await withSort(
159
161
  driver.client
160
162
  .selectFrom('orders')
@@ -166,7 +168,7 @@ const list_customer_orders = (driver) => {
166
168
  .where(
167
169
  (eb) => eb.and(
168
170
  [
169
- query_to_eb(eb, query, table_name),
171
+ query_to_eb(eb, query, 'orders'),
170
172
  eb.or(
171
173
  [
172
174
  eb('_customer_id', '=', id),
@@ -14,6 +14,10 @@ import {
14
14
  delete_tags_of, insert_media_of, insert_search_of,
15
15
  insert_tags_of, regular_upsert_me, where_id_or_handle_table,
16
16
  with_media, with_tags, count_regular, with_search,
17
+ products_with_collections,
18
+ products_with_discounts,
19
+ products_with_variants,
20
+ products_with_related_products,
17
21
  } from './con.shared.js'
18
22
  import { sanitize, sanitize_array } from './utils.funcs.js'
19
23
  import { query_to_eb, withQuery, withSort } from './utils.query.js'
@@ -276,6 +280,17 @@ const list = (driver) => {
276
280
  const list_discount_products = (driver) => {
277
281
  return async (handle_or_id, query={}) => {
278
282
 
283
+ const expand = query.expand ?? ['*'];
284
+ const expand_collections = expand.includes('*') ||
285
+ expand.includes('collections');
286
+ const expand_discounts = expand.includes('*') ||
287
+ expand.includes('discounts');
288
+ // @ts-ignore
289
+ const expand_variants = expand.includes('*') ||
290
+ expand.includes('variants');
291
+ const expand_related_products = expand.includes('*') ||
292
+ expand.includes('related_products');
293
+
279
294
  const items = await withSort(
280
295
  driver.client
281
296
  .selectFrom('products')
@@ -288,7 +303,27 @@ const list_discount_products = (driver) => {
288
303
  .select(eb => [
289
304
  with_media(eb, eb.ref('products.id'), driver.dialectType),
290
305
  with_tags(eb, eb.ref('products.id'), driver.dialectType),
291
- ])
306
+
307
+ expand_collections &&
308
+ products_with_collections(
309
+ eb, eb.ref('products.id'), driver.dialectType
310
+ ),
311
+
312
+ expand_discounts &&
313
+ products_with_discounts(
314
+ eb, eb.ref('products.id'), driver.dialectType
315
+ ),
316
+
317
+ expand_variants &&
318
+ products_with_variants(
319
+ eb, eb.ref('products.id'), driver.dialectType
320
+ ),
321
+
322
+ expand_related_products &&
323
+ products_with_related_products(
324
+ eb, eb.ref('products.id'), driver.dialectType
325
+ ),
326
+ ].filter(Boolean))
292
327
  .where(
293
328
  (eb) => eb.and(
294
329
  [
@@ -240,8 +240,6 @@ const get = (driver) => {
240
240
 
241
241
  /**
242
242
  * @param {SQL} driver
243
- *
244
- *
245
243
  * @returns {db_col["getBulk"]}
246
244
  */
247
245
  const getBulk = (driver) => {
@@ -372,8 +370,6 @@ const remove = (driver) => {
372
370
 
373
371
  /**
374
372
  * @param {SQL} driver
375
- *
376
- *
377
373
  * @returns {db_col["list"]}
378
374
  */
379
375
  const list = (driver) => {