@storecraft/database-sqlite 1.0.1 → 1.0.3
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 +8 -92
- package/index.js +2 -2
- package/{tsconfig.json → jsconfig.json} +4 -4
- package/package.json +2 -6
- package/tests/runner.test.js +6 -57
- package/types.public.d.ts +5 -6
- package/src/con.auth_users.js +0 -160
- package/src/con.collections.js +0 -197
- package/src/con.customers.js +0 -202
- package/src/con.discounts.js +0 -225
- package/src/con.discounts.utils.js +0 -180
- package/src/con.helpers.json.js +0 -231
- package/src/con.helpers.json.mssql.js +0 -233
- package/src/con.helpers.json.mysql.js +0 -239
- package/src/con.helpers.json.postgres.js +0 -223
- package/src/con.helpers.json.sqlite.js +0 -263
- package/src/con.images.js +0 -230
- package/src/con.notifications.js +0 -149
- package/src/con.orders.js +0 -171
- package/src/con.posts.js +0 -147
- package/src/con.products.js +0 -497
- package/src/con.search.js +0 -148
- package/src/con.shared.experiment.js +0 -723
- package/src/con.shared.js +0 -616
- package/src/con.shipping.js +0 -147
- package/src/con.storefronts.js +0 -301
- package/src/con.tags.js +0 -120
- package/src/con.templates.js +0 -133
- package/src/kysely.sanitize.plugin.js +0 -40
- package/src/utils.funcs.js +0 -77
- package/src/utils.query.js +0 -195
- package/tests/query.cursor.test.js +0 -389
- package/tests/query.vql.test.js +0 -71
- package/tests/runner.mssql-local.test.js +0 -118
- package/tests/runner.mysql-local.test.js +0 -103
- package/tests/runner.postgres-local.test.js +0 -103
- package/tests/sandbox.test.js +0 -73
package/tests/query.vql.test.js
DELETED
@@ -1,71 +0,0 @@
|
|
1
|
-
// import { test } from 'uvu';
|
2
|
-
// import * as assert from 'uvu/assert';
|
3
|
-
// import { query_vql_to_mongo } from '../src/utils.query.js'
|
4
|
-
|
5
|
-
// test('VQL', async () => {
|
6
|
-
// const vql_ast = {
|
7
|
-
// op: '&',
|
8
|
-
// args: [
|
9
|
-
// {
|
10
|
-
// op: 'LEAF',
|
11
|
-
// value: 'name:tomer'
|
12
|
-
// },
|
13
|
-
// {
|
14
|
-
// op: '&',
|
15
|
-
// args: [
|
16
|
-
// {
|
17
|
-
// op: 'LEAF',
|
18
|
-
// value: 'tag:genre_a'
|
19
|
-
// },
|
20
|
-
// {
|
21
|
-
// op: '!',
|
22
|
-
// args: [
|
23
|
-
// {
|
24
|
-
// op: 'LEAF',
|
25
|
-
// value: 'tag:genre_b'
|
26
|
-
// }
|
27
|
-
// ]
|
28
|
-
// }
|
29
|
-
// ],
|
30
|
-
// group: true
|
31
|
-
// }
|
32
|
-
// ],
|
33
|
-
// group: true
|
34
|
-
// };
|
35
|
-
|
36
|
-
// const mongo = {
|
37
|
-
// "$and": [
|
38
|
-
// {
|
39
|
-
// "search": {
|
40
|
-
// "$regex": "^name:tomer$"
|
41
|
-
// }
|
42
|
-
// },
|
43
|
-
// {
|
44
|
-
// "$and": [
|
45
|
-
// {
|
46
|
-
// "search": {
|
47
|
-
// "$regex": "^tag:genre_a$"
|
48
|
-
// }
|
49
|
-
// },
|
50
|
-
// {
|
51
|
-
// "$nor": [
|
52
|
-
// {
|
53
|
-
// "search": {
|
54
|
-
// "$regex": "^tag:genre_b$"
|
55
|
-
// }
|
56
|
-
// }
|
57
|
-
// ]
|
58
|
-
// }
|
59
|
-
// ]
|
60
|
-
// }
|
61
|
-
// ]
|
62
|
-
// };
|
63
|
-
|
64
|
-
// const m1 = query_vql_to_mongo(vql_ast);
|
65
|
-
|
66
|
-
// // console.log(JSON.stringify(m1, null, 2))
|
67
|
-
|
68
|
-
// assert.equal(m1, mongo);
|
69
|
-
// });
|
70
|
-
|
71
|
-
// test.run();
|
@@ -1,118 +0,0 @@
|
|
1
|
-
import { App } from '@storecraft/core';
|
2
|
-
import { SQL } from '@storecraft/database-sql-base';
|
3
|
-
import { migrateToLatest } from '@storecraft/database-sql-base/migrate.js';
|
4
|
-
import { NodePlatform } from '@storecraft/platforms/node';
|
5
|
-
import { api_index } from '@storecraft/test-runner'
|
6
|
-
import { MssqlDialect } from 'kysely';
|
7
|
-
import * as Tedious from 'tedious';
|
8
|
-
import * as Tarn from 'tarn';
|
9
|
-
|
10
|
-
const dialect = new MssqlDialect({
|
11
|
-
tarn: {
|
12
|
-
...Tarn,
|
13
|
-
options: {
|
14
|
-
min: 0,
|
15
|
-
max: 10,
|
16
|
-
},
|
17
|
-
},
|
18
|
-
tedious: {
|
19
|
-
...Tedious,
|
20
|
-
connectionFactory: () => new Tedious.Connection({
|
21
|
-
authentication: {
|
22
|
-
options: {
|
23
|
-
password: process.env.MSSQL_PASSWORD,
|
24
|
-
userName: process.env.MSSQL_USER,
|
25
|
-
},
|
26
|
-
type: 'default',
|
27
|
-
},
|
28
|
-
options: {
|
29
|
-
port: parseInt(process.env.MSSQL_PORT),
|
30
|
-
trustServerCertificate: true,
|
31
|
-
},
|
32
|
-
server: process.env.MSSQL_HOST,
|
33
|
-
}),
|
34
|
-
},
|
35
|
-
});
|
36
|
-
|
37
|
-
export const create_app = async () => {
|
38
|
-
let app = new App(
|
39
|
-
new NodePlatform(),
|
40
|
-
new SQL({
|
41
|
-
dialect: dialect,
|
42
|
-
dialect_type: 'MSSQL'
|
43
|
-
}),
|
44
|
-
null, null, {
|
45
|
-
auth_admins_emails: ['admin@sc.com'],
|
46
|
-
auth_secret_access_token: 'auth_secret_access_token',
|
47
|
-
auth_secret_refresh_token: 'auth_secret_refresh_token'
|
48
|
-
}
|
49
|
-
);
|
50
|
-
|
51
|
-
await app.init();
|
52
|
-
await migrateToLatest(app.db, false);
|
53
|
-
return app;
|
54
|
-
}
|
55
|
-
|
56
|
-
async function test() {
|
57
|
-
const app = await create_app();
|
58
|
-
|
59
|
-
Object.entries(api_index).slice(0, -1).forEach(
|
60
|
-
([name, runner]) => {
|
61
|
-
runner.create(app).run();
|
62
|
-
}
|
63
|
-
);
|
64
|
-
const last_test = Object.values(api_index).at(-1).create(app);
|
65
|
-
last_test.after(async () => { await app.db.disconnect() });
|
66
|
-
last_test.run();
|
67
|
-
}
|
68
|
-
|
69
|
-
test();
|
70
|
-
|
71
|
-
async function test2() {
|
72
|
-
const app = await create_app();
|
73
|
-
|
74
|
-
// api_index.api_auth_test.create(app).run();
|
75
|
-
|
76
|
-
// api_index.api_tags_crud_test.create(app).run();
|
77
|
-
// api_index.api_tags_list_test.create(app).run();
|
78
|
-
|
79
|
-
// api_index.api_collections_crud_test.create(app).run();
|
80
|
-
// api_index.api_collections_list_test.create(app).run();
|
81
|
-
// api_index.api_collections_products_test.create(app).run();
|
82
|
-
|
83
|
-
// api_index.api_products_crud_test.create(app).run();
|
84
|
-
// api_index.api_products_collections_test.create(app).run();
|
85
|
-
// api_index.api_products_list_test.create(app).run();
|
86
|
-
// api_index.api_products_discounts_test.create(app).run();
|
87
|
-
// api_index.api_products_variants_test.create(app).run();
|
88
|
-
|
89
|
-
// api_index.api_shipping_crud_test.create(app).run();
|
90
|
-
// api_index.api_shipping_list_test.create(app).run();
|
91
|
-
|
92
|
-
// api_index.api_posts_crud_test.create(app).run();
|
93
|
-
// api_index.api_posts_list_test.create(app).run();
|
94
|
-
|
95
|
-
// api_index.api_customers_crud_test.create(app).run();
|
96
|
-
// api_index.api_customers_list_test.create(app).run();
|
97
|
-
|
98
|
-
// api_index.api_orders_crud_test.create(app).run();
|
99
|
-
// api_index.api_orders_list_test.create(app).run();
|
100
|
-
|
101
|
-
// api_index.api_storefronts_crud_test.create(app).run();
|
102
|
-
// api_index.api_storefronts_list_test.create(app).run();
|
103
|
-
// api_index.api_storefronts_all_connections_test.create(app).run();
|
104
|
-
|
105
|
-
// api_index.api_notifications_crud_test.create(app).run();
|
106
|
-
// api_index.api_notifications_list_test.create(app).run();
|
107
|
-
|
108
|
-
api_index.api_images_crud_test.create(app).run();
|
109
|
-
api_index.api_images_list_test.create(app).run();
|
110
|
-
|
111
|
-
// api_index.api_discounts_crud_test.create(app).run();
|
112
|
-
// api_index.api_discounts_list_test.create(app).run();
|
113
|
-
// api_index.api_discounts_products_test.create(app).run();
|
114
|
-
|
115
|
-
|
116
|
-
}
|
117
|
-
|
118
|
-
// test2();
|
@@ -1,103 +0,0 @@
|
|
1
|
-
import { App } from '@storecraft/core';
|
2
|
-
import { SQL } from '@storecraft/database-sql-base';
|
3
|
-
import { migrateToLatest } from '@storecraft/database-sql-base/migrate.js';
|
4
|
-
import { NodePlatform } from '@storecraft/platforms/node';
|
5
|
-
import { api_index } from '@storecraft/test-runner'
|
6
|
-
import { MysqlDialect } from 'kysely';
|
7
|
-
import { createPool } from 'mysql2'
|
8
|
-
|
9
|
-
export const dialect = new MysqlDialect({
|
10
|
-
pool: createPool({
|
11
|
-
database: process.env.MYSQL_DB_NAME,
|
12
|
-
host: process.env.MYSQL_HOST,
|
13
|
-
port: parseInt(process.env.MYSQL_PORT),
|
14
|
-
user: process.env.MYSQL_USER,
|
15
|
-
password: process.env.MYSQL_PASSWORD,
|
16
|
-
})
|
17
|
-
});
|
18
|
-
|
19
|
-
export const create_app = async () => {
|
20
|
-
const app = new App(
|
21
|
-
{
|
22
|
-
auth_admins_emails: ['admin@sc.com'],
|
23
|
-
auth_secret_access_token: 'auth_secret_access_token',
|
24
|
-
auth_secret_refresh_token: 'auth_secret_refresh_token'
|
25
|
-
}
|
26
|
-
)
|
27
|
-
.withPlatform(new NodePlatform())
|
28
|
-
.withDatabase(
|
29
|
-
new SQL({
|
30
|
-
dialect: dialect,
|
31
|
-
dialect_type: 'MYSQL'
|
32
|
-
})
|
33
|
-
)
|
34
|
-
|
35
|
-
await app.init();
|
36
|
-
await migrateToLatest(app.db, false);
|
37
|
-
|
38
|
-
return app;
|
39
|
-
}
|
40
|
-
|
41
|
-
async function test() {
|
42
|
-
const app = await create_app();
|
43
|
-
|
44
|
-
Object.entries(api_index).slice(0, -1).forEach(
|
45
|
-
([name, runner]) => {
|
46
|
-
runner.create(app).run();
|
47
|
-
}
|
48
|
-
);
|
49
|
-
const last_test = Object.values(api_index).at(-1).create(app);
|
50
|
-
last_test.after(async () => { await app.db.disconnect() });
|
51
|
-
last_test.run();
|
52
|
-
}
|
53
|
-
|
54
|
-
test();
|
55
|
-
|
56
|
-
async function test2() {
|
57
|
-
const app = await create_app();
|
58
|
-
|
59
|
-
// api_index.api_auth_test.create(app).run();
|
60
|
-
|
61
|
-
// api_index.api_tags_crud_test.create(app).run();
|
62
|
-
// api_index.api_tags_list_test.create(app).run();
|
63
|
-
|
64
|
-
// api_index.api_collections_crud_test.create(app).run();
|
65
|
-
// api_index.api_collections_list_test.create(app).run();
|
66
|
-
// api_index.api_collections_products_test.create(app).run();
|
67
|
-
|
68
|
-
// api_index.api_products_crud_test.create(app).run();
|
69
|
-
// api_index.api_products_collections_test.create(app).run();
|
70
|
-
// api_index.api_products_list_test.create(app).run();
|
71
|
-
// api_index.api_products_discounts_test.create(app).run();
|
72
|
-
// api_index.api_products_variants_test.create(app).run();
|
73
|
-
|
74
|
-
// api_index.api_shipping_crud_test.create(app).run();
|
75
|
-
// api_index.api_shipping_list_test.create(app).run();
|
76
|
-
|
77
|
-
// api_index.api_posts_crud_test.create(app).run();
|
78
|
-
// api_index.api_posts_list_test.create(app).run();
|
79
|
-
|
80
|
-
// api_index.api_customers_crud_test.create(app).run();
|
81
|
-
// api_index.api_customers_list_test.create(app).run();
|
82
|
-
|
83
|
-
api_index.api_orders_crud_test.create(app).run();
|
84
|
-
api_index.api_orders_list_test.create(app).run();
|
85
|
-
|
86
|
-
api_index.api_storefronts_crud_test.create(app).run();
|
87
|
-
api_index.api_storefronts_list_test.create(app).run();
|
88
|
-
api_index.api_storefronts_all_connections_test.create(app).run();
|
89
|
-
|
90
|
-
api_index.api_notifications_crud_test.create(app).run();
|
91
|
-
api_index.api_notifications_list_test.create(app).run();
|
92
|
-
|
93
|
-
api_index.api_images_crud_test.create(app).run();
|
94
|
-
api_index.api_images_list_test.create(app).run();
|
95
|
-
|
96
|
-
api_index.api_discounts_crud_test.create(app).run();
|
97
|
-
api_index.api_discounts_list_test.create(app).run();
|
98
|
-
api_index.api_discounts_products_test.create(app).run();
|
99
|
-
|
100
|
-
|
101
|
-
}
|
102
|
-
|
103
|
-
// test2();
|
@@ -1,103 +0,0 @@
|
|
1
|
-
import { App } from '@storecraft/core';
|
2
|
-
import { SQL } from '@storecraft/database-sql-base';
|
3
|
-
import { migrateToLatest } from '@storecraft/database-sql-base/migrate.js';
|
4
|
-
import { NodePlatform } from '@storecraft/platforms/node';
|
5
|
-
import { api_index } from '@storecraft/test-runner'
|
6
|
-
import { PostgresDialect } from 'kysely';
|
7
|
-
import pg from 'pg'
|
8
|
-
|
9
|
-
const pg_dialect = new PostgresDialect({
|
10
|
-
pool: new pg.Pool({
|
11
|
-
host: process.env.POSTGRES_HOST,
|
12
|
-
port: parseInt(process.env.POSTGRES_PORT),
|
13
|
-
user: process.env.POSTGRES_USER,
|
14
|
-
password: process.env.POSTGRES_PASSWORD,
|
15
|
-
})
|
16
|
-
});
|
17
|
-
|
18
|
-
export const create_app = async () => {
|
19
|
-
|
20
|
-
const app = new App(
|
21
|
-
{
|
22
|
-
auth_admins_emails: ['admin@sc.com'],
|
23
|
-
auth_secret_access_token: 'auth_secret_access_token',
|
24
|
-
auth_secret_refresh_token: 'auth_secret_refresh_token'
|
25
|
-
}
|
26
|
-
)
|
27
|
-
.withPlatform(new NodePlatform())
|
28
|
-
.withDatabase(
|
29
|
-
new SQL({
|
30
|
-
dialect: pg_dialect,
|
31
|
-
dialect_type: 'POSTGRES'
|
32
|
-
})
|
33
|
-
);
|
34
|
-
|
35
|
-
await app.init();
|
36
|
-
await migrateToLatest(app.db, false);
|
37
|
-
|
38
|
-
return app;
|
39
|
-
}
|
40
|
-
|
41
|
-
async function test() {
|
42
|
-
const app = await create_app();
|
43
|
-
|
44
|
-
Object.entries(api_index).slice(0, -1).forEach(
|
45
|
-
([name, runner]) => {
|
46
|
-
runner.create(app).run();
|
47
|
-
}
|
48
|
-
);
|
49
|
-
const last_test = Object.values(api_index).at(-1).create(app);
|
50
|
-
last_test.after(async () => { await app.db.disconnect() });
|
51
|
-
last_test.run();
|
52
|
-
}
|
53
|
-
|
54
|
-
test();
|
55
|
-
|
56
|
-
async function test2() {
|
57
|
-
const app = await create_app();
|
58
|
-
|
59
|
-
api_index.api_auth_test.create(app).run();
|
60
|
-
|
61
|
-
api_index.api_tags_crud_test.create(app).run();
|
62
|
-
api_index.api_tags_list_test.create(app).run();
|
63
|
-
|
64
|
-
api_index.api_collections_crud_test.create(app).run();
|
65
|
-
api_index.api_collections_list_test.create(app).run();
|
66
|
-
api_index.api_collections_products_test.create(app).run();
|
67
|
-
|
68
|
-
api_index.api_products_crud_test.create(app).run();
|
69
|
-
api_index.api_products_collections_test.create(app).run();
|
70
|
-
api_index.api_products_list_test.create(app).run();
|
71
|
-
api_index.api_products_discounts_test.create(app).run();
|
72
|
-
api_index.api_products_variants_test.create(app).run();
|
73
|
-
|
74
|
-
api_index.api_shipping_crud_test.create(app).run();
|
75
|
-
api_index.api_shipping_list_test.create(app).run();
|
76
|
-
|
77
|
-
api_index.api_posts_crud_test.create(app).run();
|
78
|
-
api_index.api_posts_list_test.create(app).run();
|
79
|
-
|
80
|
-
api_index.api_customers_crud_test.create(app).run();
|
81
|
-
api_index.api_customers_list_test.create(app).run();
|
82
|
-
|
83
|
-
api_index.api_orders_crud_test.create(app).run();
|
84
|
-
api_index.api_orders_list_test.create(app).run();
|
85
|
-
|
86
|
-
api_index.api_storefronts_crud_test.create(app).run();
|
87
|
-
api_index.api_storefronts_list_test.create(app).run();
|
88
|
-
api_index.api_storefronts_all_connections_test.create(app).run();
|
89
|
-
|
90
|
-
api_index.api_notifications_crud_test.create(app).run();
|
91
|
-
api_index.api_notifications_list_test.create(app).run();
|
92
|
-
|
93
|
-
api_index.api_images_crud_test.create(app).run();
|
94
|
-
api_index.api_images_list_test.create(app).run();
|
95
|
-
|
96
|
-
api_index.api_discounts_crud_test.create(app).run();
|
97
|
-
api_index.api_discounts_list_test.create(app).run();
|
98
|
-
api_index.api_discounts_products_test.create(app).run();
|
99
|
-
|
100
|
-
|
101
|
-
}
|
102
|
-
|
103
|
-
// test2();
|
package/tests/sandbox.test.js
DELETED
@@ -1,73 +0,0 @@
|
|
1
|
-
import { App } from '@storecraft/core';
|
2
|
-
import { NodePlatform } from '@storecraft/platforms/node';
|
3
|
-
import { SqliteDialect } from 'kysely';
|
4
|
-
import { homedir } from 'os';
|
5
|
-
import { join } from 'path';
|
6
|
-
import SQLite from 'better-sqlite3'
|
7
|
-
import { SQL } from '../index.js';
|
8
|
-
import { migrateToLatest } from '../migrate.js';
|
9
|
-
|
10
|
-
export const sqlite_dialect = new SqliteDialect({
|
11
|
-
database: async () => 4,
|
12
|
-
});
|
13
|
-
|
14
|
-
export const create_app = async () => {
|
15
|
-
|
16
|
-
const app = new App(
|
17
|
-
{
|
18
|
-
auth_admins_emails: ['admin@sc.com'],
|
19
|
-
auth_secret_access_token: 'auth_secret_access_token',
|
20
|
-
auth_secret_refresh_token: 'auth_secret_refresh_token'
|
21
|
-
}
|
22
|
-
)
|
23
|
-
.withPlatform(new NodePlatform())
|
24
|
-
.withDatabase(
|
25
|
-
new SQL({
|
26
|
-
dialect: sqlite_dialect,
|
27
|
-
dialect_type: 'SQLITE'
|
28
|
-
})
|
29
|
-
)
|
30
|
-
|
31
|
-
await app.init();
|
32
|
-
await migrateToLatest(app.db, false);
|
33
|
-
|
34
|
-
return app;
|
35
|
-
}
|
36
|
-
|
37
|
-
/**
|
38
|
-
*
|
39
|
-
* @template R
|
40
|
-
*
|
41
|
-
* @param {(()=>Promise<R>) | (() => R)} fn
|
42
|
-
*/
|
43
|
-
const withTime = async (fn) => {
|
44
|
-
const n1 = Date.now() ;
|
45
|
-
const r = await fn();
|
46
|
-
const delta = Date.now() - n1;
|
47
|
-
console.log(delta);
|
48
|
-
return r;
|
49
|
-
}
|
50
|
-
|
51
|
-
async function test() {
|
52
|
-
const app = await withTime(create_app);
|
53
|
-
|
54
|
-
await migrateToLatest(app.db, false);
|
55
|
-
|
56
|
-
|
57
|
-
const doit = async () => {
|
58
|
-
let items = await app.db.resources.search.quicksearch(
|
59
|
-
{
|
60
|
-
vql: 'ship 2',
|
61
|
-
sortBy: ['updated_at']
|
62
|
-
}
|
63
|
-
);
|
64
|
-
return items;
|
65
|
-
}
|
66
|
-
|
67
|
-
const items = await withTime(doit);
|
68
|
-
|
69
|
-
// console.log('items ', items)
|
70
|
-
}
|
71
|
-
|
72
|
-
test();
|
73
|
-
|