@storecraft/database-sql-base 1.0.9 → 1.0.11

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.0.9",
3
+ "version": "1.0.11",
4
4
  "description": "Official SQL Database driver for storecraft",
5
5
  "license": "MIT",
6
6
  "author": "Tomer Shalev (https://github.com/store-craft)",
@@ -33,6 +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",
36
37
  "prepublishOnly": "npm version patch --force"
37
38
  },
38
39
  "dependencies": {
@@ -1,9 +1,9 @@
1
1
  import { SQL } from '../index.js'
2
- import { sanitize_array } from './utils.funcs.js'
3
- import { count_regular, delete_me, insert_search_of, insert_tags_of, regular_upsert_me,
4
- where_id_or_handle_table,
5
- with_media,
6
- with_tags} from './con.shared.js'
2
+ import { sanitize, sanitize_array } from './utils.funcs.js'
3
+ import {
4
+ count_regular, delete_me, insert_search_of, insert_tags_of, regular_upsert_me,
5
+ where_id_or_handle_table, with_media, with_tags
6
+ } from './con.shared.js'
7
7
  import { query_to_eb, query_to_sort } from './utils.query.js';
8
8
 
9
9
  /**
@@ -60,7 +60,8 @@ const get = (driver) => {
60
60
  .selectFrom(table_name)
61
61
  .selectAll()
62
62
  .where(where_id_or_handle_table(id_or_email))
63
- .executeTakeFirst();
63
+ .executeTakeFirst()
64
+ .then(sanitize);
64
65
  }
65
66
  }
66
67
 
@@ -70,11 +71,12 @@ const get = (driver) => {
70
71
  * @returns {db_col["getByEmail"]}
71
72
  */
72
73
  const getByEmail = (driver) => {
73
- return (email) => {
74
+ return async (email) => {
74
75
  return driver.client
75
76
  .selectFrom('auth_users')
76
77
  .selectAll().where('email', '=', email)
77
- .executeTakeFirst();
78
+ .executeTakeFirst()
79
+ .then(sanitize);
78
80
  }
79
81
  }
80
82
 
@@ -134,13 +136,13 @@ const list = (driver) => {
134
136
  return query_to_eb(eb, query, table_name);
135
137
  }
136
138
  )
137
- .orderBy(query_to_sort(query))
139
+ .orderBy(query_to_sort(query, 'auth_users'))
138
140
  .limit(query.limitToLast ?? query.limit ?? 10)
139
141
  .execute();
140
142
 
141
143
  if(query.limitToLast) items.reverse();
142
144
 
143
- return items;
145
+ return sanitize_array(items);
144
146
  }
145
147
  }
146
148
 
@@ -6,8 +6,9 @@ import { delete_entity_values_by_value_or_reporter, delete_me,
6
6
  select_entity_ids_by_value_or_reporter,
7
7
  regular_upsert_me, where_id_or_handle_table,
8
8
  with_media, with_tags,
9
- count_regular} from './con.shared.js'
10
- import { sanitize_array } from './utils.funcs.js'
9
+ count_regular,
10
+ with_search} from './con.shared.js'
11
+ import { sanitize, sanitize_array } from './utils.funcs.js'
11
12
  import { query_to_eb, query_to_sort } from './utils.query.js'
12
13
 
13
14
 
@@ -61,17 +62,17 @@ const upsert = (driver) => {
61
62
  */
62
63
  const get = (driver) => {
63
64
  return (id_or_handle, options) => {
64
-
65
65
  return driver.client
66
66
  .selectFrom(table_name)
67
67
  .selectAll('collections')
68
68
  .select(eb => [
69
69
  with_tags(eb, eb.ref('collections.id'), driver.dialectType),
70
- with_media(eb, eb.ref('collections.id'), driver.dialectType)
70
+ with_media(eb, eb.ref('collections.id'), driver.dialectType),
71
+ with_search(eb, eb.ref('collections.id'), driver.dialectType)
71
72
  ])
72
73
  .where(where_id_or_handle_table(id_or_handle))
73
- // .compile()
74
- .executeTakeFirst();
74
+ .executeTakeFirst()
75
+ .then(sanitize);
75
76
  }
76
77
  }
77
78
 
@@ -124,13 +125,14 @@ const list = (driver) => {
124
125
  .select(eb => [
125
126
  with_tags(eb, eb.ref('collections.id'), driver.dialectType),
126
127
  with_media(eb, eb.ref('collections.id'), driver.dialectType),
128
+ with_search(eb, eb.ref('collections.id'), driver.dialectType),
127
129
  ])
128
130
  .where(
129
131
  (eb) => {
130
132
  return query_to_eb(eb, query, table_name);
131
133
  }
132
134
  )
133
- .orderBy(query_to_sort(query))
135
+ .orderBy(query_to_sort(query, 'collections'))
134
136
  .limit(query.limitToLast ?? query.limit ?? 10)
135
137
  .execute();
136
138
 
@@ -166,7 +168,7 @@ const list_collection_products = (driver) => {
166
168
  ].filter(Boolean)
167
169
  )
168
170
  )
169
- .orderBy(query_to_sort(query))
171
+ .orderBy(query_to_sort(query, 'products'))
170
172
  .limit(query.limitToLast ?? query.limit ?? 10)
171
173
  .execute();
172
174
 
@@ -3,8 +3,8 @@ import { report_document_media } from './con.images.js'
3
3
  import { count_regular, delete_me, delete_media_of, delete_search_of,
4
4
  delete_tags_of, insert_media_of, insert_search_of,
5
5
  insert_tags_of, regular_upsert_me, where_id_or_handle_table,
6
- with_media, with_tags} from './con.shared.js'
7
- import { sanitize_array } from './utils.funcs.js'
6
+ with_media, with_search, with_tags} from './con.shared.js'
7
+ import { sanitize, sanitize_array } from './utils.funcs.js'
8
8
  import { query_to_eb, query_to_sort } from './utils.query.js'
9
9
 
10
10
  /**
@@ -64,9 +64,11 @@ const get = (driver) => {
64
64
  .select(eb => [
65
65
  with_media(eb, id, driver.dialectType),
66
66
  with_tags(eb, id, driver.dialectType),
67
+ with_search(eb, id, driver.dialectType),
67
68
  ])
68
69
  .where(where_id_or_handle_table(id))
69
- .executeTakeFirst();
70
+ .executeTakeFirst()
71
+ .then(sanitize);
70
72
  }
71
73
  }
72
74
 
@@ -129,13 +131,14 @@ const list = (driver) => {
129
131
  .select(eb => [
130
132
  with_media(eb, eb.ref('customers.id'), driver.dialectType),
131
133
  with_tags(eb, eb.ref('customers.id'), driver.dialectType),
134
+ with_search(eb, eb.ref('customers.id'), driver.dialectType),
132
135
  ].filter(Boolean))
133
136
  .where(
134
137
  (eb) => {
135
138
  return query_to_eb(eb, query, table_name);
136
139
  }
137
140
  )
138
- .orderBy(query_to_sort(query))
141
+ .orderBy(query_to_sort(query, table_name))
139
142
  .limit(query.limitToLast ?? query.limit ?? 10)
140
143
  .execute();
141
144
 
@@ -174,7 +177,7 @@ const list_customer_orders = (driver) => {
174
177
  ].filter(Boolean)
175
178
  )
176
179
  )
177
- .orderBy(query_to_sort(query))
180
+ .orderBy(query_to_sort(query, 'orders'))
178
181
  .limit(query.limitToLast ?? query.limit ?? 10)
179
182
  .execute();
180
183
 
@@ -6,8 +6,9 @@ import { delete_entity_values_by_value_or_reporter,
6
6
  delete_tags_of, insert_media_of, insert_search_of,
7
7
  insert_tags_of, select_entity_ids_by_value_or_reporter, regular_upsert_me, where_id_or_handle_table,
8
8
  with_media, with_tags,
9
- count_regular} from './con.shared.js'
10
- import { sanitize_array } from './utils.funcs.js'
9
+ count_regular,
10
+ with_search} from './con.shared.js'
11
+ import { sanitize, sanitize_array } from './utils.funcs.js'
11
12
  import { query_to_eb, query_to_sort } from './utils.query.js'
12
13
  import { report_document_media } from './con.images.js'
13
14
 
@@ -37,6 +38,12 @@ const upsert = (driver) => {
37
38
  // remove all products relation to this discount
38
39
  await delete_entity_values_by_value_or_reporter('products_to_discounts')(
39
40
  trx, item.id, item.handle);
41
+
42
+ await delete_entity_values_by_value_or_reporter('entity_to_search_terms')(
43
+ trx, `discount:${item.id}`);
44
+ await delete_entity_values_by_value_or_reporter('entity_to_search_terms')(
45
+ trx, `discount:${item.handle}`);
46
+
40
47
  if(item.active && item.application.id===enums.DiscountApplicationEnum.Auto.id) {
41
48
  // make connections
42
49
  await trx
@@ -56,6 +63,37 @@ const upsert = (driver) => {
56
63
  )
57
64
  ).execute();
58
65
 
66
+ await trx
67
+ .insertInto('entity_to_search_terms')
68
+ .columns(['entity_handle', 'entity_id', 'value'])
69
+ .expression(eb =>
70
+ eb.selectFrom('products')
71
+ .select(eb => [
72
+ 'handle as entity_handle',
73
+ 'id as entity_id',
74
+ eb.val(`discount:${item.id}`).as('value'),
75
+ ]
76
+ )
77
+ .where(
78
+ eb => eb.and(discount_to_conjunctions(eb, item))
79
+ )
80
+ ).execute();
81
+
82
+ await trx
83
+ .insertInto('entity_to_search_terms')
84
+ .columns(['entity_handle', 'entity_id', 'value'])
85
+ .expression(eb =>
86
+ eb.selectFrom('products')
87
+ .select(eb => [
88
+ 'handle as entity_handle',
89
+ 'id as entity_id',
90
+ eb.val(`discount:${item.handle}`).as('value'),
91
+ ]
92
+ )
93
+ .where(
94
+ eb => eb.and(discount_to_conjunctions(eb, item))
95
+ )
96
+ ).execute();
59
97
  }
60
98
 
61
99
  ///
@@ -100,9 +138,11 @@ const get = (driver) => {
100
138
  .select(eb => [
101
139
  with_media(eb, id_or_handle, driver.dialectType),
102
140
  with_tags(eb, id_or_handle, driver.dialectType),
141
+ with_search(eb, id_or_handle, driver.dialectType),
103
142
  ].filter(Boolean))
104
143
  .where(where_id_or_handle_table(id_or_handle))
105
- .executeTakeFirst();
144
+ .executeTakeFirst()
145
+ .then(sanitize);
106
146
  }
107
147
  }
108
148
 
@@ -156,13 +196,14 @@ const list = (driver) => {
156
196
  .select(eb => [
157
197
  with_media(eb, eb.ref('discounts.id'), driver.dialectType),
158
198
  with_tags(eb, eb.ref('discounts.id'), driver.dialectType),
199
+ with_search(eb, eb.ref('discounts.id'), driver.dialectType),
159
200
  ].filter(Boolean))
160
201
  .where(
161
202
  (eb) => {
162
203
  return query_to_eb(eb, query, table_name);
163
204
  }
164
205
  )
165
- .orderBy(query_to_sort(query))
206
+ .orderBy(query_to_sort(query, table_name))
166
207
  .limit(query.limitToLast ?? query.limit ?? 10)
167
208
  .execute();
168
209
 
@@ -179,6 +220,10 @@ const list = (driver) => {
179
220
  const list_discount_products = (driver) => {
180
221
  return async (handle_or_id, query={}) => {
181
222
 
223
+ // TODO: try to rewrite this with JOIN to products_to_discounts ON products.id=entity_id
224
+ // TODO: and then filter by value==handle_or_id_of_discount
225
+ // TODO: I think it will be better and more memory efficient for the database
226
+ // TODO: becausee right now it loads all the eligible products ids in advance
182
227
  const items = await driver.client
183
228
  .selectFrom('products')
184
229
  .selectAll()
@@ -198,7 +243,7 @@ const list_discount_products = (driver) => {
198
243
  ].filter(Boolean)
199
244
  )
200
245
  )
201
- .orderBy(query_to_sort(query))
246
+ .orderBy(query_to_sort(query, 'products'))
202
247
  .limit(query.limitToLast ?? query.limit ?? 10)
203
248
  .execute();
204
249
 
@@ -66,8 +66,10 @@ export const discount_to_conjunctions = (eb, d) => {
66
66
  break;
67
67
  case enums.FilterMetaEnum.p_in_products.op:
68
68
  {
69
- /** @type {import("@storecraft/core/api").FilterValue_p_in_products} */
70
- const cast = Array.isArray(filter?.value) ? filter.value : [];
69
+
70
+ const cast = /** @type {import("@storecraft/core/api").FilterValue_p_in_products} */ (
71
+ Array.isArray(filter?.value) ? filter.value : []
72
+ );
71
73
 
72
74
  conjunctions.push(
73
75
  eb(
@@ -79,8 +81,10 @@ export const discount_to_conjunctions = (eb, d) => {
79
81
  break;
80
82
  case enums.FilterMetaEnum.p_not_in_products.op:
81
83
  {
82
- /** @type {import("@storecraft/core/api").FilterValue_p_not_in_products} */
83
- const cast = Array.isArray(filter?.value) ? filter.value : [];
84
+
85
+ const cast = /** @type {import("@storecraft/core/api").FilterValue_p_not_in_products} */ (
86
+ Array.isArray(filter?.value) ? filter.value : []
87
+ );
84
88
 
85
89
  conjunctions.push(
86
90
  eb(
@@ -92,8 +96,10 @@ export const discount_to_conjunctions = (eb, d) => {
92
96
  break;
93
97
  case enums.FilterMetaEnum.p_in_tags.op:
94
98
  {
95
- /** @type {import("@storecraft/core/api").FilterValue_p_in_tags} */
96
- const cast = Array.isArray(filter?.value) ? filter.value : [];
99
+
100
+ const cast = /** @type {import("@storecraft/core/api").FilterValue_p_in_tags} */(
101
+ Array.isArray(filter?.value) ? filter.value : []
102
+ );
97
103
 
98
104
  conjunctions.push(
99
105
  eb_in(
@@ -105,8 +111,9 @@ export const discount_to_conjunctions = (eb, d) => {
105
111
  break;
106
112
  case enums.FilterMetaEnum.p_not_in_tags.op:
107
113
  {
108
- /** @type {import("@storecraft/core/api").FilterValue_p_not_in_tags} */
109
- const cast = Array.isArray(filter?.value) ? filter.value : [];
114
+ const cast = /** @type {import("@storecraft/core/api").FilterValue_p_not_in_tags} */ (
115
+ Array.isArray(filter?.value) ? filter.value : []
116
+ );
110
117
 
111
118
  conjunctions.push(
112
119
  eb.not(
@@ -120,8 +127,9 @@ export const discount_to_conjunctions = (eb, d) => {
120
127
  break;
121
128
  case enums.FilterMetaEnum.p_in_collections.op:
122
129
  {
123
- /** @type {import("@storecraft/core/api").FilterValue_p_in_collections} */
124
- const cast = Array.isArray(filter?.value) ? filter.value : [];
130
+ const cast = /** @type {import("@storecraft/core/api").FilterValue_p_in_collections} */ (
131
+ Array.isArray(filter?.value) ? filter.value : []
132
+ );
125
133
 
126
134
  // PROBLEM: we only have ids, but use handles in the filters
127
135
  conjunctions.push(
@@ -134,8 +142,9 @@ export const discount_to_conjunctions = (eb, d) => {
134
142
  break;
135
143
  case enums.FilterMetaEnum.p_not_in_collections.op:
136
144
  {
137
- /** @type {import("@storecraft/core/api").FilterValue_p_not_in_collections} */
138
- const cast = Array.isArray(filter?.value) ? filter.value : [];
145
+ const cast = /** @type {import("@storecraft/core/api").FilterValue_p_not_in_collections} */ (
146
+ Array.isArray(filter?.value) ? filter.value : []
147
+ );
139
148
 
140
149
  conjunctions.push(
141
150
  eb.not(
@@ -149,12 +158,13 @@ export const discount_to_conjunctions = (eb, d) => {
149
158
  break;
150
159
  case enums.FilterMetaEnum.p_in_price_range.op:
151
160
  {
152
- /** @type {import("@storecraft/core/api").FilterValue_p_in_price_range} */
153
- const cast = {
154
- from: 0,
155
- to: Number.POSITIVE_INFINITY,
156
- ...(filter?.value ?? {}),
157
- };
161
+ const cast = /** @type {import("@storecraft/core/api").FilterValue_p_in_price_range} */ (
162
+ {
163
+ from: 0,
164
+ to: Number.POSITIVE_INFINITY,
165
+ ...(filter?.value ?? {}),
166
+ }
167
+ );
158
168
 
159
169
  const from = extract_abs_number(cast.from);
160
170
  const to = extract_abs_number(cast.to);
@@ -140,8 +140,8 @@ export function jsonArrayFrom(expr, sql_type) {
140
140
  return pg_jsonArrayFrom(expr);
141
141
  case 'MYSQL':
142
142
  return mysql_jsonArrayFrom(expr);
143
- case 'MSSQL':
144
- return mssql_jsonArrayFrom(expr);
143
+ // case 'MSSQL':
144
+ // return mssql_jsonArrayFrom(expr);
145
145
  default:
146
146
  throw new Error(`sql_type=${sql_type} NOT SUPPORTED !`);
147
147
  }
@@ -171,7 +171,6 @@ export function jsonArrayFrom(expr, sql_type) {
171
171
  * @template O
172
172
  * @param {import('./con.helpers.json.js').SelectQueryBuilderExpression<O>} expr
173
173
  * @param {import('../types.public.d.ts').SqlDialectType} sql_type
174
- * @returns {import('kysely').RawBuilder<import('kysely').Simplify<O>[]>}
175
174
  */
176
175
  export function stringArrayFrom(expr, sql_type) {
177
176
  switch(sql_type) {
@@ -181,13 +180,14 @@ export function stringArrayFrom(expr, sql_type) {
181
180
  return pg_stringArrayFrom(expr);
182
181
  case 'MYSQL':
183
182
  return mysql_stringArrayFrom(expr);
184
- case 'MSSQL':
185
- return mssql_stringArrayFrom(expr);
183
+ // case 'MSSQL':
184
+ // return mssql_stringArrayFrom(expr);
186
185
  default:
187
186
  throw new Error(`sql_type=${sql_type} NOT SUPPORTED !`);
188
187
  }
189
188
  }
190
189
 
190
+
191
191
  /**
192
192
  * ### Examples
193
193
  *
@@ -223,8 +223,8 @@ export function jsonObjectFrom(expr, sql_type) {
223
223
  return pg_jsonObjectFrom(expr);
224
224
  case 'MYSQL':
225
225
  return mysql_jsonObjectFrom(expr);
226
- case 'MSSQL':
227
- return mssql_jsonObjectFrom(expr);
226
+ // case 'MSSQL':
227
+ // return mssql_jsonObjectFrom(expr);
228
228
  default:
229
229
  throw new Error(`sql_type=${sql_type} NOT SUPPORTED !`);
230
230
  }
@@ -106,7 +106,7 @@ export function mysql_jsonArrayFrom(expr) {
106
106
  * ```
107
107
  * @template O
108
108
  * @param {import('./con.helpers.json.js').SelectQueryBuilderExpression<O>} expr
109
- * @returns {import('kysely').RawBuilder<import('kysely').Simplify<O>[]>}
109
+ * @returns {import('kysely').RawBuilder<string[]>}
110
110
  */
111
111
  export function mysql_stringArrayFrom(expr) {
112
112
  const arg = extract_first_selection(expr, 'agg');
@@ -51,7 +51,7 @@ import { extract_first_selection } from './con.helpers.json.js';
51
51
  * ```
52
52
  * @template O
53
53
  * @param {import('./con.helpers.json.js').SelectQueryBuilderExpression<O>} expr
54
- * @returns {import('kysely').RawBuilder<import('kysely').Simplify<O>[]>}
54
+ * @returns {import('kysely').RawBuilder<string[]>}
55
55
  */
56
56
  export function pg_stringArrayFrom(expr) {
57
57
  const arg = extract_first_selection(expr, 'agg');
@@ -114,7 +114,7 @@ export function sqlite_jsonArrayFrom(expr) {
114
114
  * ```
115
115
  * @template O
116
116
  * @param {import('./con.helpers.json.js').SelectQueryBuilderExpression<O>} expr
117
- * @returns {import('kysely').RawBuilder<import('kysely').Simplify<O>[]>}
117
+ * @returns {import('kysely').RawBuilder<string[]>}
118
118
  */
119
119
  export function sqlite_stringArrayFrom(expr) {
120
120
  const arg = extract_first_selection(expr, 'agg');
package/src/con.images.js CHANGED
@@ -3,7 +3,7 @@ import { SQL } from '../index.js'
3
3
  import { count_regular, delete_me, delete_search_of,
4
4
  insert_search_of, regular_upsert_me, where_id_or_handle_table
5
5
  } from './con.shared.js'
6
- import { sanitize_array } from './utils.funcs.js'
6
+ import { sanitize, sanitize_array } from './utils.funcs.js'
7
7
  import { query_to_eb, query_to_sort } from './utils.query.js'
8
8
  import { Transaction } from 'kysely'
9
9
  import { ID } from '@storecraft/core/api/utils.func.js'
@@ -58,7 +58,8 @@ const get = (driver) => {
58
58
  .selectFrom(table_name)
59
59
  .selectAll()
60
60
  .where(where_id_or_handle_table(id_or_handle))
61
- .executeTakeFirst();
61
+ .executeTakeFirst()
62
+ .then(sanitize);
62
63
  }
63
64
  }
64
65
 
@@ -193,7 +194,6 @@ export const report_document_media = (driver) => {
193
194
  */
194
195
  const list = (driver) => {
195
196
  return async (query) => {
196
-
197
197
  const items = await driver.client
198
198
  .selectFrom(table_name)
199
199
  .selectAll()
@@ -202,7 +202,7 @@ const list = (driver) => {
202
202
  return query_to_eb(eb, query, table_name);
203
203
  }
204
204
  )
205
- .orderBy(query_to_sort(query))
205
+ .orderBy(query_to_sort(query, 'images')) // ts complains because `usage` field is absent
206
206
  .limit(query.limitToLast ?? query.limit ?? 10)
207
207
  .execute();
208
208
 
@@ -25,6 +25,7 @@ const upsert = (driver) => {
25
25
  item.id, item.id, table_name
26
26
  );
27
27
  await regular_upsert_me(trx, table_name, {
28
+ handle: null,
28
29
  created_at: item.created_at,
29
30
  updated_at: item.updated_at,
30
31
  message: item.message,
@@ -121,7 +122,7 @@ const list = (driver) => {
121
122
  return query_to_eb(eb, query, table_name);
122
123
  }
123
124
  )
124
- .orderBy(query_to_sort(query))
125
+ .orderBy(query_to_sort(query, 'notifications'))
125
126
  .limit(query.limitToLast ?? query.limit ?? 10)
126
127
  .execute();
127
128
 
package/src/con.orders.js CHANGED
@@ -3,8 +3,8 @@ import { report_document_media } from './con.images.js'
3
3
  import { count_regular, delete_me, delete_media_of, delete_search_of,
4
4
  delete_tags_of, insert_media_of, insert_search_of,
5
5
  insert_tags_of, regular_upsert_me, where_id_or_handle_table,
6
- with_media, with_tags} from './con.shared.js'
7
- import { sanitize_array } from './utils.funcs.js'
6
+ with_media, with_search, with_tags} from './con.shared.js'
7
+ import { sanitize, sanitize_array } from './utils.funcs.js'
8
8
  import { query_to_eb, query_to_sort } from './utils.query.js'
9
9
 
10
10
  /**
@@ -82,10 +82,12 @@ const get = (driver) => {
82
82
  .select(eb => [
83
83
  with_media(eb, id_or_handle, driver.dialectType),
84
84
  with_tags(eb, id_or_handle, driver.dialectType),
85
+ with_search(eb, id_or_handle, driver.dialectType),
85
86
  ]
86
87
  .filter(Boolean))
87
88
  .where(where_id_or_handle_table(id_or_handle))
88
- .executeTakeFirst();
89
+ .executeTakeFirst()
90
+ .then(sanitize);
89
91
  }
90
92
  }
91
93
 
@@ -138,13 +140,14 @@ const list = (driver) => {
138
140
  .select(eb => [
139
141
  with_media(eb, eb.ref('orders.id'), driver.dialectType),
140
142
  with_tags(eb, eb.ref('orders.id'), driver.dialectType),
143
+ with_search(eb, eb.ref('orders.id'), driver.dialectType),
141
144
  ].filter(Boolean))
142
145
  .where(
143
146
  (eb) => {
144
147
  return query_to_eb(eb, query, table_name);
145
148
  }
146
149
  )
147
- .orderBy(query_to_sort(query))
150
+ .orderBy(query_to_sort(query, table_name))
148
151
  .limit(query.limitToLast ?? query.limit ?? 10)
149
152
  .execute();
150
153
 
package/src/con.posts.js CHANGED
@@ -1,11 +1,12 @@
1
1
  import { SQL } from '../index.js'
2
+ import { stringArrayFrom } from './con.helpers.json.js'
2
3
  import { report_document_media } from './con.images.js'
3
4
  import { count_regular, delete_entity_values_by_value_or_reporter,
4
5
  delete_me, delete_media_of, delete_search_of, delete_tags_of,
5
6
  insert_media_of, insert_search_of, insert_tags_of,
6
7
  regular_upsert_me, where_id_or_handle_table,
7
- with_media, with_tags} from './con.shared.js'
8
- import { sanitize_array } from './utils.funcs.js'
8
+ with_media, with_search, with_tags} from './con.shared.js'
9
+ import { sanitize, sanitize_array } from './utils.funcs.js'
9
10
  import { query_to_eb, query_to_sort } from './utils.query.js'
10
11
 
11
12
  /**
@@ -54,17 +55,20 @@ const upsert = (driver) => {
54
55
  * @returns {db_col["get"]}
55
56
  */
56
57
  const get = (driver) => {
57
- return (id_or_handle, options) => {
58
- return driver.client
59
- .selectFrom(table_name)
60
- .selectAll()
61
- .select(eb => [
62
- with_media(eb, id_or_handle, driver.dialectType),
63
- with_tags(eb, id_or_handle, driver.dialectType),
64
- ]
65
- .filter(Boolean))
66
- .where(where_id_or_handle_table(id_or_handle))
67
- .executeTakeFirst();
58
+ return async (id_or_handle, options) => {
59
+ const result = await driver.client
60
+ .selectFrom(table_name)
61
+ .selectAll()
62
+ .select(eb => [
63
+ with_media(eb, id_or_handle, driver.dialectType),
64
+ with_tags(eb, id_or_handle, driver.dialectType),
65
+ with_search(eb, id_or_handle, driver.dialectType),
66
+ ]
67
+ .filter(Boolean))
68
+ .where(where_id_or_handle_table(id_or_handle))
69
+ .executeTakeFirst();
70
+
71
+ return sanitize(result);
68
72
  }
69
73
  }
70
74
 
@@ -114,18 +118,20 @@ const list = (driver) => {
114
118
  .select(eb => [
115
119
  with_media(eb, eb.ref('posts.id'), driver.dialectType),
116
120
  with_tags(eb, eb.ref('posts.id'), driver.dialectType),
121
+ with_search(eb, eb.ref('posts.id'), driver.dialectType),
117
122
  ].filter(Boolean))
118
123
  .where(
119
124
  (eb) => {
120
125
  return query_to_eb(eb, query, table_name);
121
126
  }
122
127
  )
123
- .orderBy(query_to_sort(query))
128
+ .orderBy(query_to_sort(query, 'posts'))
129
+ // .orderBy()
124
130
  .limit(query.limitToLast ?? query.limit ?? 10)
125
131
  .execute();
126
132
 
127
133
  if(query.limitToLast) items.reverse();
128
-
134
+
129
135
  return sanitize_array(items);
130
136
  }
131
137
  }