@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 CHANGED
@@ -37,14 +37,15 @@ const app = new App(
37
37
  })
38
38
  )
39
39
  .withStorage(new NodeLocalStorage('storage'))
40
+ .init();
40
41
 
41
- await app.init();
42
- await migrateToLatest(app.db, false);
43
-
44
- const server = http.createServer(app.handler).listen(
42
+ await migrateToLatest(app.__show_me_everything.db, false);
43
+ await app.__show_me_everything.vector_store.createVectorIndex();
44
+
45
+ http.createServer(app.handler).listen(
45
46
  8000,
46
47
  () => {
47
- console.log(`Server is running on http://localhost:8000`);
48
+ app.print_banner('http://localhost:8000');
48
49
  }
49
50
  );
50
51
 
package/index.js CHANGED
@@ -18,6 +18,7 @@ import { impl as products } from './src/con.products.js';
18
18
  import { impl as shipping } from './src/con.shipping.js';
19
19
  import { impl as storefronts } from './src/con.storefronts.js';
20
20
  import { impl as tags } from './src/con.tags.js';
21
+ import { impl as chats } from './src/con.chats.js';
21
22
  import { impl as templates } from './src/con.templates.js';
22
23
  import { impl as search } from './src/con.search.js';
23
24
  import { Kysely, ParseJSONResultsPlugin } from 'kysely'
@@ -101,6 +102,7 @@ export class SQL {
101
102
  products: products(this),
102
103
  storefronts: storefronts(this),
103
104
  tags: tags(this),
105
+ chats: chats(this),
104
106
  shipping_methods: shipping(this),
105
107
  templates: templates(this),
106
108
  search: search(this),
@@ -8,7 +8,7 @@ import { CreateTableBuilder, Kysely } from 'kysely'
8
8
  * @template {string} B
9
9
  * @param {CreateTableBuilder<TB, B>} tb
10
10
  */
11
- const add_base_columns = tb => {
11
+ export const add_base_columns = tb => {
12
12
  return tb
13
13
  .addColumn('id', 'varchar(255)', (col) =>
14
14
  col.primaryKey()
@@ -26,7 +26,7 @@ const add_base_columns = tb => {
26
26
  * @param {Kysely<Database>} db
27
27
  * @param {keyof Database} table_name
28
28
  */
29
- const create_entity_to_value_table = (db, table_name) => {
29
+ export const create_entity_to_value_table = (db, table_name) => {
30
30
 
31
31
  return db.schema
32
32
  .createTable(table_name).ifNotExists()
@@ -45,7 +45,7 @@ const create_entity_to_value_table = (db, table_name) => {
45
45
  * @param {Kysely<Database>} db
46
46
  * @param {keyof Database} table_name
47
47
  */
48
- const create_safe_table = (db, table_name) => {
48
+ export const create_safe_table = (db, table_name) => {
49
49
  return db.schema.createTable(table_name).ifNotExists();
50
50
  }
51
51
 
@@ -54,7 +54,7 @@ const create_safe_table = (db, table_name) => {
54
54
  * @param {Kysely<Database>} db
55
55
  * @param {keyof Database} table_name
56
56
  */
57
- const drop_safe_table = (db, table_name) => {
57
+ export const drop_safe_table = (db, table_name) => {
58
58
  return db.schema.dropTable(table_name).ifExists().execute();
59
59
  }
60
60
 
@@ -64,7 +64,7 @@ const drop_safe_table = (db, table_name) => {
64
64
  * @param {boolean} [include_id=true]
65
65
  * @param {boolean} [include_handle=true]
66
66
  */
67
- const create_base_indexes = async (db, table_name, include_id=true, include_handle=true) => {
67
+ export const create_base_indexes = async (db, table_name, include_id=true, include_handle=true) => {
68
68
  if(include_id) {
69
69
  await db.schema.createIndex(`index_${table_name}_id_updated_at_asc`)
70
70
  .on(table_name)
@@ -95,7 +95,7 @@ const create_base_indexes = async (db, table_name, include_id=true, include_hand
95
95
  * 'products_to_collections' | 'products_to_discounts' |
96
96
  * 'products_to_variants' | 'storefronts_to_other' | 'products_to_related_products'>} table_name
97
97
  */
98
- const create_entity_table_indexes = async (db, table_name) => {
98
+ export const create_entity_table_indexes = async (db, table_name) => {
99
99
  await db.schema.createIndex(`index_${table_name}_entity_id`)
100
100
  .on(table_name)
101
101
  .column('entity_id')
@@ -123,7 +123,6 @@ const create_entity_table_indexes = async (db, table_name) => {
123
123
  * @param {Kysely<Database>} db
124
124
  */
125
125
  export async function up(db) {
126
- // await drop_tables(db);
127
126
 
128
127
  { // auth_users
129
128
  let tb = create_safe_table(db, 'auth_users');
@@ -273,7 +272,7 @@ export async function up(db) {
273
272
  }
274
273
 
275
274
  { // storefronts_to_other
276
- let tb = create_entity_to_value_table(db, 'storefronts_to_other').execute();
275
+ await create_entity_to_value_table(db, 'storefronts_to_other').execute();
277
276
  await create_entity_table_indexes(db, 'storefronts_to_other');
278
277
  }
279
278
 
@@ -314,17 +313,17 @@ export async function up(db) {
314
313
  }
315
314
 
316
315
  { // entity_to_tags_projections
317
- let tb = create_entity_to_value_table(db, 'entity_to_tags_projections').execute();
316
+ await create_entity_to_value_table(db, 'entity_to_tags_projections').execute();
318
317
  await create_entity_table_indexes(db, 'entity_to_tags_projections');
319
318
  }
320
319
 
321
320
  { // entity_to_search_terms
322
- let tb = create_entity_to_value_table(db, 'entity_to_search_terms').execute();
321
+ await create_entity_to_value_table(db, 'entity_to_search_terms').execute();
323
322
  await create_entity_table_indexes(db, 'entity_to_search_terms');
324
323
  }
325
324
 
326
325
  { // entity_to_media
327
- let tb = create_entity_to_value_table(db, 'entity_to_media').execute();
326
+ await create_entity_to_value_table(db, 'entity_to_media').execute();
328
327
  await create_entity_table_indexes(db, 'entity_to_media');
329
328
  }
330
329
 
@@ -0,0 +1,30 @@
1
+ /**
2
+ * @import { Database } from '../types.sql.tables.js'
3
+ */
4
+ import { Kysely } from 'kysely'
5
+ import {
6
+ add_base_columns, create_base_indexes,
7
+ create_safe_table, drop_safe_table
8
+ } from './00000_init_tables.js';
9
+
10
+ /**
11
+ * @param {Kysely<Database>} db
12
+ */
13
+ export async function up(db) {
14
+
15
+ let tb = create_safe_table(db, 'chats');
16
+ tb = add_base_columns(tb);
17
+ tb = tb
18
+ .addColumn('customer_id', 'text')
19
+ .addColumn('customer_email', 'text')
20
+ .addColumn('extra', 'json')
21
+ await tb.execute();
22
+ await create_base_indexes(db, 'chats');
23
+ }
24
+
25
+ /**
26
+ * @param {Kysely<Database>} db
27
+ */
28
+ export async function down(db) {
29
+ await drop_safe_table(db, 'chats');
30
+ }
@@ -8,7 +8,7 @@ import { CreateTableBuilder, Kysely } from 'kysely'
8
8
  * @template {string} B
9
9
  * @param {CreateTableBuilder<TB, B>} tb
10
10
  */
11
- const add_base_columns = tb => {
11
+ export const add_base_columns = tb => {
12
12
  return tb
13
13
  .addColumn('id', 'text', (col) =>
14
14
  col.primaryKey()
@@ -25,7 +25,7 @@ const add_base_columns = tb => {
25
25
  * @param {Kysely<Database>} db
26
26
  * @param {keyof Database} table_name
27
27
  */
28
- const create_entity_to_value_table = (db, table_name) => {
28
+ export const create_entity_to_value_table = (db, table_name) => {
29
29
 
30
30
  return db.schema
31
31
  .createTable(table_name).ifNotExists()
@@ -44,7 +44,7 @@ const create_entity_to_value_table = (db, table_name) => {
44
44
  * @param {Kysely<Database>} db
45
45
  * @param {keyof Database} table_name
46
46
  */
47
- const create_safe_table = (db, table_name) => {
47
+ export const create_safe_table = (db, table_name) => {
48
48
  return db.schema.createTable(table_name).ifNotExists();
49
49
  }
50
50
 
@@ -53,7 +53,7 @@ const create_safe_table = (db, table_name) => {
53
53
  * @param {Kysely<Database>} db
54
54
  * @param {keyof Database} table_name
55
55
  */
56
- const drop_safe_table = (db, table_name) => {
56
+ export const drop_safe_table = (db, table_name) => {
57
57
  return db.schema.dropTable(table_name).ifExists().execute();
58
58
  }
59
59
 
@@ -63,7 +63,7 @@ const drop_safe_table = (db, table_name) => {
63
63
  * @param {boolean} [include_id=true]
64
64
  * @param {boolean} [include_handle=true]
65
65
  */
66
- const create_base_indexes = async (db, table_name, include_id=true, include_handle=true) => {
66
+ export const create_base_indexes = async (db, table_name, include_id=true, include_handle=true) => {
67
67
  if(include_id) {
68
68
  await db.schema.createIndex(`index_${table_name}_id_updated_at_asc`).ifNotExists()
69
69
  .on(table_name)
@@ -95,7 +95,7 @@ const create_base_indexes = async (db, table_name, include_id=true, include_hand
95
95
  * 'products_to_collections' | 'products_to_discounts' |
96
96
  * 'products_to_variants' | 'storefronts_to_other' | 'products_to_related_products'>} table_name
97
97
  */
98
- const create_entity_table_indexes = async (db, table_name) => {
98
+ export const create_entity_table_indexes = async (db, table_name) => {
99
99
  await db.schema.createIndex(`index_${table_name}_entity_id`).ifNotExists()
100
100
  .on(table_name)
101
101
  .column('entity_id')
@@ -272,7 +272,7 @@ export async function up(db) {
272
272
  }
273
273
 
274
274
  { // storefronts_to_other
275
- let tb = create_entity_to_value_table(db, 'storefronts_to_other').execute();
275
+ await create_entity_to_value_table(db, 'storefronts_to_other').execute();
276
276
  await create_entity_table_indexes(db, 'storefronts_to_other');
277
277
  }
278
278
 
@@ -313,17 +313,17 @@ export async function up(db) {
313
313
  }
314
314
 
315
315
  { // entity_to_tags_projections
316
- let tb = create_entity_to_value_table(db, 'entity_to_tags_projections').execute();
316
+ await create_entity_to_value_table(db, 'entity_to_tags_projections').execute();
317
317
  await create_entity_table_indexes(db, 'entity_to_tags_projections');
318
318
  }
319
319
 
320
320
  { // entity_to_search_terms
321
- let tb = create_entity_to_value_table(db, 'entity_to_search_terms').execute();
321
+ await create_entity_to_value_table(db, 'entity_to_search_terms').execute();
322
322
  await create_entity_table_indexes(db, 'entity_to_search_terms');
323
323
  }
324
324
 
325
325
  { // entity_to_media
326
- let tb = create_entity_to_value_table(db, 'entity_to_media').execute();
326
+ await create_entity_to_value_table(db, 'entity_to_media').execute();
327
327
  await create_entity_table_indexes(db, 'entity_to_media');
328
328
  }
329
329
 
@@ -0,0 +1,31 @@
1
+ /**
2
+ * @import { Database } from '../types.sql.tables.js'
3
+ */
4
+ import { Kysely } from 'kysely'
5
+ import {
6
+ add_base_columns, create_base_indexes,
7
+ create_safe_table, drop_safe_table
8
+ } from './00000_init_tables.js';
9
+
10
+ /**
11
+ * @param {Kysely<Database>} db
12
+ */
13
+ export async function up(db) {
14
+
15
+ let tb = create_safe_table(db, 'chats');
16
+ tb = add_base_columns(tb);
17
+ tb = tb
18
+ .addColumn('customer_id', 'text')
19
+ .addColumn('customer_email', 'text')
20
+ .addColumn('extra', 'json')
21
+ await tb.execute();
22
+ await create_base_indexes(db, 'chats');
23
+
24
+ }
25
+
26
+ /**
27
+ * @param {Kysely<Database>} db
28
+ */
29
+ export async function down(db) {
30
+ await drop_safe_table(db, 'chats');
31
+ }
@@ -8,7 +8,7 @@ import { CreateTableBuilder, Kysely } from 'kysely'
8
8
  * @template {string} B
9
9
  * @param {CreateTableBuilder<TB, B>} tb
10
10
  */
11
- const add_base_columns = tb => {
11
+ export const add_base_columns = tb => {
12
12
  return tb
13
13
  .addColumn('id', 'text', (col) =>
14
14
  col.primaryKey()
@@ -25,7 +25,7 @@ const add_base_columns = tb => {
25
25
  * @param {Kysely<Database>} db
26
26
  * @param {keyof Database} table_name
27
27
  */
28
- const create_entity_to_value_table = (db, table_name) => {
28
+ export const create_entity_to_value_table = (db, table_name) => {
29
29
  return db.schema
30
30
  .createTable(table_name).ifNotExists()
31
31
  .addColumn('id', 'integer',
@@ -43,7 +43,7 @@ const create_entity_to_value_table = (db, table_name) => {
43
43
  * @param {Kysely<Database>} db
44
44
  * @param {keyof Database} table_name
45
45
  */
46
- const create_safe_table = (db, table_name) => {
46
+ export const create_safe_table = (db, table_name) => {
47
47
  return db.schema.createTable(table_name).ifNotExists();
48
48
  }
49
49
 
@@ -51,7 +51,7 @@ const create_safe_table = (db, table_name) => {
51
51
  * @param {Kysely<Database>} db
52
52
  * @param {keyof Database} table_name
53
53
  */
54
- const drop_safe_table = (db, table_name) => {
54
+ export const drop_safe_table = (db, table_name) => {
55
55
  return db.schema.dropTable(table_name).ifExists().execute();
56
56
  }
57
57
 
@@ -61,7 +61,7 @@ const drop_safe_table = (db, table_name) => {
61
61
  * @param {boolean} [include_id=true]
62
62
  * @param {boolean} [include_handle=true]
63
63
  */
64
- const create_base_indexes = async (db, table_name, include_id=true, include_handle=true) => {
64
+ export const create_base_indexes = async (db, table_name, include_id=true, include_handle=true) => {
65
65
  if(include_id) {
66
66
  await db.schema.createIndex(`index_${table_name}_id_updated_at_asc`).ifNotExists()
67
67
  .on(table_name)
@@ -93,7 +93,7 @@ const create_base_indexes = async (db, table_name, include_id=true, include_hand
93
93
  * 'products_to_collections' | 'products_to_discounts' |
94
94
  * 'products_to_variants' | 'products_to_related_products' | 'storefronts_to_other'>} table_name
95
95
  */
96
- const create_entity_table_indexes = async (db, table_name) => {
96
+ export const create_entity_table_indexes = async (db, table_name) => {
97
97
  await db.schema.createIndex(`index_${table_name}_entity_id`).ifNotExists()
98
98
  .on(table_name)
99
99
  .column('entity_id')
@@ -0,0 +1,31 @@
1
+ /**
2
+ * @import { Database } from '../types.sql.tables.js'
3
+ */
4
+ import { Kysely } from 'kysely'
5
+ import {
6
+ add_base_columns, create_base_indexes,
7
+ create_safe_table, drop_safe_table
8
+ } from './00000_init_tables.js';
9
+
10
+ /**
11
+ * @param {Kysely<Database>} db
12
+ */
13
+ export async function up(db) {
14
+
15
+ let tb = create_safe_table(db, 'chats');
16
+ tb = add_base_columns(tb);
17
+ tb = tb
18
+ .addColumn('customer_id', 'text')
19
+ .addColumn('customer_email', 'text')
20
+ .addColumn('extra', 'json')
21
+ await tb.execute();
22
+ await create_base_indexes(db, 'chats');
23
+
24
+ }
25
+
26
+ /**
27
+ * @param {Kysely<Database>} db
28
+ */
29
+ export async function down(db) {
30
+ await drop_safe_table(db, 'chats');
31
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storecraft/database-sql-base",
3
- "version": "1.0.24",
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)",
@@ -33,8 +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",
37
- "prepublishOnly": "npm version patch --force"
36
+ "sc-publish": "npm publish"
38
37
  },
39
38
  "dependencies": {
40
39
  "@storecraft/core": "^1.0.0",
@@ -134,13 +134,6 @@ const list = (driver) => {
134
134
  with_media(eb, eb.ref('auth_users.id'), driver.dialectType),
135
135
  ]),
136
136
  query, table_name
137
- // .where(
138
- // (eb) => {
139
- // return query_to_eb(eb, query, table_name);
140
- // }
141
- // )
142
- // .orderBy(query_to_sort(query, 'auth_users'))
143
- // .limit(query.limitToLast ?? query.limit ?? 10)
144
137
  )
145
138
  .execute();
146
139
 
@@ -0,0 +1,151 @@
1
+ /**
2
+ * @import { db_chats as db_col } from '@storecraft/core/database'
3
+ */
4
+ import { SQL } from '../index.js'
5
+ import { report_document_media } from './con.images.js'
6
+ import {
7
+ count_regular,
8
+ delete_me, delete_media_of, delete_search_of, delete_tags_of,
9
+ insert_media_of, insert_search_of, insert_tags_of,
10
+ regular_upsert_me, where_id_or_handle_table,
11
+ with_media, with_search, with_tags
12
+ } from './con.shared.js'
13
+ import { sanitize, sanitize_array } from './utils.funcs.js'
14
+ import { withQuery } from './utils.query.js'
15
+
16
+ export const table_name = 'chats'
17
+
18
+ /**
19
+ * @param {SQL} driver
20
+ * @returns {db_col["upsert"]}
21
+ */
22
+ const upsert = (driver) => {
23
+ return async (item, search_terms) => {
24
+ const c = driver.client;
25
+ try {
26
+ const t = await c.transaction().execute(
27
+ async (trx) => {
28
+ await insert_search_of(trx, search_terms, item.id, item.handle, table_name);
29
+ await insert_media_of(trx, item.media, item.id, item.handle, table_name);
30
+ await insert_tags_of(trx, item.tags, item.id, item.handle, table_name);
31
+ await report_document_media(driver)(item, trx);
32
+ await regular_upsert_me(trx, table_name, {
33
+ active: item.active ? 1 : 0,
34
+ attributes: JSON.stringify(item.attributes),
35
+ description: item.description,
36
+ created_at: item.created_at,
37
+ updated_at: item.updated_at,
38
+ id: item.id,
39
+ handle: item.id,
40
+ customer_email: item.customer_email,
41
+ customer_id: item.customer_id,
42
+ extra: JSON.stringify(item.extra),
43
+ });
44
+ }
45
+ );
46
+ } catch(e) {
47
+ console.log(e);
48
+ return false;
49
+ }
50
+ return true;
51
+ }
52
+ }
53
+
54
+
55
+ /**
56
+ * @param {SQL} driver
57
+ * @returns {db_col["get"]}
58
+ */
59
+ const get = (driver) => {
60
+ return async (id_or_handle, options) => {
61
+ const result = await driver.client
62
+ .selectFrom(table_name)
63
+ .selectAll()
64
+ .select(
65
+ eb => [
66
+ with_media(eb, id_or_handle, driver.dialectType),
67
+ with_tags(eb, id_or_handle, driver.dialectType),
68
+ with_search(eb, id_or_handle, driver.dialectType),
69
+ ].filter(Boolean)
70
+ )
71
+ .where(where_id_or_handle_table(id_or_handle))
72
+ .executeTakeFirst();
73
+
74
+ return sanitize(result);
75
+ }
76
+ }
77
+
78
+
79
+ /**
80
+ * @param {SQL} driver
81
+ * @returns {db_col["remove"]}
82
+ */
83
+ const remove = (driver) => {
84
+ return async (id_or_handle) => {
85
+ try {
86
+ await driver.client.transaction().execute(
87
+ async (trx) => {
88
+
89
+ // entities
90
+ await delete_tags_of(trx, id_or_handle, id_or_handle, table_name);
91
+ await delete_search_of(trx, id_or_handle, id_or_handle, table_name);
92
+ await delete_media_of(trx, id_or_handle, id_or_handle, table_name);
93
+ // delete me
94
+ await delete_me(trx, table_name, id_or_handle);
95
+ }
96
+ );
97
+
98
+ } catch(e) {
99
+ console.log(e);
100
+ return false;
101
+ }
102
+ return true;
103
+ }
104
+ }
105
+
106
+
107
+ /**
108
+ * @param {SQL} driver
109
+ * @returns {db_col["list"]}
110
+ */
111
+ const list = (driver) => {
112
+ return async (query) => {
113
+
114
+ const items = await withQuery(
115
+ driver.client
116
+ .selectFrom(table_name)
117
+ .selectAll()
118
+ .select(
119
+ eb => [
120
+ with_media(eb, eb.ref('chats.id'), driver.dialectType),
121
+ with_tags(eb, eb.ref('chats.id'), driver.dialectType),
122
+ with_search(eb, eb.ref('chats.id'), driver.dialectType),
123
+ ].filter(Boolean)
124
+ ),
125
+ query, table_name
126
+ )
127
+ .execute();
128
+ // console.log({items})
129
+
130
+ if(query.limitToLast)
131
+ items.reverse();
132
+
133
+ return sanitize_array(items);
134
+ }
135
+ }
136
+
137
+
138
+ /**
139
+ * @param {SQL} driver
140
+ * @return {db_col}}
141
+ * */
142
+ export const impl = (driver) => {
143
+
144
+ return {
145
+ get: get(driver),
146
+ upsert: upsert(driver),
147
+ remove: remove(driver),
148
+ list: list(driver),
149
+ count: count_regular(driver, table_name),
150
+ }
151
+ }
@@ -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'
@@ -132,15 +136,6 @@ const list = (driver) => {
132
136
  query, table_name
133
137
  ).execute();
134
138
 
135
- // .where(
136
- // (eb) => {
137
- // return query_to_eb(eb, query, table_name);
138
- // }
139
- // )
140
- // .orderBy(query_to_sort(query, 'collections'))
141
- // .limit(query.limitToLast ?? query.limit ?? 10)
142
- // .execute();
143
-
144
139
  if(query.limitToLast) items.reverse();
145
140
 
146
141
  return sanitize_array(items);
@@ -154,6 +149,17 @@ const list = (driver) => {
154
149
  const list_collection_products = (driver) => {
155
150
  return async (handle_or_id, query={}) => {
156
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
+
157
163
  const items = await withSort(
158
164
  driver.client
159
165
  .selectFrom('products')
@@ -167,7 +173,27 @@ const list_collection_products = (driver) => {
167
173
  eb => [
168
174
  with_media(eb, eb.ref('products.id'), driver.dialectType),
169
175
  with_tags(eb, eb.ref('products.id'), driver.dialectType),
170
- ]
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)
171
197
  )
172
198
  .where(
173
199
  (eb) => eb.and(
@@ -185,11 +211,6 @@ const list_collection_products = (driver) => {
185
211
  .limit(query.limitToLast ?? query.limit ?? 10),
186
212
  query, 'products'
187
213
  ).execute()
188
- // .orderBy(query_to_sort(query, 'products'))
189
- // .execute();
190
-
191
- // .compile();
192
- // console.log(items[0])
193
214
 
194
215
  if(query.limitToLast)
195
216
  items.reverse();
@@ -140,16 +140,8 @@ const list = (driver) => {
140
140
  with_search(eb, eb.ref('customers.id'), driver.dialectType),
141
141
  ].filter(Boolean)),
142
142
  query, table_name
143
- ).execute();
143
+ ).execute();
144
144
 
145
- // .where(
146
- // (eb) => {
147
- // return query_to_eb(eb, query, table_name);
148
- // }
149
- // .orderBy(query_to_sort(query, table_name))
150
- // .limit(query.limitToLast ?? query.limit ?? 10)
151
- // .execute();
152
-
153
145
  if(query.limitToLast) items.reverse();
154
146
 
155
147
  return sanitize_array(items);
@@ -163,6 +155,8 @@ const list = (driver) => {
163
155
  const list_customer_orders = (driver) => {
164
156
  return async (id, query) => {
165
157
 
158
+ console.dir({ id, query }, { depth: 5 });
159
+
166
160
  const items = await withSort(
167
161
  driver.client
168
162
  .selectFrom('orders')
@@ -174,7 +168,7 @@ const list_customer_orders = (driver) => {
174
168
  .where(
175
169
  (eb) => eb.and(
176
170
  [
177
- query_to_eb(eb, query, table_name),
171
+ query_to_eb(eb, query, 'orders'),
178
172
  eb.or(
179
173
  [
180
174
  eb('_customer_id', '=', id),
@@ -187,8 +181,6 @@ const list_customer_orders = (driver) => {
187
181
  .limit(query.limitToLast ?? query.limit ?? 10),
188
182
  query, 'orders'
189
183
  ).execute();
190
- // .orderBy(query_to_sort(query, 'orders'))
191
- // .execute();
192
184
 
193
185
  if(query.limitToLast)
194
186
  items.reverse();