@storecraft/database-sql-base 1.0.11 → 1.0.12
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/index.js +23 -25
- package/migrations.mysql/00002_seed_email_templates.js +1 -0
- package/migrations.postgres/00002_seed_email_templates.js +1 -0
- package/migrations.shared/00002_seed_email_templates.js +27 -0
- package/migrations.sqlite/00002_seed_email_templates.js +1 -0
- package/package.json +1 -1
- package/src/con.auth_users.js +5 -5
- package/src/con.collections.js +3 -3
- package/src/con.customers.js +3 -3
- package/src/con.discounts.js +3 -3
- package/src/con.discounts.utils.js +22 -14
- package/src/con.images.js +7 -5
- package/src/con.notifications.js +3 -3
- package/src/con.orders.js +4 -3
- package/src/con.posts.js +4 -3
- package/src/con.products.js +8 -7
- package/src/con.search.js +9 -10
- package/src/con.shared.js +37 -36
- package/src/con.shipping.js +8 -8
- package/src/con.storefronts.js +3 -3
- package/src/con.tags.js +13 -4
- package/src/con.templates.js +16 -6
- package/src/kysely.sanitize.plugin.js +10 -8
- package/src/utils.funcs.js +5 -1
- package/src/utils.query.js +13 -10
- package/types.public.d.ts +2 -2
- package/migrations.mssql/00000_init_tables.js +0 -268
- package/migrations.shared/00001_seed_email_templates copy.js +0 -262
- package/tests/runner.mssql-local.test.js +0 -122
package/src/con.shared.js
CHANGED
@@ -1,4 +1,9 @@
|
|
1
|
-
|
1
|
+
/**
|
2
|
+
* @import { db_crud } from '@storecraft/core/database'
|
3
|
+
* @import { Database } from '../types.sql.tables.js'
|
4
|
+
* @import { ExpressionBuilder, InsertObject } from 'kysely'
|
5
|
+
* @import { SqlDialectType } from '../types.public.js'
|
6
|
+
*/
|
2
7
|
import { ExpressionWrapper, InsertQueryBuilder, Kysely, Transaction } from 'kysely'
|
3
8
|
import { jsonArrayFrom, stringArrayFrom } from './con.helpers.json.js'
|
4
9
|
import { SQL } from '../index.js';
|
@@ -43,7 +48,7 @@ export const safe_trx = (k) => {
|
|
43
48
|
* @param {SQL} driver
|
44
49
|
* @param {keyof Database} table_name
|
45
50
|
*
|
46
|
-
* @returns {
|
51
|
+
* @returns {db_crud["count"]}
|
47
52
|
*/
|
48
53
|
export const count_regular = (driver, table_name) => {
|
49
54
|
return async (query) => {
|
@@ -70,7 +75,7 @@ export const count_regular = (driver, table_name) => {
|
|
70
75
|
*/
|
71
76
|
export const where_id_or_handle_entity = (id_or_handle) => {
|
72
77
|
/**
|
73
|
-
* @param {
|
78
|
+
* @param {ExpressionBuilder<Database>} eb
|
74
79
|
*/
|
75
80
|
return (eb) => eb.or(
|
76
81
|
[
|
@@ -86,7 +91,7 @@ export const where_id_or_handle_entity = (id_or_handle) => {
|
|
86
91
|
*/
|
87
92
|
export const where_id_or_handle_table = (id_or_handle) => {
|
88
93
|
/**
|
89
|
-
* @param {
|
94
|
+
* @param {ExpressionBuilder<Database>} eb
|
90
95
|
*/
|
91
96
|
return (eb) => eb.or(
|
92
97
|
[
|
@@ -139,7 +144,7 @@ export const delete_entity_values_of_by_entity_id_or_handle =
|
|
139
144
|
(entity_table_name) => {
|
140
145
|
/**
|
141
146
|
*
|
142
|
-
* @param {Kysely<
|
147
|
+
* @param {Kysely<Database>} trx
|
143
148
|
* @param {string} entity_id delete by id
|
144
149
|
* @param {string} [entity_handle=entity_id] delete by handle
|
145
150
|
*/
|
@@ -262,17 +267,13 @@ export const delete_tags_of = delete_entity_values_of_by_entity_id_or_handle('en
|
|
262
267
|
export const delete_search_of = delete_entity_values_of_by_entity_id_or_handle('entity_to_search_terms');
|
263
268
|
export const delete_media_of = delete_entity_values_of_by_entity_id_or_handle('entity_to_media');
|
264
269
|
|
265
|
-
/**
|
266
|
-
* @typedef {import('../index.js').Database} Database
|
267
|
-
*/
|
268
|
-
|
269
270
|
|
270
271
|
/**
|
271
272
|
* @template {keyof Database} T
|
272
273
|
*
|
273
274
|
* @param {Kysely<Database>} trx
|
274
275
|
* @param {T} table_name
|
275
|
-
* @param {
|
276
|
+
* @param {InsertObject<Database, T> & {id: string, handle: string}} item values of the entity
|
276
277
|
*
|
277
278
|
*/
|
278
279
|
export const regular_upsert_me = async (trx, table_name, item) => {
|
@@ -308,9 +309,9 @@ export const delete_me = async (trx, table_name, id_or_handle) => {
|
|
308
309
|
|
309
310
|
/**
|
310
311
|
*
|
311
|
-
* @param {
|
312
|
+
* @param {ExpressionBuilder<Database>} eb
|
312
313
|
* @param {string | ExpressionWrapper<Database>} id_or_handle
|
313
|
-
* @param {
|
314
|
+
* @param {SqlDialectType} sql_type
|
314
315
|
*/
|
315
316
|
export const with_tags = (eb, id_or_handle, sql_type) => {
|
316
317
|
return stringArrayFrom(
|
@@ -322,9 +323,9 @@ export const with_tags = (eb, id_or_handle, sql_type) => {
|
|
322
323
|
|
323
324
|
/**
|
324
325
|
*
|
325
|
-
* @param {
|
326
|
+
* @param {ExpressionBuilder<Database>} eb
|
326
327
|
* @param {string | ExpressionWrapper<Database>} id_or_handle
|
327
|
-
* @param {
|
328
|
+
* @param {SqlDialectType} sql_type
|
328
329
|
*/
|
329
330
|
export const with_search = (eb, id_or_handle, sql_type) => {
|
330
331
|
return stringArrayFrom(
|
@@ -336,9 +337,9 @@ export const with_search = (eb, id_or_handle, sql_type) => {
|
|
336
337
|
|
337
338
|
/**
|
338
339
|
*
|
339
|
-
* @param {
|
340
|
+
* @param {ExpressionBuilder<Database>} eb
|
340
341
|
* @param {string | ExpressionWrapper<Database>} id_or_handle
|
341
|
-
* @param {
|
342
|
+
* @param {SqlDialectType} sql_type
|
342
343
|
*/
|
343
344
|
export const with_media = (eb, id_or_handle, sql_type) => {
|
344
345
|
return stringArrayFrom(
|
@@ -352,9 +353,9 @@ export const with_media = (eb, id_or_handle, sql_type) => {
|
|
352
353
|
/**
|
353
354
|
* select as json array collections of a product
|
354
355
|
*
|
355
|
-
* @param {
|
356
|
+
* @param {ExpressionBuilder<Database, 'products'>} eb
|
356
357
|
* @param {string | ExpressionWrapper<Database>} product_id_or_handle
|
357
|
-
* @param {
|
358
|
+
* @param {SqlDialectType} sql_type
|
358
359
|
*/
|
359
360
|
export const products_with_collections = (eb, product_id_or_handle, sql_type) => {
|
360
361
|
return jsonArrayFrom(
|
@@ -383,9 +384,9 @@ export const products_with_collections = (eb, product_id_or_handle, sql_type) =>
|
|
383
384
|
/**
|
384
385
|
* select as json array collections of a product
|
385
386
|
*
|
386
|
-
* @param {
|
387
|
+
* @param {ExpressionBuilder<Database, 'products'>} eb
|
387
388
|
* @param {string | ExpressionWrapper<Database>} product_id_or_handle
|
388
|
-
* @param {
|
389
|
+
* @param {SqlDialectType} sql_type
|
389
390
|
*/
|
390
391
|
export const products_with_discounts = (eb, product_id_or_handle, sql_type) => {
|
391
392
|
return jsonArrayFrom(
|
@@ -417,9 +418,9 @@ export const products_with_discounts = (eb, product_id_or_handle, sql_type) => {
|
|
417
418
|
/**
|
418
419
|
* select as json array collections of a product
|
419
420
|
*
|
420
|
-
* @param {
|
421
|
+
* @param {ExpressionBuilder<Database, 'products'>} eb
|
421
422
|
* @param {string | ExpressionWrapper<Database>} product_id_or_handle
|
422
|
-
* @param {
|
423
|
+
* @param {SqlDialectType} sql_type
|
423
424
|
*/
|
424
425
|
export const products_with_variants = (eb, product_id_or_handle, sql_type) => {
|
425
426
|
return jsonArrayFrom(
|
@@ -455,9 +456,9 @@ export const products_with_variants = (eb, product_id_or_handle, sql_type) => {
|
|
455
456
|
/**
|
456
457
|
* select as json array collections of a product
|
457
458
|
*
|
458
|
-
* @param {
|
459
|
+
* @param {ExpressionBuilder<Database, 'products'>} eb
|
459
460
|
* @param {string | ExpressionWrapper<Database>} product_id_or_handle
|
460
|
-
* @param {
|
461
|
+
* @param {SqlDialectType} sql_type
|
461
462
|
*/
|
462
463
|
export const products_with_related_products = (eb, product_id_or_handle, sql_type) => {
|
463
464
|
return jsonArrayFrom(
|
@@ -494,9 +495,9 @@ export const products_with_related_products = (eb, product_id_or_handle, sql_typ
|
|
494
495
|
/**
|
495
496
|
* select as json array collections of a product
|
496
497
|
*
|
497
|
-
* @param {
|
498
|
+
* @param {ExpressionBuilder<Database, 'storefronts'>} eb
|
498
499
|
* @param {string | ExpressionWrapper<Database>} sf_id_or_handle
|
499
|
-
* @param {
|
500
|
+
* @param {SqlDialectType} sql_type
|
500
501
|
*/
|
501
502
|
export const storefront_with_collections = (eb, sf_id_or_handle, sql_type) => {
|
502
503
|
return jsonArrayFrom(
|
@@ -525,9 +526,9 @@ export const storefront_with_collections = (eb, sf_id_or_handle, sql_type) => {
|
|
525
526
|
/**
|
526
527
|
* select as json array collections of a product
|
527
528
|
*
|
528
|
-
* @param {
|
529
|
+
* @param {ExpressionBuilder<Database>} eb
|
529
530
|
* @param {string | ExpressionWrapper<Database>} sf_id_or_handle
|
530
|
-
* @param {
|
531
|
+
* @param {SqlDialectType} sql_type
|
531
532
|
*/
|
532
533
|
export const storefront_with_products = (eb, sf_id_or_handle, sql_type) => {
|
533
534
|
return jsonArrayFrom(
|
@@ -563,9 +564,9 @@ export const storefront_with_products = (eb, sf_id_or_handle, sql_type) => {
|
|
563
564
|
/**
|
564
565
|
* select as json array collections of a product
|
565
566
|
*
|
566
|
-
* @param {
|
567
|
+
* @param {ExpressionBuilder<Database>} eb
|
567
568
|
* @param {string | ExpressionWrapper<Database>} sf_id_or_handle
|
568
|
-
* @param {
|
569
|
+
* @param {SqlDialectType} sql_type
|
569
570
|
*/
|
570
571
|
export const storefront_with_discounts = (eb, sf_id_or_handle, sql_type) => {
|
571
572
|
return jsonArrayFrom(
|
@@ -597,9 +598,9 @@ export const storefront_with_discounts = (eb, sf_id_or_handle, sql_type) => {
|
|
597
598
|
/**
|
598
599
|
* select as json array collections of a product
|
599
600
|
*
|
600
|
-
* @param {
|
601
|
+
* @param {ExpressionBuilder<Database>} eb
|
601
602
|
* @param {string | ExpressionWrapper<Database>} sf_id_or_handle
|
602
|
-
* @param {
|
603
|
+
* @param {SqlDialectType} sql_type
|
603
604
|
*/
|
604
605
|
export const storefront_with_posts = (eb, sf_id_or_handle, sql_type) => {
|
605
606
|
return jsonArrayFrom(
|
@@ -628,9 +629,9 @@ export const storefront_with_posts = (eb, sf_id_or_handle, sql_type) => {
|
|
628
629
|
/**
|
629
630
|
* select as json array collections of a product
|
630
631
|
*
|
631
|
-
* @param {
|
632
|
+
* @param {ExpressionBuilder<Database>} eb
|
632
633
|
* @param {string | ExpressionWrapper<Database>} sf_id_or_handle
|
633
|
-
* @param {
|
634
|
+
* @param {SqlDialectType} sql_type
|
634
635
|
*/
|
635
636
|
export const storefront_with_shipping = (eb, sf_id_or_handle, sql_type) => {
|
636
637
|
return jsonArrayFrom(
|
@@ -659,7 +660,7 @@ export const storefront_with_shipping = (eb, sf_id_or_handle, sql_type) => {
|
|
659
660
|
/**
|
660
661
|
* select all the entity values by entity id or handle
|
661
662
|
*
|
662
|
-
* @param {
|
663
|
+
* @param {ExpressionBuilder<Database>} eb
|
663
664
|
* @param {EntityTableKeys} entity_junction_table
|
664
665
|
* @param {string | ExpressionWrapper<Database>} entity_id_or_handle
|
665
666
|
*/
|
@@ -681,7 +682,7 @@ export const select_values_of_entity_by_entity_id_or_handle =
|
|
681
682
|
/**
|
682
683
|
* select the entity ids which are constrained by value or reporter
|
683
684
|
*
|
684
|
-
* @param {
|
685
|
+
* @param {ExpressionBuilder<Database>} eb
|
685
686
|
* @param {EntityTableKeys} entity_junction_table
|
686
687
|
* @param {string | ExpressionWrapper<Database>} value
|
687
688
|
* @param {string | ExpressionWrapper<Database>} [reporter]
|
package/src/con.shipping.js
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
/**
|
2
|
+
* @import { db_shipping as db_col } from '@storecraft/core/database'
|
3
|
+
*/
|
1
4
|
import { SQL } from '../index.js'
|
2
5
|
import { report_document_media } from './con.images.js'
|
3
6
|
import { count_regular, delete_entity_values_by_value_or_reporter,
|
@@ -8,9 +11,6 @@ import { count_regular, delete_entity_values_by_value_or_reporter,
|
|
8
11
|
import { sanitize, sanitize_array } from './utils.funcs.js'
|
9
12
|
import { query_to_eb, query_to_sort } from './utils.query.js'
|
10
13
|
|
11
|
-
/**
|
12
|
-
* @typedef {import('@storecraft/core/database').db_shipping} db_col
|
13
|
-
*/
|
14
14
|
export const table_name = 'shipping_methods'
|
15
15
|
|
16
16
|
/**
|
@@ -59,11 +59,11 @@ const get = (driver) => {
|
|
59
59
|
.selectFrom(table_name)
|
60
60
|
.selectAll()
|
61
61
|
.select(eb => [
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
62
|
+
with_media(eb, id_or_handle, driver.dialectType),
|
63
|
+
with_tags(eb, id_or_handle, driver.dialectType),
|
64
|
+
with_search(eb, id_or_handle, driver.dialectType),
|
65
|
+
].filter(Boolean)
|
66
|
+
)
|
67
67
|
.where(where_id_or_handle_table(id_or_handle))
|
68
68
|
.executeTakeFirst();
|
69
69
|
|
package/src/con.storefronts.js
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
/**
|
2
|
+
* @import { db_storefronts as db_col } from '@storecraft/core/database'
|
3
|
+
*/
|
1
4
|
import { SQL } from '../index.js'
|
2
5
|
import { report_document_media } from './con.images.js'
|
3
6
|
import { delete_entity_values_of_by_entity_id_or_handle,
|
@@ -13,9 +16,6 @@ import { delete_entity_values_of_by_entity_id_or_handle,
|
|
13
16
|
import { sanitize, sanitize_array } from './utils.funcs.js'
|
14
17
|
import { query_to_eb, query_to_sort } from './utils.query.js'
|
15
18
|
|
16
|
-
/**
|
17
|
-
* @typedef {import('@storecraft/core/database').db_storefronts} db_col
|
18
|
-
*/
|
19
19
|
export const table_name = 'storefronts'
|
20
20
|
|
21
21
|
/**
|
package/src/con.tags.js
CHANGED
@@ -1,12 +1,14 @@
|
|
1
|
+
/**
|
2
|
+
* @import { db_tags as db_col } from '@storecraft/core/database'
|
3
|
+
*/
|
1
4
|
import { SQL } from '../index.js'
|
2
5
|
import { count_regular, delete_me, delete_search_of, insert_search_of,
|
3
|
-
regular_upsert_me, where_id_or_handle_table
|
6
|
+
regular_upsert_me, where_id_or_handle_table,
|
7
|
+
with_media,
|
8
|
+
with_search} from './con.shared.js'
|
4
9
|
import { sanitize, sanitize_array } from './utils.funcs.js'
|
5
10
|
import { query_to_eb, query_to_sort } from './utils.query.js'
|
6
11
|
|
7
|
-
/**
|
8
|
-
* @typedef {import('@storecraft/core/database').db_tags} db_col
|
9
|
-
*/
|
10
12
|
export const table_name = 'tags'
|
11
13
|
|
12
14
|
/**
|
@@ -47,6 +49,10 @@ const get = (driver) => {
|
|
47
49
|
return driver.client
|
48
50
|
.selectFrom(table_name)
|
49
51
|
.selectAll()
|
52
|
+
.select(eb => [
|
53
|
+
with_search(eb, id_or_handle, driver.dialectType),
|
54
|
+
].filter(Boolean)
|
55
|
+
)
|
50
56
|
.where(where_id_or_handle_table(id_or_handle))
|
51
57
|
.executeTakeFirst()
|
52
58
|
.then(sanitize);
|
@@ -90,6 +96,9 @@ const list = (driver) => {
|
|
90
96
|
const items = await driver.client
|
91
97
|
.selectFrom(table_name)
|
92
98
|
.selectAll()
|
99
|
+
.select(eb => [
|
100
|
+
with_search(eb, eb.ref('tags.id'), driver.dialectType),
|
101
|
+
].filter(Boolean))
|
93
102
|
.where(
|
94
103
|
(eb) => {
|
95
104
|
return query_to_eb(eb, query, table_name);
|
package/src/con.templates.js
CHANGED
@@ -1,14 +1,16 @@
|
|
1
|
+
/**
|
2
|
+
* @import { db_templates as db_col } from '@storecraft/core/database'
|
3
|
+
* @import { Database } from '../types.sql.tables.js'
|
4
|
+
*/
|
1
5
|
import { Kysely } from 'kysely'
|
2
6
|
import { SQL } from '../index.js'
|
3
7
|
import { count_regular, delete_me, delete_search_of, insert_search_of,
|
4
|
-
regular_upsert_me, safe_trx, where_id_or_handle_table
|
8
|
+
regular_upsert_me, safe_trx, where_id_or_handle_table,
|
9
|
+
with_search} from './con.shared.js'
|
5
10
|
import { sanitize, sanitize_array } from './utils.funcs.js'
|
6
11
|
import { query_to_eb, query_to_sort } from './utils.query.js'
|
7
12
|
import { base64 } from '@storecraft/core/crypto';
|
8
13
|
|
9
|
-
/**
|
10
|
-
* @typedef {import('@storecraft/core/database').db_templates} db_col
|
11
|
-
*/
|
12
14
|
export const table_name = 'templates'
|
13
15
|
|
14
16
|
/**
|
@@ -25,8 +27,7 @@ const decode_if_base64 = val => {
|
|
25
27
|
}
|
26
28
|
|
27
29
|
/**
|
28
|
-
* @param {Kysely<
|
29
|
-
*
|
30
|
+
* @param {Kysely<Database>} client
|
30
31
|
*
|
31
32
|
* @returns {db_col["upsert"]}
|
32
33
|
*/
|
@@ -70,6 +71,10 @@ const get = (driver) => {
|
|
70
71
|
return driver.client
|
71
72
|
.selectFrom(table_name)
|
72
73
|
.selectAll()
|
74
|
+
.select(eb => [
|
75
|
+
with_search(eb, id_or_handle, driver.dialectType),
|
76
|
+
].filter(Boolean)
|
77
|
+
)
|
73
78
|
.where(where_id_or_handle_table(id_or_handle))
|
74
79
|
.executeTakeFirst()
|
75
80
|
.then(sanitize);
|
@@ -115,6 +120,11 @@ const list = (driver) => {
|
|
115
120
|
const items = await driver.client
|
116
121
|
.selectFrom(table_name)
|
117
122
|
.selectAll()
|
123
|
+
.select(
|
124
|
+
eb => [
|
125
|
+
with_search(eb, eb.ref('templates.id'), driver.dialectType),
|
126
|
+
].filter(Boolean)
|
127
|
+
)
|
118
128
|
.where(
|
119
129
|
(eb) => {
|
120
130
|
return query_to_eb(eb, query, table_name);
|
@@ -1,3 +1,9 @@
|
|
1
|
+
/**
|
2
|
+
* @import {
|
3
|
+
* KyselyPlugin, PluginTransformQueryArgs, RootOperationNode,
|
4
|
+
* PluginTransformResultArgs, QueryResult, UnknownRow
|
5
|
+
* } from 'kysely'
|
6
|
+
*/
|
1
7
|
import { sanitize } from './utils.funcs.js';
|
2
8
|
|
3
9
|
/**
|
@@ -6,20 +12,16 @@ import { sanitize } from './utils.funcs.js';
|
|
6
12
|
* - sanitize `undefined` and `null` values
|
7
13
|
* - `active` keys will be transformed to `boolean`
|
8
14
|
*
|
9
|
-
*
|
10
|
-
* @typedef {import('kysely').KyselyPlugin} KyselyPlugin
|
11
|
-
*
|
12
|
-
*
|
13
15
|
* @implements {KyselyPlugin}
|
14
16
|
*/
|
15
17
|
export class SanitizePlugin {
|
16
18
|
|
17
19
|
/**
|
18
20
|
*
|
19
|
-
* @param {
|
21
|
+
* @param {PluginTransformQueryArgs} args
|
20
22
|
*
|
21
23
|
*
|
22
|
-
* @returns {
|
24
|
+
* @returns {RootOperationNode}
|
23
25
|
*/
|
24
26
|
transformQuery(args) {
|
25
27
|
return args.node;
|
@@ -27,10 +29,10 @@ export class SanitizePlugin {
|
|
27
29
|
|
28
30
|
/**
|
29
31
|
*
|
30
|
-
* @param {
|
32
|
+
* @param {PluginTransformResultArgs} args
|
31
33
|
*
|
32
34
|
*
|
33
|
-
* @returns {Promise<
|
35
|
+
* @returns {Promise<QueryResult<UnknownRow>>}
|
34
36
|
*/
|
35
37
|
transformResult(args){
|
36
38
|
sanitize(args.result.rows);
|
package/src/utils.funcs.js
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
/**
|
2
|
+
* @import { ReplaceValuesOfKeys } from './utils.types.js'
|
3
|
+
*/
|
4
|
+
|
1
5
|
export const isDef = v => v!==undefined && v!==null;
|
2
6
|
export const isUndef = v => !isDef(v);
|
3
7
|
|
@@ -25,7 +29,7 @@ export const delete_keys = (...keys) => {
|
|
25
29
|
* Sanitize null/undefined valued keys
|
26
30
|
* @template T
|
27
31
|
* @param {T} o
|
28
|
-
* @return {
|
32
|
+
* @return {ReplaceValuesOfKeys<T, 'active' | 'confirmed_mail', boolean>}
|
29
33
|
*/
|
30
34
|
export const sanitize = o => {
|
31
35
|
for (const key in o) {
|
package/src/utils.query.js
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
/**
|
2
|
-
* @
|
2
|
+
* @import { ApiQuery, Cursor } from '@storecraft/core/api'
|
3
|
+
* @import { VQL } from '@storecraft/core/vql'
|
4
|
+
* @import { Database } from '../types.sql.tables.js'
|
5
|
+
* @import { ExpressionBuilder } from 'kysely'
|
3
6
|
*/
|
4
7
|
|
5
8
|
import { parse } from "@storecraft/core/vql";
|
@@ -12,8 +15,8 @@ import { parse } from "@storecraft/core/vql";
|
|
12
15
|
* 3. (a1, a2, a3) > (b1, b2, b3) ==> (a1 > b1) || (a1=b1 & a2>b2) || (a1=b1 & a2=b2 & a3>b3)
|
13
16
|
* 4. (a1, a2, a3) >= (b1, b2, b3) ==> (a1 > b1) || (a1=b1 & a2>b2) || (a1=b1 & a2=b2 & a3>=b3)
|
14
17
|
*
|
15
|
-
* @param {
|
16
|
-
* @param {
|
18
|
+
* @param {ExpressionBuilder<Database>} eb
|
19
|
+
* @param {Cursor} c
|
17
20
|
* @param {'>' | '>=' | '<' | '<='} relation
|
18
21
|
* @param {(x: [k: string, v: any]) => [k: string, v: any]} transformer Your chance to change key and value
|
19
22
|
*/
|
@@ -73,8 +76,8 @@ export const query_cursor_to_eb = (eb, c, relation, transformer=(x)=>x) => {
|
|
73
76
|
|
74
77
|
/**
|
75
78
|
* @template {keyof Database} T
|
76
|
-
* @param {
|
77
|
-
* @param {
|
79
|
+
* @param {ExpressionBuilder<Database>} eb
|
80
|
+
* @param {VQL.Node} node
|
78
81
|
* @param {T} table_name
|
79
82
|
*/
|
80
83
|
export const query_vql_node_to_eb = (eb, node, table_name) => {
|
@@ -120,8 +123,8 @@ export const query_vql_node_to_eb = (eb, node, table_name) => {
|
|
120
123
|
}
|
121
124
|
|
122
125
|
/**
|
123
|
-
* @param {
|
124
|
-
* @param {
|
126
|
+
* @param {ExpressionBuilder<Database>} eb
|
127
|
+
* @param {VQL.Node} root
|
125
128
|
* @param {keyof Database} table_name
|
126
129
|
*/
|
127
130
|
export const query_vql_to_eb = (eb, root, table_name) => {
|
@@ -149,8 +152,8 @@ const transform_boolean_to_0_or_1 = (kv) => {
|
|
149
152
|
*
|
150
153
|
* @template {any} [T=any]
|
151
154
|
*
|
152
|
-
* @param {
|
153
|
-
* @param {
|
155
|
+
* @param {ExpressionBuilder<Database>} eb
|
156
|
+
* @param {ApiQuery<T>} q
|
154
157
|
* @param {keyof Database} table_name
|
155
158
|
*
|
156
159
|
*/
|
@@ -202,7 +205,7 @@ const SIGN = {
|
|
202
205
|
* @template {Record<string, any>} [Type=Record<string, any>]
|
203
206
|
* @template {keyof Database} [Table=keyof Database]
|
204
207
|
*
|
205
|
-
* @param {
|
208
|
+
* @param {ApiQuery<Type>} q
|
206
209
|
* @param {Table} table
|
207
210
|
* @returns {DirectedOrderByStringReference<Database, Table, Database[Table]>[]}
|
208
211
|
*/
|
package/types.public.d.ts
CHANGED
@@ -7,7 +7,7 @@ export type SqlDialectType = 'SQLITE' | 'POSTGRES' | 'MYSQL';
|
|
7
7
|
/**
|
8
8
|
* The Storecraft SQL config
|
9
9
|
*/
|
10
|
-
export type Config = {
|
10
|
+
export type Config<DialectType extends Dialect = Dialect> = {
|
11
11
|
/**
|
12
12
|
* @description Database name
|
13
13
|
*
|
@@ -18,7 +18,7 @@ export type Config = {
|
|
18
18
|
/**
|
19
19
|
* @description The `Kysely` dialect
|
20
20
|
*/
|
21
|
-
dialect:
|
21
|
+
dialect: DialectType,
|
22
22
|
|
23
23
|
/**
|
24
24
|
* @description The type of the sql dialect `SQLITE`, `POSTGRES`, `MYSQL`
|