@storecraft/database-sql-base 1.0.24 → 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/README.md +6 -5
- package/index.js +2 -0
- package/migrations.mysql/00000_init_tables.js +10 -11
- package/migrations.mysql/00005_add_chats_table.js +30 -0
- package/migrations.postgres/00000_init_tables.js +10 -10
- package/migrations.postgres/00005_add_chats_table.js +31 -0
- package/migrations.sqlite/00000_init_tables.js +6 -6
- package/migrations.sqlite/00005_add_chats_table.js +31 -0
- package/package.json +2 -3
- package/src/con.auth_users.js +0 -7
- package/src/con.chats.js +151 -0
- package/src/con.collections.js +37 -16
- package/src/con.customers.js +4 -12
- package/src/con.discounts.js +47 -18
- package/src/con.images.js +0 -9
- package/src/con.notifications.js +0 -9
- package/src/con.orders.js +0 -9
- package/src/con.products.js +0 -16
- package/src/con.search.js +4 -2
- package/src/con.shared.experiment.js +719 -719
- package/src/con.shipping.js +2 -10
- package/src/con.storefronts.js +2 -11
- package/src/con.tags.js +0 -9
- package/tests/runner.mysql-local.test.js +5 -6
- package/tests/runner.postgres-local.test.js +5 -6
- package/tests/runner.sqlite-local.test.js +5 -6
- package/tests/sandbox.js +27 -27
- package/types.sql.tables.d.ts +7 -0
package/src/con.discounts.js
CHANGED
@@ -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'
|
@@ -72,16 +76,17 @@ const upsert = (driver) => {
|
|
72
76
|
.columns(['entity_handle', 'entity_id', 'value', 'reporter'])
|
73
77
|
.expression(eb =>
|
74
78
|
eb.selectFrom('products')
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
)
|
79
|
+
.select(
|
80
|
+
eb => [
|
81
|
+
'handle as entity_handle',
|
82
|
+
'id as entity_id',
|
83
|
+
eb.val(item.id).as('value'),
|
84
|
+
eb.val(item.handle).as('reporter')
|
85
|
+
]
|
86
|
+
)
|
87
|
+
.where(
|
88
|
+
eb => eb.and(discount_to_conjunctions(eb, item))
|
89
|
+
)
|
85
90
|
).execute();
|
86
91
|
|
87
92
|
for(const extra_search of extra_search_for_products) {
|
@@ -261,10 +266,6 @@ const list = (driver) => {
|
|
261
266
|
query, table_name
|
262
267
|
).execute();
|
263
268
|
|
264
|
-
// .orderBy(query_to_sort(query, table_name))
|
265
|
-
// .limit(query.limitToLast ?? query.limit ?? 10)
|
266
|
-
// .execute();
|
267
|
-
|
268
269
|
if(query.limitToLast)
|
269
270
|
items.reverse();
|
270
271
|
|
@@ -279,6 +280,17 @@ const list = (driver) => {
|
|
279
280
|
const list_discount_products = (driver) => {
|
280
281
|
return async (handle_or_id, query={}) => {
|
281
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
|
+
|
282
294
|
const items = await withSort(
|
283
295
|
driver.client
|
284
296
|
.selectFrom('products')
|
@@ -291,7 +303,27 @@ const list_discount_products = (driver) => {
|
|
291
303
|
.select(eb => [
|
292
304
|
with_media(eb, eb.ref('products.id'), driver.dialectType),
|
293
305
|
with_tags(eb, eb.ref('products.id'), driver.dialectType),
|
294
|
-
|
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))
|
295
327
|
.where(
|
296
328
|
(eb) => eb.and(
|
297
329
|
[
|
@@ -309,9 +341,6 @@ const list_discount_products = (driver) => {
|
|
309
341
|
query, 'products'
|
310
342
|
).execute();
|
311
343
|
|
312
|
-
// .orderBy(query_to_sort(query, 'products'))
|
313
|
-
// .execute();
|
314
|
-
|
315
344
|
if(query.limitToLast)
|
316
345
|
items.reverse();
|
317
346
|
|
package/src/con.images.js
CHANGED
@@ -203,15 +203,6 @@ const list = (driver) => {
|
|
203
203
|
query, table_name
|
204
204
|
).execute()
|
205
205
|
|
206
|
-
// .where(
|
207
|
-
// (eb) => {
|
208
|
-
// return query_to_eb(eb, query, table_name);
|
209
|
-
// }
|
210
|
-
// )
|
211
|
-
// .orderBy(query_to_sort(query, 'images')) // ts complains because `usage` field is absent
|
212
|
-
// .limit(query.limitToLast ?? query.limit ?? 10)
|
213
|
-
// .execute();
|
214
|
-
|
215
206
|
if(query.limitToLast)
|
216
207
|
items.reverse();
|
217
208
|
|
package/src/con.notifications.js
CHANGED
@@ -129,15 +129,6 @@ const list = (driver) => {
|
|
129
129
|
query, table_name
|
130
130
|
).execute();
|
131
131
|
|
132
|
-
// .where(
|
133
|
-
// (eb) => {
|
134
|
-
// return query_to_eb(eb, query, table_name);
|
135
|
-
// }
|
136
|
-
// )
|
137
|
-
// .orderBy(query_to_sort(query, 'notifications'))
|
138
|
-
// .limit(query.limitToLast ?? query.limit ?? 10)
|
139
|
-
// .execute();
|
140
|
-
|
141
132
|
if(query.limitToLast)
|
142
133
|
items.reverse();
|
143
134
|
|
package/src/con.orders.js
CHANGED
@@ -150,15 +150,6 @@ const list = (driver) => {
|
|
150
150
|
query, table_name
|
151
151
|
).execute();
|
152
152
|
|
153
|
-
// .where(
|
154
|
-
// (eb) => {
|
155
|
-
// return query_to_eb(eb, query, table_name);
|
156
|
-
// }
|
157
|
-
// )
|
158
|
-
// .orderBy(query_to_sort(query, table_name))
|
159
|
-
// .limit(query.limitToLast ?? query.limit ?? 10)
|
160
|
-
// .execute();
|
161
|
-
|
162
153
|
if(query.limitToLast)
|
163
154
|
items.reverse();
|
164
155
|
|
package/src/con.products.js
CHANGED
@@ -34,7 +34,6 @@ import {
|
|
34
34
|
export const table_name = 'products'
|
35
35
|
|
36
36
|
/**
|
37
|
-
*
|
38
37
|
* @param {db_col["$type_upsert"]} item
|
39
38
|
*/
|
40
39
|
const is_variant = item => {
|
@@ -54,8 +53,6 @@ const is_variant = item => {
|
|
54
53
|
|
55
54
|
/**
|
56
55
|
* @param {SQL} driver
|
57
|
-
*
|
58
|
-
*
|
59
56
|
* @returns {db_col["upsert"]}
|
60
57
|
*/
|
61
58
|
const upsert = (driver) => {
|
@@ -243,8 +240,6 @@ const get = (driver) => {
|
|
243
240
|
|
244
241
|
/**
|
245
242
|
* @param {SQL} driver
|
246
|
-
*
|
247
|
-
*
|
248
243
|
* @returns {db_col["getBulk"]}
|
249
244
|
*/
|
250
245
|
const getBulk = (driver) => {
|
@@ -375,8 +370,6 @@ const remove = (driver) => {
|
|
375
370
|
|
376
371
|
/**
|
377
372
|
* @param {SQL} driver
|
378
|
-
*
|
379
|
-
*
|
380
373
|
* @returns {db_col["list"]}
|
381
374
|
*/
|
382
375
|
const list = (driver) => {
|
@@ -424,15 +417,6 @@ const list = (driver) => {
|
|
424
417
|
query, table_name
|
425
418
|
).execute();
|
426
419
|
|
427
|
-
// .where(
|
428
|
-
// (eb) => {
|
429
|
-
// return query_to_eb(eb, query, table_name);
|
430
|
-
// }
|
431
|
-
// )
|
432
|
-
// .orderBy(query_to_sort(query, table_name))
|
433
|
-
// .limit(query.limitToLast ?? query.limit ?? 10)
|
434
|
-
// .execute();
|
435
|
-
|
436
420
|
if(query.limitToLast)
|
437
421
|
items.reverse();
|
438
422
|
|
package/src/con.search.js
CHANGED
@@ -22,7 +22,8 @@ const tables = [
|
|
22
22
|
'notifications',
|
23
23
|
'discounts',
|
24
24
|
'orders',
|
25
|
-
'templates'
|
25
|
+
'templates',
|
26
|
+
'chats'
|
26
27
|
]
|
27
28
|
|
28
29
|
/**
|
@@ -42,7 +43,7 @@ const prefix_to_resource = {
|
|
42
43
|
'tag': 'tags',
|
43
44
|
'template': 'templates',
|
44
45
|
'post': 'posts',
|
45
|
-
|
46
|
+
'chat': 'chats',
|
46
47
|
}
|
47
48
|
|
48
49
|
const resource_to_props = {
|
@@ -58,6 +59,7 @@ const resource_to_props = {
|
|
58
59
|
'tags': ['id', 'handle'],
|
59
60
|
'templates': ['id', 'handle', 'title'],
|
60
61
|
'posts': ['id', 'handle', 'title'],
|
62
|
+
'chats': ['id', 'customer_email', 'customer_id'],
|
61
63
|
}
|
62
64
|
|
63
65
|
/**
|