@storecraft/database-sqlite 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.
@@ -0,0 +1,71 @@
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();
@@ -0,0 +1,118 @@
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();
@@ -0,0 +1,103 @@
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();
@@ -0,0 +1,103 @@
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();
@@ -0,0 +1,92 @@
1
+ import { App } from '@storecraft/core';
2
+ import { SQLite } from '@storecraft/database-sqlite';
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 { homedir } from 'node:os';
7
+ import { join } from 'node:path';
8
+
9
+ export const create_app = async () => {
10
+ const app = new App(
11
+ {
12
+ auth_admins_emails: ['admin@sc.com'],
13
+ auth_secret_access_token: 'auth_secret_access_token',
14
+ auth_secret_refresh_token: 'auth_secret_refresh_token'
15
+ }
16
+ )
17
+ .withPlatform(new NodePlatform())
18
+ .withDatabase(
19
+ new SQLite({ filename: join(homedir(), 'db.sqlite') })
20
+ );
21
+
22
+ await app.init();
23
+ await migrateToLatest(app.db, false);
24
+
25
+ return app;
26
+ }
27
+
28
+ async function test() {
29
+ const app = await create_app();
30
+
31
+ Object.entries(api_index).slice(0, -1).forEach(
32
+ ([name, runner]) => {
33
+ runner.create(app).run();
34
+ }
35
+ );
36
+ const last_test = Object.values(api_index).at(-1).create(app);
37
+ last_test.after(async () => { await app.db.disconnect() });
38
+ last_test.run();
39
+ }
40
+
41
+ test();
42
+
43
+ async function test2() {
44
+ const app = await create_app();
45
+
46
+ // api_index.api_auth_test.create(app).run();
47
+
48
+ api_index.api_checkout_test.create(app).run();
49
+
50
+ // api_index.api_tags_crud_test.create(app).run();
51
+ // api_index.api_tags_list_test.create(app).run();
52
+
53
+ // api_index.api_collections_crud_test.create(app).run();
54
+ // api_index.api_collections_list_test.create(app).run();
55
+ // api_index.api_collections_products_test.create(app).run();
56
+
57
+ // api_index.api_products_crud_test.create(app).run();
58
+ // api_index.api_products_collections_test.create(app).run();
59
+ // api_index.api_products_list_test.create(app).run();
60
+ // api_index.api_products_discounts_test.create(app).run();
61
+ // api_index.api_products_variants_test.create(app).run();
62
+
63
+ // api_index.api_shipping_crud_test.create(app).run();
64
+ // api_index.api_shipping_list_test.create(app).run();
65
+
66
+ // api_index.api_posts_crud_test.create(app).run();
67
+ // api_index.api_posts_list_test.create(app).run();
68
+
69
+ // api_index.api_customers_crud_test.create(app).run();
70
+ // api_index.api_customers_list_test.create(app).run();
71
+
72
+ // api_index.api_orders_crud_test.create(app).run();
73
+ // api_index.api_orders_list_test.create(app).run();
74
+
75
+ // api_index.api_storefronts_crud_test.create(app).run();
76
+ // api_index.api_storefronts_list_test.create(app).run();
77
+ // api_index.api_storefronts_all_connections_test.create(app).run();
78
+
79
+ // api_index.api_notifications_crud_test.create(app).run();
80
+ // api_index.api_notifications_list_test.create(app).run();
81
+
82
+ // api_index.api_images_crud_test.create(app).run();
83
+ // api_index.api_images_list_test.create(app).run();
84
+
85
+ // api_index.api_discounts_crud_test.create(app).run();
86
+ // api_index.api_discounts_list_test.create(app).run();
87
+ // api_index.api_discounts_products_test.create(app).run();
88
+
89
+
90
+ }
91
+
92
+ // test2();
@@ -0,0 +1,73 @@
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
+
package/tsconfig.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "compilerOptions": {
3
+ "checkJs": true,
4
+ "allowJs": true,
5
+ "maxNodeModuleJsDepth": 10,
6
+ "moduleResolution": "NodeNext",
7
+ "module": "NodeNext",
8
+ "composite": true,
9
+ },
10
+ "include": [
11
+ "*.js",
12
+ "src/*",
13
+ "migrations.sqlite/*",
14
+ "migrations.postgres/*",
15
+ "migrations.mysql/*",
16
+ "test/*.js"
17
+ ]
18
+ }
@@ -0,0 +1,21 @@
1
+ import Database from 'better-sqlite3';
2
+
3
+ export { SQLite } from './index.js';
4
+
5
+ export type SqlDialectType = 'SQLITE' | 'POSTGRES' | 'MYSQL';
6
+
7
+ /**
8
+ * @description The Storecraft SQLite config
9
+ */
10
+ export type Config = {
11
+ /**
12
+ * @description Database filename, can be ':memory' for in memory session
13
+ *
14
+ */
15
+ filename: string,
16
+
17
+ /**
18
+ * @description `better-sqlite` options
19
+ */
20
+ options?: Database.Options;
21
+ }