@storecraft/database-sql-base 1.0.0 → 1.0.2
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 +30 -12
- package/index.js +172 -1
- package/{tsconfig.json → jsconfig.json} +1 -5
- package/migrate.js +25 -19
- package/migrations.mysql/00000_init_tables.js +6 -5
- package/migrations.postgres/00000_init_tables.js +15 -14
- package/migrations.shared/00001_seed_email_templates copy.js +262 -0
- package/migrations.shared/00001_seed_email_templates.js +5 -238
- package/migrations.sqlite/00000_init_tables.js +12 -12
- package/package.json +2 -4
- package/src/con.auth_users.js +5 -2
- package/src/con.collections.js +2 -2
- package/src/con.customers.js +2 -2
- package/src/con.discounts.js +3 -3
- package/src/con.discounts.utils.js +11 -11
- package/src/con.helpers.json.js +3 -3
- package/src/con.images.js +5 -5
- package/src/con.notifications.js +2 -2
- package/src/con.orders.js +19 -4
- package/src/con.posts.js +2 -2
- package/src/con.products.js +5 -5
- package/src/con.search.js +7 -7
- package/src/con.shared.experiment.js +723 -0
- package/src/con.shared.js +55 -21
- package/src/con.shipping.js +2 -2
- package/src/con.storefronts.js +2 -2
- package/src/con.tags.js +2 -2
- package/src/con.templates.js +22 -7
- package/src/utils.query.js +6 -6
- package/tests/runner.mssql-local.test.js +10 -6
- package/tests/runner.mysql-local.test.js +16 -63
- package/tests/runner.postgres-local.test.js +17 -62
- package/tests/runner.sqlite-local.test.js +15 -64
- package/tests/sandbox.test.js +15 -13
- package/types.public.d.ts +12 -4
- package/types.sql.tables.d.ts +4 -2
- package/driver.js +0 -190
- package/tests/query.cursor.test.js +0 -389
- package/tests/query.vql.test.js +0 -71
package/src/con.helpers.json.js
CHANGED
@@ -129,7 +129,7 @@ export const extract_first_selection = (expr, table) => {
|
|
129
129
|
*
|
130
130
|
* @template O
|
131
131
|
* @param {import('./con.helpers.json.js').SelectQueryBuilderExpression<O>} expr
|
132
|
-
* @param {import('../types.public.
|
132
|
+
* @param {import('../types.public.d.ts').SqlDialectType} sql_type
|
133
133
|
* @returns {import('kysely').RawBuilder<import('kysely').Simplify<O>[]>}
|
134
134
|
*/
|
135
135
|
export function jsonArrayFrom(expr, sql_type) {
|
@@ -170,7 +170,7 @@ export function jsonArrayFrom(expr, sql_type) {
|
|
170
170
|
* ```
|
171
171
|
* @template O
|
172
172
|
* @param {import('./con.helpers.json.js').SelectQueryBuilderExpression<O>} expr
|
173
|
-
* @param {import('../types.public.
|
173
|
+
* @param {import('../types.public.d.ts').SqlDialectType} sql_type
|
174
174
|
* @returns {import('kysely').RawBuilder<import('kysely').Simplify<O>[]>}
|
175
175
|
*/
|
176
176
|
export function stringArrayFrom(expr, sql_type) {
|
@@ -212,7 +212,7 @@ export function stringArrayFrom(expr, sql_type) {
|
|
212
212
|
*
|
213
213
|
* @template O
|
214
214
|
* @param {import('./con.helpers.json.js').SelectQueryBuilderExpression<O>} expr
|
215
|
-
* @param {import('../types.public.
|
215
|
+
* @param {import('../types.public.d.ts').SqlDialectType} sql_type
|
216
216
|
* @returns {import('kysely').RawBuilder<import('kysely').Simplify<O> | null>}
|
217
217
|
*/
|
218
218
|
export function jsonObjectFrom(expr, sql_type) {
|
package/src/con.images.js
CHANGED
@@ -1,18 +1,18 @@
|
|
1
|
-
import { func } from '@storecraft/core/
|
2
|
-
import { SQL } from '../
|
1
|
+
import { func } from '@storecraft/core/api'
|
2
|
+
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
6
|
import { 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
|
-
import { ID } from '@storecraft/core/
|
9
|
+
import { ID } from '@storecraft/core/api/utils.func.js'
|
10
10
|
import {
|
11
11
|
image_url_to_handle, image_url_to_name
|
12
|
-
} from '@storecraft/core/
|
12
|
+
} from '@storecraft/core/api/con.images.logic.js'
|
13
13
|
|
14
14
|
/**
|
15
|
-
* @typedef {import('@storecraft/core/
|
15
|
+
* @typedef {import('@storecraft/core/database').db_images} db_col
|
16
16
|
*/
|
17
17
|
export const table_name = 'images'
|
18
18
|
|
package/src/con.notifications.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { SQL } from '../
|
1
|
+
import { SQL } from '../index.js'
|
2
2
|
import { count_regular, delete_me, delete_search_of,
|
3
3
|
insert_search_of, regular_upsert_me, where_id_or_handle_table,
|
4
4
|
with_search } from './con.shared.js'
|
@@ -6,7 +6,7 @@ import { sanitize_array } from './utils.funcs.js'
|
|
6
6
|
import { query_to_eb, query_to_sort } from './utils.query.js'
|
7
7
|
|
8
8
|
/**
|
9
|
-
* @typedef {import('@storecraft/core/
|
9
|
+
* @typedef {import('@storecraft/core/database').db_notifications} db_col
|
10
10
|
*/
|
11
11
|
export const table_name = 'notifications'
|
12
12
|
|
package/src/con.orders.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { SQL } from '../
|
1
|
+
import { SQL } from '../index.js'
|
2
2
|
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,
|
@@ -8,7 +8,7 @@ import { sanitize_array } from './utils.funcs.js'
|
|
8
8
|
import { query_to_eb, query_to_sort } from './utils.query.js'
|
9
9
|
|
10
10
|
/**
|
11
|
-
* @typedef {import('@storecraft/core/
|
11
|
+
* @typedef {import('@storecraft/core/database').db_orders} db_col
|
12
12
|
*/
|
13
13
|
export const table_name = 'orders'
|
14
14
|
|
@@ -70,7 +70,15 @@ const get = (driver) => {
|
|
70
70
|
return (id_or_handle, options) => {
|
71
71
|
return driver.client
|
72
72
|
.selectFrom(table_name)
|
73
|
-
.selectAll()
|
73
|
+
// .selectAll()
|
74
|
+
.select(
|
75
|
+
[
|
76
|
+
'active', 'address', 'attributes', 'contact', 'coupons',
|
77
|
+
'created_at', 'updated_at', 'description', 'handle', 'id',
|
78
|
+
'line_items', 'notes', 'payment_gateway', 'pricing',
|
79
|
+
'shipping_method', 'status', 'validation'
|
80
|
+
]
|
81
|
+
)
|
74
82
|
.select(eb => [
|
75
83
|
with_media(eb, id_or_handle, driver.dialectType),
|
76
84
|
with_tags(eb, id_or_handle, driver.dialectType),
|
@@ -119,7 +127,14 @@ const list = (driver) => {
|
|
119
127
|
|
120
128
|
const items = await driver.client
|
121
129
|
.selectFrom(table_name)
|
122
|
-
.selectAll()
|
130
|
+
// .selectAll()
|
131
|
+
.select(
|
132
|
+
[
|
133
|
+
'active', 'address', 'attributes', 'contact', 'coupons', 'created_at',
|
134
|
+
'updated_at', 'description', 'handle', 'id', 'line_items', 'notes',
|
135
|
+
'payment_gateway', 'pricing', 'shipping_method', 'status', 'validation'
|
136
|
+
]
|
137
|
+
)
|
123
138
|
.select(eb => [
|
124
139
|
with_media(eb, eb.ref('orders.id'), driver.dialectType),
|
125
140
|
with_tags(eb, eb.ref('orders.id'), driver.dialectType),
|
package/src/con.posts.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { SQL } from '../
|
1
|
+
import { SQL } from '../index.js'
|
2
2
|
import { report_document_media } from './con.images.js'
|
3
3
|
import { count_regular, delete_entity_values_by_value_or_reporter,
|
4
4
|
delete_me, delete_media_of, delete_search_of, delete_tags_of,
|
@@ -9,7 +9,7 @@ import { sanitize_array } from './utils.funcs.js'
|
|
9
9
|
import { query_to_eb, query_to_sort } from './utils.query.js'
|
10
10
|
|
11
11
|
/**
|
12
|
-
* @typedef {import('@storecraft/core/
|
12
|
+
* @typedef {import('@storecraft/core/database').db_posts} db_col
|
13
13
|
*/
|
14
14
|
export const table_name = 'posts'
|
15
15
|
|
package/src/con.products.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import { enums } from '@storecraft/core/
|
2
|
-
import { SQL } from '../
|
1
|
+
import { enums } from '@storecraft/core/api'
|
2
|
+
import { SQL } from '../index.js'
|
3
3
|
import { delete_entity_values_of_by_entity_id_or_handle, delete_me, delete_media_of,
|
4
4
|
delete_search_of, delete_tags_of,
|
5
5
|
insert_entity_values_of, insert_media_of, insert_search_of,
|
@@ -18,7 +18,7 @@ import { report_document_media } from './con.images.js'
|
|
18
18
|
|
19
19
|
|
20
20
|
/**
|
21
|
-
* @typedef {import('@storecraft/core/
|
21
|
+
* @typedef {import('@storecraft/core/database').db_products} db_col
|
22
22
|
*/
|
23
23
|
export const table_name = 'products'
|
24
24
|
|
@@ -247,8 +247,8 @@ const getBulk = (driver) => {
|
|
247
247
|
*/
|
248
248
|
const remove_internal = (driver) => {
|
249
249
|
/**
|
250
|
-
* @param {import('@storecraft/core/
|
251
|
-
* import('@storecraft/core/
|
250
|
+
* @param {import('@storecraft/core/api').ProductType |
|
251
|
+
* import('@storecraft/core/api').VariantType
|
252
252
|
* } product
|
253
253
|
* @param {Transaction<import('../index.js').Database>} trx
|
254
254
|
*/
|
package/src/con.search.js
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
-
import { SQL } from '../
|
1
|
+
import { SQL } from '../index.js'
|
2
2
|
import { jsonArrayFrom } from './con.helpers.json.js';
|
3
3
|
import { query_to_eb, query_to_sort } from './utils.query.js';
|
4
4
|
|
5
5
|
/**
|
6
|
-
* @typedef {import('@storecraft/core/
|
6
|
+
* @typedef {import('@storecraft/core/database').search} db_col
|
7
7
|
*/
|
8
8
|
|
9
9
|
|
10
10
|
|
11
11
|
/**
|
12
|
-
* @type {(keyof import('@storecraft/core/
|
12
|
+
* @type {(keyof import('@storecraft/core/database').db_driver["resources"])[]}
|
13
13
|
*/
|
14
14
|
const tables = [
|
15
15
|
'tags',
|
@@ -27,7 +27,7 @@ const tables = [
|
|
27
27
|
]
|
28
28
|
|
29
29
|
/**
|
30
|
-
* @type {Record<string, keyof import('@storecraft/core/
|
30
|
+
* @type {Record<string, keyof import('@storecraft/core/database').db_driver["resources"]>}
|
31
31
|
*/
|
32
32
|
const prefix_to_resource = {
|
33
33
|
'au': 'auth_users',
|
@@ -47,7 +47,7 @@ const prefix_to_resource = {
|
|
47
47
|
}
|
48
48
|
|
49
49
|
/**
|
50
|
-
* @type {Record<keyof import('@storecraft/core/
|
50
|
+
* @type {Record<keyof import('@storecraft/core/database').db_driver["resources"], string[]>}
|
51
51
|
*/
|
52
52
|
const resource_to_props = {
|
53
53
|
'auth_users': ['id', 'handle'],
|
@@ -68,7 +68,7 @@ const resource_to_props = {
|
|
68
68
|
*
|
69
69
|
* @param {string} id
|
70
70
|
*
|
71
|
-
* @returns {keyof import('@storecraft/core/
|
71
|
+
* @returns {keyof import('@storecraft/core/database').db_driver["resources"]}
|
72
72
|
*/
|
73
73
|
export const id_to_resource = id => {
|
74
74
|
let result = undefined;
|
@@ -119,7 +119,7 @@ export const quicksearch = (driver) => {
|
|
119
119
|
)
|
120
120
|
)
|
121
121
|
|
122
|
-
/** @type {import('@storecraft/core/
|
122
|
+
/** @type {import('@storecraft/core/api').QuickSearchResult} */
|
123
123
|
const items = await sts.executeTakeFirst();
|
124
124
|
|
125
125
|
const sanitized = Object.fromEntries(
|