@storecraft/database-sql-base 1.0.24 → 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 +6 -5
- package/index.js +2 -0
- package/migrations.mysql/00000_init_tables.js +10 -11
- package/migrations.mysql/00005_add_chats_table.js +30 -0
- package/migrations.postgres/00000_init_tables.js +10 -10
- package/migrations.postgres/00005_add_chats_table.js +31 -0
- package/migrations.sqlite/00000_init_tables.js +6 -6
- package/migrations.sqlite/00005_add_chats_table.js +31 -0
- package/package.json +2 -3
- package/src/con.auth_users.js +0 -7
- package/src/con.chats.js +151 -0
- package/src/con.collections.js +0 -14
- package/src/con.customers.js +1 -11
- package/src/con.discounts.js +11 -17
- package/src/con.images.js +0 -9
- package/src/con.notifications.js +0 -9
- package/src/con.orders.js +0 -9
- package/src/con.products.js +0 -12
- package/src/con.search.js +4 -2
- package/src/con.shipping.js +0 -9
- package/src/con.storefronts.js +2 -11
- package/src/con.tags.js +0 -9
- package/tests/sandbox.js +1 -1
- package/types.sql.tables.d.ts +7 -0
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.
|
42
|
-
await
|
43
|
-
|
44
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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.
|
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",
|
package/src/con.auth_users.js
CHANGED
@@ -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
|
|
package/src/con.chats.js
ADDED
@@ -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
|
+
}
|
package/src/con.collections.js
CHANGED
@@ -132,15 +132,6 @@ const list = (driver) => {
|
|
132
132
|
query, table_name
|
133
133
|
).execute();
|
134
134
|
|
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
135
|
if(query.limitToLast) items.reverse();
|
145
136
|
|
146
137
|
return sanitize_array(items);
|
@@ -185,11 +176,6 @@ const list_collection_products = (driver) => {
|
|
185
176
|
.limit(query.limitToLast ?? query.limit ?? 10),
|
186
177
|
query, 'products'
|
187
178
|
).execute()
|
188
|
-
// .orderBy(query_to_sort(query, 'products'))
|
189
|
-
// .execute();
|
190
|
-
|
191
|
-
// .compile();
|
192
|
-
// console.log(items[0])
|
193
179
|
|
194
180
|
if(query.limitToLast)
|
195
181
|
items.reverse();
|
package/src/con.customers.js
CHANGED
@@ -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
|
-
|
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);
|
@@ -187,8 +179,6 @@ const list_customer_orders = (driver) => {
|
|
187
179
|
.limit(query.limitToLast ?? query.limit ?? 10),
|
188
180
|
query, 'orders'
|
189
181
|
).execute();
|
190
|
-
// .orderBy(query_to_sort(query, 'orders'))
|
191
|
-
// .execute();
|
192
182
|
|
193
183
|
if(query.limitToLast)
|
194
184
|
items.reverse();
|
package/src/con.discounts.js
CHANGED
@@ -72,16 +72,17 @@ const upsert = (driver) => {
|
|
72
72
|
.columns(['entity_handle', 'entity_id', 'value', 'reporter'])
|
73
73
|
.expression(eb =>
|
74
74
|
eb.selectFrom('products')
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
)
|
75
|
+
.select(
|
76
|
+
eb => [
|
77
|
+
'handle as entity_handle',
|
78
|
+
'id as entity_id',
|
79
|
+
eb.val(item.id).as('value'),
|
80
|
+
eb.val(item.handle).as('reporter')
|
81
|
+
]
|
82
|
+
)
|
83
|
+
.where(
|
84
|
+
eb => eb.and(discount_to_conjunctions(eb, item))
|
85
|
+
)
|
85
86
|
).execute();
|
86
87
|
|
87
88
|
for(const extra_search of extra_search_for_products) {
|
@@ -261,10 +262,6 @@ const list = (driver) => {
|
|
261
262
|
query, table_name
|
262
263
|
).execute();
|
263
264
|
|
264
|
-
// .orderBy(query_to_sort(query, table_name))
|
265
|
-
// .limit(query.limitToLast ?? query.limit ?? 10)
|
266
|
-
// .execute();
|
267
|
-
|
268
265
|
if(query.limitToLast)
|
269
266
|
items.reverse();
|
270
267
|
|
@@ -309,9 +306,6 @@ const list_discount_products = (driver) => {
|
|
309
306
|
query, 'products'
|
310
307
|
).execute();
|
311
308
|
|
312
|
-
// .orderBy(query_to_sort(query, 'products'))
|
313
|
-
// .execute();
|
314
|
-
|
315
309
|
if(query.limitToLast)
|
316
310
|
items.reverse();
|
317
311
|
|
package/src/con.images.js
CHANGED
@@ -203,15 +203,6 @@ const list = (driver) => {
|
|
203
203
|
query, table_name
|
204
204
|
).execute()
|
205
205
|
|
206
|
-
// .where(
|
207
|
-
// (eb) => {
|
208
|
-
// return query_to_eb(eb, query, table_name);
|
209
|
-
// }
|
210
|
-
// )
|
211
|
-
// .orderBy(query_to_sort(query, 'images')) // ts complains because `usage` field is absent
|
212
|
-
// .limit(query.limitToLast ?? query.limit ?? 10)
|
213
|
-
// .execute();
|
214
|
-
|
215
206
|
if(query.limitToLast)
|
216
207
|
items.reverse();
|
217
208
|
|
package/src/con.notifications.js
CHANGED
@@ -129,15 +129,6 @@ const list = (driver) => {
|
|
129
129
|
query, table_name
|
130
130
|
).execute();
|
131
131
|
|
132
|
-
// .where(
|
133
|
-
// (eb) => {
|
134
|
-
// return query_to_eb(eb, query, table_name);
|
135
|
-
// }
|
136
|
-
// )
|
137
|
-
// .orderBy(query_to_sort(query, 'notifications'))
|
138
|
-
// .limit(query.limitToLast ?? query.limit ?? 10)
|
139
|
-
// .execute();
|
140
|
-
|
141
132
|
if(query.limitToLast)
|
142
133
|
items.reverse();
|
143
134
|
|
package/src/con.orders.js
CHANGED
@@ -150,15 +150,6 @@ const list = (driver) => {
|
|
150
150
|
query, table_name
|
151
151
|
).execute();
|
152
152
|
|
153
|
-
// .where(
|
154
|
-
// (eb) => {
|
155
|
-
// return query_to_eb(eb, query, table_name);
|
156
|
-
// }
|
157
|
-
// )
|
158
|
-
// .orderBy(query_to_sort(query, table_name))
|
159
|
-
// .limit(query.limitToLast ?? query.limit ?? 10)
|
160
|
-
// .execute();
|
161
|
-
|
162
153
|
if(query.limitToLast)
|
163
154
|
items.reverse();
|
164
155
|
|
package/src/con.products.js
CHANGED
@@ -34,7 +34,6 @@ import {
|
|
34
34
|
export const table_name = 'products'
|
35
35
|
|
36
36
|
/**
|
37
|
-
*
|
38
37
|
* @param {db_col["$type_upsert"]} item
|
39
38
|
*/
|
40
39
|
const is_variant = item => {
|
@@ -54,8 +53,6 @@ const is_variant = item => {
|
|
54
53
|
|
55
54
|
/**
|
56
55
|
* @param {SQL} driver
|
57
|
-
*
|
58
|
-
*
|
59
56
|
* @returns {db_col["upsert"]}
|
60
57
|
*/
|
61
58
|
const upsert = (driver) => {
|
@@ -424,15 +421,6 @@ const list = (driver) => {
|
|
424
421
|
query, table_name
|
425
422
|
).execute();
|
426
423
|
|
427
|
-
// .where(
|
428
|
-
// (eb) => {
|
429
|
-
// return query_to_eb(eb, query, table_name);
|
430
|
-
// }
|
431
|
-
// )
|
432
|
-
// .orderBy(query_to_sort(query, table_name))
|
433
|
-
// .limit(query.limitToLast ?? query.limit ?? 10)
|
434
|
-
// .execute();
|
435
|
-
|
436
424
|
if(query.limitToLast)
|
437
425
|
items.reverse();
|
438
426
|
|
package/src/con.search.js
CHANGED
@@ -22,7 +22,8 @@ const tables = [
|
|
22
22
|
'notifications',
|
23
23
|
'discounts',
|
24
24
|
'orders',
|
25
|
-
'templates'
|
25
|
+
'templates',
|
26
|
+
'chats'
|
26
27
|
]
|
27
28
|
|
28
29
|
/**
|
@@ -42,7 +43,7 @@ const prefix_to_resource = {
|
|
42
43
|
'tag': 'tags',
|
43
44
|
'template': 'templates',
|
44
45
|
'post': 'posts',
|
45
|
-
|
46
|
+
'chat': 'chats',
|
46
47
|
}
|
47
48
|
|
48
49
|
const resource_to_props = {
|
@@ -58,6 +59,7 @@ const resource_to_props = {
|
|
58
59
|
'tags': ['id', 'handle'],
|
59
60
|
'templates': ['id', 'handle', 'title'],
|
60
61
|
'posts': ['id', 'handle', 'title'],
|
62
|
+
'chats': ['id', 'customer_email', 'customer_id'],
|
61
63
|
}
|
62
64
|
|
63
65
|
/**
|
package/src/con.shipping.js
CHANGED
@@ -125,15 +125,6 @@ const list = (driver) => {
|
|
125
125
|
query, table_name
|
126
126
|
).execute();
|
127
127
|
|
128
|
-
// .where(
|
129
|
-
// (eb) => {
|
130
|
-
// return query_to_eb(eb, query, table_name);
|
131
|
-
// }
|
132
|
-
// )
|
133
|
-
// .orderBy(query_to_sort(query, 'shipping_methods'))
|
134
|
-
// .limit(query.limitToLast ?? query.limit ?? 10)
|
135
|
-
// .execute();
|
136
|
-
|
137
128
|
if(query.limitToLast)
|
138
129
|
items.reverse();
|
139
130
|
|
package/src/con.storefronts.js
CHANGED
@@ -221,16 +221,6 @@ const list = (driver) => {
|
|
221
221
|
query, table_name
|
222
222
|
).execute();
|
223
223
|
|
224
|
-
|
225
|
-
// .where(
|
226
|
-
// (eb) => {
|
227
|
-
// return query_to_eb(eb, query, table_name);
|
228
|
-
// }
|
229
|
-
// )
|
230
|
-
// .orderBy(query_to_sort(query, table_name))
|
231
|
-
// .limit(query.limitToLast ?? query.limit ?? 10)
|
232
|
-
// .execute();
|
233
|
-
|
234
224
|
if(query.limitToLast)
|
235
225
|
items.reverse();
|
236
226
|
|
@@ -345,7 +335,8 @@ const get_default_auto_generated_storefront = (driver) => {
|
|
345
335
|
).as('posts'),
|
346
336
|
|
347
337
|
stringArrayFrom(
|
348
|
-
eb
|
338
|
+
eb
|
339
|
+
.selectFrom('products')
|
349
340
|
.innerJoin(
|
350
341
|
'entity_to_tags_projections',
|
351
342
|
'entity_to_tags_projections.entity_id',
|
package/src/con.tags.js
CHANGED
@@ -109,15 +109,6 @@ const list = (driver) => {
|
|
109
109
|
query, table_name
|
110
110
|
).execute();
|
111
111
|
|
112
|
-
// .where(
|
113
|
-
// (eb) => {
|
114
|
-
// return query_to_eb(eb, query, table_name);
|
115
|
-
// }
|
116
|
-
// )
|
117
|
-
// .orderBy(query_to_sort(query, table_name))
|
118
|
-
// .limit(query.limitToLast ?? query.limit ?? 10)
|
119
|
-
// .execute();
|
120
|
-
|
121
112
|
if(query.limitToLast)
|
122
113
|
items.reverse();
|
123
114
|
|
package/tests/sandbox.js
CHANGED
package/types.sql.tables.d.ts
CHANGED
@@ -19,6 +19,7 @@ import {
|
|
19
19
|
export interface Database {
|
20
20
|
auth_users: AuthUserTypeTable,
|
21
21
|
tags: TagsTable
|
22
|
+
chats: ChatsTable
|
22
23
|
collections: CollectionsTable,
|
23
24
|
shipping_methods: ShippingMethodsTable;
|
24
25
|
posts: PostsTable;
|
@@ -184,6 +185,12 @@ export interface TagsTable extends Base {
|
|
184
185
|
values: JSONColumnType<string[]>;
|
185
186
|
}
|
186
187
|
|
188
|
+
export interface ChatsTable extends Base {
|
189
|
+
customer_id: string;
|
190
|
+
customer_email: string;
|
191
|
+
extra: JSONColumnType<object>;
|
192
|
+
}
|
193
|
+
|
187
194
|
export interface CollectionsTable extends Base {
|
188
195
|
title: string;
|
189
196
|
published: string | undefined;
|