@storecraft/database-sql-base 1.2.5 → 1.3.0

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.
@@ -58,7 +58,8 @@ const get = (driver) => {
58
58
  const result = await driver.client
59
59
  .selectFrom(table_name)
60
60
  .selectAll()
61
- .select(eb => [
61
+ .select(
62
+ eb => [
62
63
  with_media(eb, id_or_handle, driver.dialectType),
63
64
  with_tags(eb, id_or_handle, driver.dialectType),
64
65
  with_search(eb, id_or_handle, driver.dialectType),
@@ -33,10 +33,9 @@ export const create_app = async () => {
33
33
  dialect: dialect,
34
34
  dialect_type: 'MYSQL'
35
35
  })
36
- )
36
+ ).init();
37
37
 
38
- await app.init();
39
- await migrateToLatest(app.db, false);
38
+ await migrateToLatest(app._.db, false);
40
39
 
41
40
  return app;
42
41
  }
@@ -46,11 +45,11 @@ async function test() {
46
45
 
47
46
  Object.entries(api).slice(0, -1).forEach(
48
47
  ([name, runner]) => {
49
- runner.create(app).run();
48
+ runner.create(app._.app).run();
50
49
  }
51
50
  );
52
- const last_test = Object.values(api).at(-1).create(app);
53
- last_test.after(async () => { await app.db.disconnect() });
51
+ const last_test = Object.values(api).at(-1).create(app._.app);
52
+ last_test.after(async () => { await app._.disconnect() });
54
53
  last_test.run();
55
54
  }
56
55
 
@@ -33,10 +33,9 @@ export const create_app = async () => {
33
33
  dialect: pg_dialect,
34
34
  dialect_type: 'POSTGRES'
35
35
  })
36
- );
36
+ ).init();
37
37
 
38
- await app.init();
39
- await migrateToLatest(app.db, false);
38
+ await migrateToLatest(app._.db, false);
40
39
 
41
40
  return app;
42
41
  }
@@ -46,11 +45,11 @@ async function test() {
46
45
 
47
46
  Object.entries(api).slice(0, -1).forEach(
48
47
  ([name, runner]) => {
49
- runner.create(app).run();
48
+ runner.create(app._.app).run();
50
49
  }
51
50
  );
52
- const last_test = Object.values(api).at(-1).create(app);
53
- last_test.after(async () => { await app.db.disconnect() });
51
+ const last_test = Object.values(api).at(-1).create(app._.app);
52
+ last_test.after(async () => { await app._.disconnect() });
54
53
  last_test.run();
55
54
  }
56
55
 
@@ -29,10 +29,9 @@ export const create_app = async () => {
29
29
  dialect: sqlite_dialect,
30
30
  dialect_type: 'SQLITE'
31
31
  })
32
- );
32
+ ).init();
33
33
 
34
- await app.init();
35
- await migrateToLatest(app.db, false);
34
+ await migrateToLatest(app._.db, false);
36
35
 
37
36
  return app;
38
37
  }
@@ -42,11 +41,11 @@ async function test() {
42
41
 
43
42
  Object.entries(api).slice(0, -1).forEach(
44
43
  ([name, runner]) => {
45
- runner.create(app).run();
44
+ runner.create(app._.app).run();
46
45
  }
47
46
  );
48
- const last_test = Object.values(api).at(-1).create(app);
49
- last_test.after(async () => { await app.db.disconnect() });
47
+ const last_test = Object.values(api).at(-1).create(app._.app);
48
+ last_test.after(async () => { await app._.disconnect() });
50
49
  last_test.run();
51
50
  }
52
51
 
package/tests/sandbox.js CHANGED
@@ -32,10 +32,9 @@ export const create_app = async () => {
32
32
  dialect: sqlite_dialect,
33
33
  dialect_type: 'SQLITE'
34
34
  })
35
- );
35
+ ).init();
36
36
 
37
- await app.init();
38
- await migrateToLatest(app.db, false);
37
+ await migrateToLatest(app._.db, false);
39
38
 
40
39
  return app;
41
40
  }
@@ -65,7 +64,8 @@ const resource_to_props = (
65
64
 
66
65
  async function test() {
67
66
  const app = await create_app();
68
- const client = app.db.client;
67
+ const client = app._.db.client;
68
+ const dialectType = app._.db.dialectType;
69
69
  const limit = 0;
70
70
  const items = await client.selectNoFrom(
71
71
  eb => [
@@ -75,14 +75,14 @@ async function test() {
75
75
  .select(resource_to_props.collections)
76
76
  .select(
77
77
  eb => [
78
- with_tags(eb, eb.ref('collections.id'), app.db.dialectType),
79
- with_media(eb, eb.ref('collections.id'), app.db.dialectType),
78
+ with_tags(eb, eb.ref('collections.id'), dialectType),
79
+ with_media(eb, eb.ref('collections.id'), dialectType),
80
80
  ]
81
81
  )
82
82
  .where('active', '=', 1)
83
83
  .orderBy('updated_at', 'asc')
84
84
  .limit(limit),
85
- app.db.dialectType
85
+ dialectType
86
86
  ).as('collections'),
87
87
 
88
88
  jsonArrayFrom(
@@ -91,18 +91,18 @@ async function test() {
91
91
  .select(resource_to_props.products)
92
92
  .select(
93
93
  eb => [
94
- with_tags(eb, eb.ref('products.id'), app.db.dialectType),
95
- with_media(eb, eb.ref('products.id'), app.db.dialectType),
96
- products_with_collections(eb, eb.ref('products.id'), app.db.dialectType),
97
- products_with_discounts(eb, eb.ref('products.id'), app.db.dialectType),
98
- products_with_variants(eb, eb.ref('products.id'), app.db.dialectType),
99
- products_with_related_products(eb, eb.ref('products.id'), app.db.dialectType),
94
+ with_tags(eb, eb.ref('products.id'), dialectType),
95
+ with_media(eb, eb.ref('products.id'), dialectType),
96
+ products_with_collections(eb, eb.ref('products.id'), dialectType),
97
+ products_with_discounts(eb, eb.ref('products.id'), dialectType),
98
+ products_with_variants(eb, eb.ref('products.id'), dialectType),
99
+ products_with_related_products(eb, eb.ref('products.id'), dialectType),
100
100
  ]
101
101
  )
102
102
  .where('active', '=', 1)
103
103
  .orderBy('updated_at', 'asc')
104
104
  .limit(limit),
105
- app.db.dialectType
105
+ dialectType
106
106
  ).as('products'),
107
107
 
108
108
  jsonArrayFrom(
@@ -111,14 +111,14 @@ async function test() {
111
111
  .select(resource_to_props.discounts)
112
112
  .select(
113
113
  eb => [
114
- with_tags(eb, eb.ref('discounts.id'), app.db.dialectType),
115
- with_media(eb, eb.ref('discounts.id'), app.db.dialectType),
114
+ with_tags(eb, eb.ref('discounts.id'), dialectType),
115
+ with_media(eb, eb.ref('discounts.id'), dialectType),
116
116
  ]
117
117
  )
118
118
  .where('active', '=', 1)
119
119
  .orderBy('updated_at', 'asc')
120
120
  .limit(limit),
121
- app.db.dialectType
121
+ dialectType
122
122
  ).as('discounts'),
123
123
 
124
124
  jsonArrayFrom(
@@ -127,14 +127,14 @@ async function test() {
127
127
  .select(resource_to_props.shipping_methods)
128
128
  .select(
129
129
  eb => [
130
- with_tags(eb, eb.ref('shipping_methods.id'), app.db.dialectType),
131
- with_media(eb, eb.ref('shipping_methods.id'), app.db.dialectType),
130
+ with_tags(eb, eb.ref('shipping_methods.id'), dialectType),
131
+ with_media(eb, eb.ref('shipping_methods.id'), dialectType),
132
132
  ]
133
133
  )
134
134
  .where('active', '=', 1)
135
135
  .orderBy('updated_at', 'asc')
136
136
  .limit(limit),
137
- app.db.dialectType
137
+ dialectType
138
138
  ).as('shipping_methods'),
139
139
 
140
140
  jsonArrayFrom(
@@ -143,14 +143,14 @@ async function test() {
143
143
  .select(resource_to_props.posts)
144
144
  .select(
145
145
  eb => [
146
- with_tags(eb, eb.ref('posts.id'), app.db.dialectType),
147
- with_media(eb, eb.ref('posts.id'), app.db.dialectType),
146
+ with_tags(eb, eb.ref('posts.id'), dialectType),
147
+ with_media(eb, eb.ref('posts.id'), dialectType),
148
148
  ]
149
149
  )
150
150
  .where('active', '=', 1)
151
151
  .orderBy('updated_at', 'asc')
152
152
  .limit(limit),
153
- app.db.dialectType
153
+ dialectType
154
154
  ).as('posts'),
155
155
 
156
156
  stringArrayFrom(
@@ -167,7 +167,7 @@ async function test() {
167
167
  )
168
168
  .select('entity_to_tags_projections.value as tag')
169
169
  .groupBy('tag'),
170
- app.db.dialectType
170
+ dialectType
171
171
  ).as('all_products_tags')
172
172
  ]
173
173
  )
@@ -178,7 +178,7 @@ async function test() {
178
178
 
179
179
  async function test2() {
180
180
  const app = await create_app();
181
- const client = app.db.client;
181
+ const client = app._.db.client;
182
182
  const items = await client.selectNoFrom(
183
183
  eb => Object
184
184
  .entries(resource_to_props)
@@ -195,7 +195,7 @@ async function test2() {
195
195
  .select(props)
196
196
  .orderBy('updated_at', 'asc')
197
197
  .limit(0),
198
- app.db.dialectType
198
+ app._.db.dialectType
199
199
  ).as(table_name)
200
200
  }
201
201
  )