@storecraft/database-sql-base 1.0.23 → 1.2.5

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.23",
3
+ "version": "1.2.5",
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",
@@ -7,7 +7,7 @@ import {
7
7
  count_regular, delete_me, insert_search_of, insert_tags_of,
8
8
  regular_upsert_me, where_id_or_handle_table, with_media, with_tags
9
9
  } from './con.shared.js'
10
- import { query_to_eb, query_to_sort } from './utils.query.js';
10
+ import { withQuery } from './utils.query.js';
11
11
  import { remove as remove_customer_and_auth_user } from './con.customers.js';
12
12
 
13
13
 
@@ -126,22 +126,19 @@ const removeByEmail = (driver) => {
126
126
  const list = (driver) => {
127
127
  return async (query) => {
128
128
 
129
- const items = await driver.client.selectFrom(table_name)
129
+ const items = await withQuery(
130
+ driver.client.selectFrom(table_name)
130
131
  .selectAll()
131
132
  .select(eb => [
132
133
  with_tags(eb, eb.ref('auth_users.id'), driver.dialectType),
133
134
  with_media(eb, eb.ref('auth_users.id'), driver.dialectType),
134
- ])
135
- .where(
136
- (eb) => {
137
- return query_to_eb(eb, query, table_name);
138
- }
139
- )
140
- .orderBy(query_to_sort(query, 'auth_users'))
141
- .limit(query.limitToLast ?? query.limit ?? 10)
142
- .execute();
135
+ ]),
136
+ query, table_name
137
+ )
138
+ .execute();
143
139
 
144
- if(query.limitToLast) items.reverse();
140
+ if(query.limitToLast)
141
+ items.reverse();
145
142
 
146
143
  return sanitize_array(items);
147
144
  }
@@ -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
+ }
@@ -13,7 +13,7 @@ import {
13
13
  with_search
14
14
  } from './con.shared.js'
15
15
  import { sanitize, sanitize_array } from './utils.funcs.js'
16
- import { query_to_eb, query_to_sort } from './utils.query.js'
16
+ import { query_to_eb, withQuery, withSort } from './utils.query.js'
17
17
 
18
18
  export const table_name = 'collections'
19
19
 
@@ -120,22 +120,17 @@ const remove = (driver) => {
120
120
  const list = (driver) => {
121
121
  return async (query) => {
122
122
 
123
- const items = await driver.client
123
+ const items = await withQuery(
124
+ driver.client
124
125
  .selectFrom(table_name)
125
126
  .selectAll()
126
127
  .select(eb => [
127
128
  with_tags(eb, eb.ref('collections.id'), driver.dialectType),
128
129
  with_media(eb, eb.ref('collections.id'), driver.dialectType),
129
130
  with_search(eb, eb.ref('collections.id'), driver.dialectType),
130
- ])
131
- .where(
132
- (eb) => {
133
- return query_to_eb(eb, query, table_name);
134
- }
135
- )
136
- .orderBy(query_to_sort(query, 'collections'))
137
- .limit(query.limitToLast ?? query.limit ?? 10)
138
- .execute();
131
+ ]),
132
+ query, table_name
133
+ ).execute();
139
134
 
140
135
  if(query.limitToLast) items.reverse();
141
136
 
@@ -150,7 +145,8 @@ const list = (driver) => {
150
145
  const list_collection_products = (driver) => {
151
146
  return async (handle_or_id, query={}) => {
152
147
 
153
- const items = await driver.client
148
+ const items = await withSort(
149
+ driver.client
154
150
  .selectFrom('products')
155
151
  .innerJoin(
156
152
  'products_to_collections',
@@ -177,14 +173,12 @@ const list_collection_products = (driver) => {
177
173
  ].filter(Boolean)
178
174
  )
179
175
  )
180
- .orderBy(query_to_sort(query, 'products'))
181
- .limit(query.limitToLast ?? query.limit ?? 10)
182
- .execute();
183
-
184
- // .compile();
185
- // console.log(items[0])
176
+ .limit(query.limitToLast ?? query.limit ?? 10),
177
+ query, 'products'
178
+ ).execute()
186
179
 
187
- if(query.limitToLast) items.reverse();
180
+ if(query.limitToLast)
181
+ items.reverse();
188
182
 
189
183
  return sanitize_array(items);
190
184
  }