@storecraft/database-sql-base 1.0.0 → 1.0.1
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 -9
- package/driver.js +4 -20
- package/index.js +1 -1
- package/migrate.js +25 -19
- package/migrations.mysql/00000_init_tables.js +15 -14
- 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 +3 -1
- package/migrations.sqlite/00000_init_tables.js +12 -12
- package/migrations.sqlite/00002_test.js +26 -0
- package/package.json +2 -2
- package/src/con.auth_users.js +1 -0
- package/src/con.helpers.json.js +3 -3
- package/src/con.orders.js +17 -2
- package/src/con.shared.experiment.js +723 -0
- package/src/con.shared.js +12 -12
- package/tests/runner.mssql-local.test.js +3 -3
- package/tests/runner.mysql-local.test.js +13 -11
- package/tests/runner.postgres-local.test.js +14 -10
- package/tests/runner.sqlite-local.test.js +12 -10
- package/tests/sandbox.test.js +15 -13
- package/types.public.d.ts +12 -4
package/src/con.shared.js
CHANGED
@@ -273,7 +273,7 @@ export const delete_me = async (trx, table_name, id_or_handle) => {
|
|
273
273
|
*
|
274
274
|
* @param {import('kysely').ExpressionBuilder<Database>} eb
|
275
275
|
* @param {string | ExpressionWrapper<Database>} id_or_handle
|
276
|
-
* @param {import('../types.public.
|
276
|
+
* @param {import('../types.public.d.ts').SqlDialectType} sql_type
|
277
277
|
*/
|
278
278
|
export const with_tags = (eb, id_or_handle, sql_type) => {
|
279
279
|
return stringArrayFrom(
|
@@ -287,7 +287,7 @@ export const with_tags = (eb, id_or_handle, sql_type) => {
|
|
287
287
|
*
|
288
288
|
* @param {import('kysely').ExpressionBuilder<Database>} eb
|
289
289
|
* @param {string | ExpressionWrapper<Database>} id_or_handle
|
290
|
-
* @param {import('../types.public.
|
290
|
+
* @param {import('../types.public.d.ts').SqlDialectType} sql_type
|
291
291
|
*/
|
292
292
|
export const with_search = (eb, id_or_handle, sql_type) => {
|
293
293
|
return stringArrayFrom(
|
@@ -301,7 +301,7 @@ export const with_search = (eb, id_or_handle, sql_type) => {
|
|
301
301
|
*
|
302
302
|
* @param {import('kysely').ExpressionBuilder<Database>} eb
|
303
303
|
* @param {string | ExpressionWrapper<Database>} id_or_handle
|
304
|
-
* @param {import('../types.public.
|
304
|
+
* @param {import('../types.public.d.ts').SqlDialectType} sql_type
|
305
305
|
*/
|
306
306
|
export const with_media = (eb, id_or_handle, sql_type) => {
|
307
307
|
return stringArrayFrom(
|
@@ -331,7 +331,7 @@ const select_base_from = (eb, table) => {
|
|
331
331
|
*
|
332
332
|
* @param {import('kysely').ExpressionBuilder<Database, 'products'>} eb
|
333
333
|
* @param {string | ExpressionWrapper<Database>} product_id_or_handle
|
334
|
-
* @param {import('../types.public.
|
334
|
+
* @param {import('../types.public.d.ts').SqlDialectType} sql_type
|
335
335
|
*/
|
336
336
|
export const products_with_collections = (eb, product_id_or_handle, sql_type) => {
|
337
337
|
return jsonArrayFrom(
|
@@ -355,7 +355,7 @@ export const products_with_collections = (eb, product_id_or_handle, sql_type) =>
|
|
355
355
|
*
|
356
356
|
* @param {import('kysely').ExpressionBuilder<Database, 'products'>} eb
|
357
357
|
* @param {string | ExpressionWrapper<Database>} product_id_or_handle
|
358
|
-
* @param {import('../types.public.
|
358
|
+
* @param {import('../types.public.d.ts').SqlDialectType} sql_type
|
359
359
|
*/
|
360
360
|
export const products_with_discounts = (eb, product_id_or_handle, sql_type) => {
|
361
361
|
return jsonArrayFrom(
|
@@ -382,7 +382,7 @@ export const products_with_discounts = (eb, product_id_or_handle, sql_type) => {
|
|
382
382
|
*
|
383
383
|
* @param {import('kysely').ExpressionBuilder<Database, 'products'>} eb
|
384
384
|
* @param {string | ExpressionWrapper<Database>} product_id_or_handle
|
385
|
-
* @param {import('../types.public.
|
385
|
+
* @param {import('../types.public.d.ts').SqlDialectType} sql_type
|
386
386
|
*/
|
387
387
|
export const products_with_variants = (eb, product_id_or_handle, sql_type) => {
|
388
388
|
return jsonArrayFrom(
|
@@ -413,7 +413,7 @@ export const products_with_variants = (eb, product_id_or_handle, sql_type) => {
|
|
413
413
|
*
|
414
414
|
* @param {import('kysely').ExpressionBuilder<Database, 'products'>} eb
|
415
415
|
* @param {string | ExpressionWrapper<Database>} product_id_or_handle
|
416
|
-
* @param {import('../types.public.
|
416
|
+
* @param {import('../types.public.d.ts').SqlDialectType} sql_type
|
417
417
|
*/
|
418
418
|
export const products_with_related_products = (eb, product_id_or_handle, sql_type) => {
|
419
419
|
return jsonArrayFrom(
|
@@ -445,7 +445,7 @@ export const products_with_related_products = (eb, product_id_or_handle, sql_typ
|
|
445
445
|
*
|
446
446
|
* @param {import('kysely').ExpressionBuilder<Database, 'storefronts'>} eb
|
447
447
|
* @param {string | ExpressionWrapper<Database>} sf_id_or_handle
|
448
|
-
* @param {import('../types.public.
|
448
|
+
* @param {import('../types.public.d.ts').SqlDialectType} sql_type
|
449
449
|
*/
|
450
450
|
export const storefront_with_collections = (eb, sf_id_or_handle, sql_type) => {
|
451
451
|
return jsonArrayFrom(
|
@@ -469,7 +469,7 @@ export const storefront_with_collections = (eb, sf_id_or_handle, sql_type) => {
|
|
469
469
|
*
|
470
470
|
* @param {import('kysely').ExpressionBuilder<Database>} eb
|
471
471
|
* @param {string | ExpressionWrapper<Database>} sf_id_or_handle
|
472
|
-
* @param {import('../types.public.
|
472
|
+
* @param {import('../types.public.d.ts').SqlDialectType} sql_type
|
473
473
|
*/
|
474
474
|
export const storefront_with_products = (eb, sf_id_or_handle, sql_type) => {
|
475
475
|
return jsonArrayFrom(
|
@@ -500,7 +500,7 @@ export const storefront_with_products = (eb, sf_id_or_handle, sql_type) => {
|
|
500
500
|
*
|
501
501
|
* @param {import('kysely').ExpressionBuilder<Database>} eb
|
502
502
|
* @param {string | ExpressionWrapper<Database>} sf_id_or_handle
|
503
|
-
* @param {import('../types.public.
|
503
|
+
* @param {import('../types.public.d.ts').SqlDialectType} sql_type
|
504
504
|
*/
|
505
505
|
export const storefront_with_discounts = (eb, sf_id_or_handle, sql_type) => {
|
506
506
|
return jsonArrayFrom(
|
@@ -527,7 +527,7 @@ export const storefront_with_discounts = (eb, sf_id_or_handle, sql_type) => {
|
|
527
527
|
*
|
528
528
|
* @param {import('kysely').ExpressionBuilder<Database>} eb
|
529
529
|
* @param {string | ExpressionWrapper<Database>} sf_id_or_handle
|
530
|
-
* @param {import('../types.public.
|
530
|
+
* @param {import('../types.public.d.ts').SqlDialectType} sql_type
|
531
531
|
*/
|
532
532
|
export const storefront_with_posts = (eb, sf_id_or_handle, sql_type) => {
|
533
533
|
return jsonArrayFrom(
|
@@ -551,7 +551,7 @@ export const storefront_with_posts = (eb, sf_id_or_handle, sql_type) => {
|
|
551
551
|
*
|
552
552
|
* @param {import('kysely').ExpressionBuilder<Database>} eb
|
553
553
|
* @param {string | ExpressionWrapper<Database>} sf_id_or_handle
|
554
|
-
* @param {import('../types.public.
|
554
|
+
* @param {import('../types.public.d.ts').SqlDialectType} sql_type
|
555
555
|
*/
|
556
556
|
export const storefront_with_shipping = (eb, sf_id_or_handle, sql_type) => {
|
557
557
|
return jsonArrayFrom(
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import { App } from '@storecraft/core';
|
2
2
|
import { SQL } from '@storecraft/database-sql-base';
|
3
|
-
import {
|
3
|
+
import { migrateToLatest } from '@storecraft/database-sql-base/migrate.js';
|
4
|
+
import { NodePlatform } from '@storecraft/platforms/node';
|
4
5
|
import { api_index } from '@storecraft/test-runner'
|
5
6
|
import { MssqlDialect } from 'kysely';
|
6
7
|
import * as Tedious from 'tedious';
|
@@ -42,14 +43,13 @@ export const create_app = async () => {
|
|
42
43
|
}),
|
43
44
|
null, null, {
|
44
45
|
auth_admins_emails: ['admin@sc.com'],
|
45
|
-
auth_password_hash_rounds: 100,
|
46
46
|
auth_secret_access_token: 'auth_secret_access_token',
|
47
47
|
auth_secret_refresh_token: 'auth_secret_refresh_token'
|
48
48
|
}
|
49
49
|
);
|
50
50
|
|
51
51
|
await app.init();
|
52
|
-
await app.db
|
52
|
+
await migrateToLatest(app.db, false);
|
53
53
|
return app;
|
54
54
|
}
|
55
55
|
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import { App } from '@storecraft/core';
|
2
2
|
import { SQL } from '@storecraft/database-sql-base';
|
3
|
-
import {
|
3
|
+
import { migrateToLatest } from '@storecraft/database-sql-base/migrate.js';
|
4
|
+
import { NodePlatform } from '@storecraft/platforms/node';
|
4
5
|
import { api_index } from '@storecraft/test-runner'
|
5
6
|
import { MysqlDialect } from 'kysely';
|
6
7
|
import { createPool } from 'mysql2'
|
@@ -16,22 +17,23 @@ export const dialect = new MysqlDialect({
|
|
16
17
|
});
|
17
18
|
|
18
19
|
export const create_app = async () => {
|
19
|
-
|
20
|
-
|
21
|
-
new SQL({
|
22
|
-
dialect: dialect,
|
23
|
-
dialect_type: 'MYSQL'
|
24
|
-
}),
|
25
|
-
null, null, {
|
20
|
+
const app = new App(
|
21
|
+
{
|
26
22
|
auth_admins_emails: ['admin@sc.com'],
|
27
|
-
auth_password_hash_rounds: 100,
|
28
23
|
auth_secret_access_token: 'auth_secret_access_token',
|
29
24
|
auth_secret_refresh_token: 'auth_secret_refresh_token'
|
30
25
|
}
|
31
|
-
)
|
26
|
+
)
|
27
|
+
.withPlatform(new NodePlatform())
|
28
|
+
.withDatabase(
|
29
|
+
new SQL({
|
30
|
+
dialect: dialect,
|
31
|
+
dialect_type: 'MYSQL'
|
32
|
+
})
|
33
|
+
)
|
32
34
|
|
33
35
|
await app.init();
|
34
|
-
await app.db
|
36
|
+
await migrateToLatest(app.db, false);
|
35
37
|
|
36
38
|
return app;
|
37
39
|
}
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import { App } from '@storecraft/core';
|
2
2
|
import { SQL } from '@storecraft/database-sql-base';
|
3
|
-
import {
|
3
|
+
import { migrateToLatest } from '@storecraft/database-sql-base/migrate.js';
|
4
|
+
import { NodePlatform } from '@storecraft/platforms/node';
|
4
5
|
import { api_index } from '@storecraft/test-runner'
|
5
6
|
import { PostgresDialect } from 'kysely';
|
6
7
|
import pg from 'pg'
|
@@ -15,22 +16,25 @@ const pg_dialect = new PostgresDialect({
|
|
15
16
|
});
|
16
17
|
|
17
18
|
export const create_app = async () => {
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
dialect: pg_dialect,
|
22
|
-
dialect_type: 'POSTGRES'
|
23
|
-
}),
|
24
|
-
null, null, {
|
19
|
+
|
20
|
+
const app = new App(
|
21
|
+
{
|
25
22
|
auth_admins_emails: ['admin@sc.com'],
|
26
|
-
auth_password_hash_rounds: 100,
|
27
23
|
auth_secret_access_token: 'auth_secret_access_token',
|
28
24
|
auth_secret_refresh_token: 'auth_secret_refresh_token'
|
29
25
|
}
|
26
|
+
)
|
27
|
+
.withPlatform(new NodePlatform())
|
28
|
+
.withDatabase(
|
29
|
+
new SQL({
|
30
|
+
dialect: pg_dialect,
|
31
|
+
dialect_type: 'POSTGRES'
|
32
|
+
})
|
30
33
|
);
|
31
34
|
|
32
35
|
await app.init();
|
33
|
-
await app.db
|
36
|
+
await migrateToLatest(app.db, false);
|
37
|
+
|
34
38
|
return app;
|
35
39
|
}
|
36
40
|
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import { App } from '@storecraft/core';
|
2
2
|
import { SQL } from '@storecraft/database-sql-base';
|
3
|
-
import {
|
3
|
+
import { migrateToLatest } from '@storecraft/database-sql-base/migrate.js';
|
4
|
+
import { NodePlatform } from '@storecraft/platforms/node';
|
4
5
|
import { api_index } from '@storecraft/test-runner'
|
5
6
|
import SQLite from 'better-sqlite3'
|
6
7
|
import { SqliteDialect } from 'kysely';
|
@@ -12,22 +13,23 @@ export const sqlite_dialect = new SqliteDialect({
|
|
12
13
|
});
|
13
14
|
|
14
15
|
export const create_app = async () => {
|
15
|
-
|
16
|
-
|
17
|
-
new SQL({
|
18
|
-
dialect: sqlite_dialect,
|
19
|
-
dialect_type: 'SQLITE'
|
20
|
-
}),
|
21
|
-
null, null, {
|
16
|
+
const app = new App(
|
17
|
+
{
|
22
18
|
auth_admins_emails: ['admin@sc.com'],
|
23
|
-
auth_password_hash_rounds: 100,
|
24
19
|
auth_secret_access_token: 'auth_secret_access_token',
|
25
20
|
auth_secret_refresh_token: 'auth_secret_refresh_token'
|
26
21
|
}
|
22
|
+
)
|
23
|
+
.withPlatform(new NodePlatform())
|
24
|
+
.withDatabase(
|
25
|
+
new SQL({
|
26
|
+
dialect: sqlite_dialect,
|
27
|
+
dialect_type: 'SQLITE'
|
28
|
+
})
|
27
29
|
);
|
28
30
|
|
29
31
|
await app.init();
|
30
|
-
await app.db
|
32
|
+
await migrateToLatest(app.db, false);
|
31
33
|
|
32
34
|
return app;
|
33
35
|
}
|
package/tests/sandbox.test.js
CHANGED
@@ -1,33 +1,35 @@
|
|
1
1
|
import { App } from '@storecraft/core';
|
2
|
-
import {
|
3
|
-
import { NodePlatform } from '@storecraft/platform-node';
|
2
|
+
import { NodePlatform } from '@storecraft/platforms/node';
|
4
3
|
import { SqliteDialect } from 'kysely';
|
5
4
|
import { homedir } from 'os';
|
6
5
|
import { join } from 'path';
|
7
6
|
import SQLite from 'better-sqlite3'
|
8
7
|
import { SQL } from '../index.js';
|
8
|
+
import { migrateToLatest } from '../migrate.js';
|
9
9
|
|
10
10
|
export const sqlite_dialect = new SqliteDialect({
|
11
11
|
database: async () => new SQLite(join(homedir(), 'db.sqlite')),
|
12
12
|
});
|
13
13
|
|
14
14
|
export const create_app = async () => {
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
dialect: sqlite_dialect,
|
19
|
-
dialect_type: 'SQLITE'
|
20
|
-
}),
|
21
|
-
null, null, {
|
15
|
+
|
16
|
+
const app = new App(
|
17
|
+
{
|
22
18
|
auth_admins_emails: ['admin@sc.com'],
|
23
|
-
auth_password_hash_rounds: 100,
|
24
19
|
auth_secret_access_token: 'auth_secret_access_token',
|
25
20
|
auth_secret_refresh_token: 'auth_secret_refresh_token'
|
26
21
|
}
|
27
|
-
)
|
22
|
+
)
|
23
|
+
.withPlatform(new NodePlatform())
|
24
|
+
.withDatabase(
|
25
|
+
new SQL({
|
26
|
+
dialect: sqlite_dialect,
|
27
|
+
dialect_type: 'SQLITE'
|
28
|
+
})
|
29
|
+
)
|
28
30
|
|
29
31
|
await app.init();
|
30
|
-
await app.db
|
32
|
+
await migrateToLatest(app.db, false);
|
31
33
|
|
32
34
|
return app;
|
33
35
|
}
|
@@ -49,7 +51,7 @@ const withTime = async (fn) => {
|
|
49
51
|
async function test() {
|
50
52
|
const app = await withTime(create_app);
|
51
53
|
|
52
|
-
await app.db
|
54
|
+
await migrateToLatest(app.db, false);
|
53
55
|
|
54
56
|
|
55
57
|
const doit = async () => {
|
package/types.public.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
import type { Dialect } from 'kysely'
|
1
|
+
import type { Dialect } from 'kysely';
|
2
2
|
|
3
|
-
export
|
3
|
+
export { SQL } from './index.js';
|
4
4
|
|
5
5
|
export type SqlDialectType = 'SQLITE' | 'POSTGRES' | 'MYSQL';
|
6
6
|
|
@@ -9,11 +9,19 @@ export type SqlDialectType = 'SQLITE' | 'POSTGRES' | 'MYSQL';
|
|
9
9
|
*/
|
10
10
|
export type Config = {
|
11
11
|
/**
|
12
|
-
*
|
12
|
+
* @description Database name
|
13
|
+
*
|
14
|
+
* @default main
|
15
|
+
*/
|
16
|
+
db_name?: string,
|
17
|
+
|
18
|
+
/**
|
19
|
+
* @description The `Kysely` dialect
|
13
20
|
*/
|
14
21
|
dialect: Dialect,
|
22
|
+
|
15
23
|
/**
|
16
|
-
* The type of the sql dialect `SQLITE`, `POSTGRES`, `MYSQL
|
24
|
+
* @description The type of the sql dialect `SQLITE`, `POSTGRES`, `MYSQL`
|
17
25
|
*/
|
18
26
|
dialect_type: SqlDialectType;
|
19
27
|
}
|