velocious 1.0.100 → 1.0.102
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/package.json +1 -1
- package/spec/dummy/src/model-bases/authentication-token.js +3 -4
- package/spec/dummy/src/model-bases/project-detail.js +3 -4
- package/spec/dummy/src/model-bases/project-translation.js +3 -4
- package/spec/dummy/src/model-bases/project.js +10 -16
- package/spec/dummy/src/model-bases/task.js +3 -4
- package/spec/dummy/src/model-bases/user.js +7 -12
- package/src/cli/base-command.js +1 -1
- package/src/configuration-types.js +7 -1
- package/src/configuration.js +2 -2
- package/src/database/drivers/base-column.js +8 -7
- package/src/database/drivers/base-columns-index.js +1 -1
- package/src/database/drivers/base-foreign-key.js +5 -5
- package/src/database/drivers/base-table.js +4 -4
- package/src/database/drivers/base.js +45 -23
- package/src/database/pool/base.js +5 -5
- package/src/database/query/base.js +1 -1
- package/src/database/query/from-base.js +2 -4
- package/src/database/query/index.js +31 -18
- package/src/database/query/order-base.js +1 -1
- package/src/database/query/select-base.js +1 -1
- package/src/database/query/where-base.js +1 -1
- package/src/database/record/index.js +444 -172
- package/src/database/record/instance-relationships/base.js +41 -44
- package/src/database/record/instance-relationships/belongs-to.js +15 -3
- package/src/database/record/instance-relationships/has-many.js +49 -28
- package/src/database/record/instance-relationships/has-one.js +22 -7
- package/src/database/record/relationships/base.js +35 -45
- package/src/database/record/relationships/belongs-to.js +13 -3
- package/src/database/record/relationships/has-many.js +8 -2
- package/src/database/record/relationships/has-one.js +8 -2
- package/src/database/record/validators/base.js +15 -3
- package/src/database/record/validators/presence.js +7 -0
- package/src/environment-handlers/base.js +7 -7
- package/src/environment-handlers/node/cli/commands/generate/base-models.js +5 -8
- package/src/environment-handlers/node.js +1 -2
- package/src/initializer.js +1 -1
- package/src/routes/base-route.js +1 -1
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
* @property {string[]} [columns]
|
|
24
24
|
* @property {{[key: string]: any}} [data]
|
|
25
25
|
* @property {boolean} [multiple]
|
|
26
|
-
* @property {boolean} [returnLastInsertedColumnNames]
|
|
26
|
+
* @property {boolean | string[]} [returnLastInsertedColumnNames]
|
|
27
27
|
* @property {Array<Array<any>>} [rows]
|
|
28
28
|
* @property {string} tableName
|
|
29
29
|
*/
|
|
@@ -91,7 +91,7 @@ export default class VelociousDatabaseDriversBase {
|
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
/**
|
|
94
|
-
* @
|
|
94
|
+
* @abstract
|
|
95
95
|
* @param {import("../table-data/index.js").default} _tableData
|
|
96
96
|
* @returns {Promise<string[]>}
|
|
97
97
|
*/
|
|
@@ -100,7 +100,7 @@ export default class VelociousDatabaseDriversBase {
|
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
/**
|
|
103
|
-
* @
|
|
103
|
+
* @abstract
|
|
104
104
|
* @returns {Promise<void>}
|
|
105
105
|
*/
|
|
106
106
|
connect() {
|
|
@@ -108,7 +108,7 @@ export default class VelociousDatabaseDriversBase {
|
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
/**
|
|
111
|
-
* @
|
|
111
|
+
* @abstract
|
|
112
112
|
* @param {CreateIndexSqlArgs} indexData
|
|
113
113
|
* @returns {string}
|
|
114
114
|
*/
|
|
@@ -129,7 +129,7 @@ export default class VelociousDatabaseDriversBase {
|
|
|
129
129
|
}
|
|
130
130
|
|
|
131
131
|
/**
|
|
132
|
-
* @
|
|
132
|
+
* @abstract
|
|
133
133
|
* @param {import("../table-data/index.js").default} tableData
|
|
134
134
|
* @returns {string[]}
|
|
135
135
|
*/
|
|
@@ -148,7 +148,7 @@ export default class VelociousDatabaseDriversBase {
|
|
|
148
148
|
}
|
|
149
149
|
|
|
150
150
|
/**
|
|
151
|
-
* @
|
|
151
|
+
* @abstract
|
|
152
152
|
* @param {DeleteSqlArgsType} args
|
|
153
153
|
* @returns {string}
|
|
154
154
|
*/
|
|
@@ -170,7 +170,7 @@ export default class VelociousDatabaseDriversBase {
|
|
|
170
170
|
}
|
|
171
171
|
|
|
172
172
|
/**
|
|
173
|
-
* @
|
|
173
|
+
* @abstract
|
|
174
174
|
* @param {string} tableName
|
|
175
175
|
* @param {DropTableSqlArgsType} [args]
|
|
176
176
|
* @returns {string}
|
|
@@ -180,7 +180,7 @@ export default class VelociousDatabaseDriversBase {
|
|
|
180
180
|
}
|
|
181
181
|
|
|
182
182
|
/**
|
|
183
|
-
* @
|
|
183
|
+
* @abstract
|
|
184
184
|
* @param {any} value
|
|
185
185
|
* @returns {any}
|
|
186
186
|
*/
|
|
@@ -189,7 +189,7 @@ export default class VelociousDatabaseDriversBase {
|
|
|
189
189
|
}
|
|
190
190
|
|
|
191
191
|
/**
|
|
192
|
-
* @returns {
|
|
192
|
+
* @returns {import("../../configuration-types.js").DatabaseConfigurationType}
|
|
193
193
|
*/
|
|
194
194
|
getArgs() {
|
|
195
195
|
return this._args
|
|
@@ -212,7 +212,7 @@ export default class VelociousDatabaseDriversBase {
|
|
|
212
212
|
}
|
|
213
213
|
|
|
214
214
|
/**
|
|
215
|
-
* @
|
|
215
|
+
* @abstract
|
|
216
216
|
* @returns {Array<import("./base-table.js").default>}
|
|
217
217
|
*/
|
|
218
218
|
getTables() {
|
|
@@ -227,15 +227,27 @@ export default class VelociousDatabaseDriversBase {
|
|
|
227
227
|
*/
|
|
228
228
|
async getTableByName(name, args) {
|
|
229
229
|
const tables = await this.getTables()
|
|
230
|
-
const
|
|
230
|
+
const tableNames = []
|
|
231
|
+
let table
|
|
231
232
|
|
|
232
|
-
|
|
233
|
+
for (const candidate of tables) {
|
|
234
|
+
const candidateName = candidate.getName()
|
|
235
|
+
|
|
236
|
+
if (candidateName == name) {
|
|
237
|
+
table = candidate
|
|
238
|
+
break
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
tableNames.push(candidateName)
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
if (!table && args?.throwError !== false) throw new Error(`Couldn't find a table by that name "${name}" in: ${tableNames.join(", ")}`)
|
|
233
245
|
|
|
234
246
|
return table
|
|
235
247
|
}
|
|
236
248
|
|
|
237
249
|
/**
|
|
238
|
-
* @
|
|
250
|
+
* @abstract
|
|
239
251
|
* @returns {string}
|
|
240
252
|
*/
|
|
241
253
|
getType() {
|
|
@@ -253,7 +265,18 @@ export default class VelociousDatabaseDriversBase {
|
|
|
253
265
|
}
|
|
254
266
|
|
|
255
267
|
/**
|
|
256
|
-
* @
|
|
268
|
+
* @abstract
|
|
269
|
+
* @param {string} tableName
|
|
270
|
+
* @param {Array<string>} columns
|
|
271
|
+
* @param {Array<Array<string>>} rows
|
|
272
|
+
* @returns {Promise<void>}
|
|
273
|
+
*/
|
|
274
|
+
async insertMultiple(tableName, columns, rows) { // eslint-disable-line no-unused-vars
|
|
275
|
+
throw new Error("'insertMultiple' not implemented")
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* @abstract
|
|
257
280
|
* @param {InsertSqlArgsType} args
|
|
258
281
|
* @returns {string}
|
|
259
282
|
*/
|
|
@@ -262,7 +285,7 @@ export default class VelociousDatabaseDriversBase {
|
|
|
262
285
|
}
|
|
263
286
|
|
|
264
287
|
/**
|
|
265
|
-
* @
|
|
288
|
+
* @abstract
|
|
266
289
|
* @returns {Promise<number>}
|
|
267
290
|
*/
|
|
268
291
|
lastInsertID() {
|
|
@@ -282,7 +305,7 @@ export default class VelociousDatabaseDriversBase {
|
|
|
282
305
|
}
|
|
283
306
|
|
|
284
307
|
/**
|
|
285
|
-
* @
|
|
308
|
+
* @abstract
|
|
286
309
|
* @returns {import("../query-parser/options.js").default}
|
|
287
310
|
*/
|
|
288
311
|
options() {
|
|
@@ -361,7 +384,7 @@ export default class VelociousDatabaseDriversBase {
|
|
|
361
384
|
}
|
|
362
385
|
|
|
363
386
|
/**
|
|
364
|
-
* @
|
|
387
|
+
* @abstract
|
|
365
388
|
* @returns {boolean}
|
|
366
389
|
*/
|
|
367
390
|
shouldSetAutoIncrementWhenPrimaryKey() {
|
|
@@ -498,7 +521,7 @@ export default class VelociousDatabaseDriversBase {
|
|
|
498
521
|
}
|
|
499
522
|
|
|
500
523
|
/**
|
|
501
|
-
* @
|
|
524
|
+
* @abstract
|
|
502
525
|
* @param {string} sql
|
|
503
526
|
* @returns {Promise<QueryResultType>}
|
|
504
527
|
*/
|
|
@@ -507,14 +530,13 @@ export default class VelociousDatabaseDriversBase {
|
|
|
507
530
|
}
|
|
508
531
|
|
|
509
532
|
/**
|
|
510
|
-
* @
|
|
533
|
+
* @abstract
|
|
511
534
|
* @param {Query} _query
|
|
512
535
|
* @returns {string}
|
|
513
536
|
*/
|
|
514
537
|
queryToSql(_query) { throw new Error("queryToSql not implemented") } // eslint-disable-line no-unused-vars
|
|
515
538
|
|
|
516
539
|
/**
|
|
517
|
-
* @interface
|
|
518
540
|
* @param {Error} _error
|
|
519
541
|
* @returns {boolean}
|
|
520
542
|
*/
|
|
@@ -674,7 +696,7 @@ export default class VelociousDatabaseDriversBase {
|
|
|
674
696
|
}
|
|
675
697
|
|
|
676
698
|
/**
|
|
677
|
-
* @
|
|
699
|
+
* @abstract
|
|
678
700
|
* @param {UpdateSqlArgsType} args
|
|
679
701
|
* @returns {string}
|
|
680
702
|
*/
|
|
@@ -683,7 +705,7 @@ export default class VelociousDatabaseDriversBase {
|
|
|
683
705
|
}
|
|
684
706
|
|
|
685
707
|
/**
|
|
686
|
-
* @
|
|
708
|
+
* @abstract
|
|
687
709
|
* @returns {Promise<void>}
|
|
688
710
|
*/
|
|
689
711
|
disableForeignKeys() {
|
|
@@ -691,7 +713,7 @@ export default class VelociousDatabaseDriversBase {
|
|
|
691
713
|
}
|
|
692
714
|
|
|
693
715
|
/**
|
|
694
|
-
* @
|
|
716
|
+
* @abstract
|
|
695
717
|
* @returns {Promise<void>}
|
|
696
718
|
*/
|
|
697
719
|
enableForeignKeys() {
|
|
@@ -36,7 +36,7 @@ class VelociousDatabasePoolBase {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
|
-
* @
|
|
39
|
+
* @abstract
|
|
40
40
|
* @param {import("../drivers/base.js").default} _connection
|
|
41
41
|
*/
|
|
42
42
|
checkin(_connection) { // eslint-disable-line no-unused-vars
|
|
@@ -44,7 +44,7 @@ class VelociousDatabasePoolBase {
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
/**
|
|
47
|
-
* @
|
|
47
|
+
* @abstract
|
|
48
48
|
* @returns {Promise<import("../drivers/base.js").default>}
|
|
49
49
|
*/
|
|
50
50
|
checkout() {
|
|
@@ -52,7 +52,7 @@ class VelociousDatabasePoolBase {
|
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
/**
|
|
55
|
-
* @
|
|
55
|
+
* @abstract
|
|
56
56
|
* @returns {import("../drivers/base.js").default}
|
|
57
57
|
*/
|
|
58
58
|
getCurrentConnection() {
|
|
@@ -67,7 +67,7 @@ class VelociousDatabasePoolBase {
|
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
/**
|
|
70
|
-
* @
|
|
70
|
+
* @abstract
|
|
71
71
|
* @returns {string}
|
|
72
72
|
*/
|
|
73
73
|
primaryKeyType() {
|
|
@@ -119,7 +119,7 @@ class VelociousDatabasePoolBase {
|
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
/**
|
|
122
|
-
* @
|
|
122
|
+
* @abstract
|
|
123
123
|
* @param {function(import("../drivers/base.js").default) : void} _callback
|
|
124
124
|
* @returns {Promise<void>}
|
|
125
125
|
*/
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
|
|
3
|
-
import Query from "./index.js"
|
|
4
|
-
|
|
5
3
|
export default class VelociousDatabaseQueryFromBase {
|
|
6
|
-
/** @type {
|
|
4
|
+
/** @type {import("./index.js").default | null} */
|
|
7
5
|
query = null
|
|
8
6
|
|
|
9
7
|
/**
|
|
@@ -24,7 +22,7 @@ export default class VelociousDatabaseQueryFromBase {
|
|
|
24
22
|
}
|
|
25
23
|
|
|
26
24
|
/**
|
|
27
|
-
* @
|
|
25
|
+
* @abstract
|
|
28
26
|
* @returns {string[]}
|
|
29
27
|
*/
|
|
30
28
|
toSql() {
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* @typedef {{[key: string]: boolean | NestedPreloadRecord }} NestedPreloadRecord
|
|
5
|
+
* @typedef {string|SelectPlain} SelectArgumentType
|
|
6
|
+
* @typedef {object|string} WhereArgumentType
|
|
7
|
+
*/
|
|
8
|
+
|
|
3
9
|
import FromPlain from "./from-plain.js"
|
|
4
10
|
import {incorporate} from "incorporator"
|
|
5
11
|
import * as inflection from "inflection"
|
|
@@ -16,10 +22,6 @@ import WhereHash from "./where-hash.js"
|
|
|
16
22
|
import WherePlain from "./where-plain.js"
|
|
17
23
|
import restArgsError from "../../utils/rest-args-error.js"
|
|
18
24
|
|
|
19
|
-
/**
|
|
20
|
-
* @typedef {{[key: string]: boolean | NestedPreloadRecord }} NestedPreloadRecord
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
25
|
/**
|
|
24
26
|
* A generic query over some model type.
|
|
25
27
|
*/
|
|
@@ -112,7 +114,7 @@ export default class VelociousDatabaseQuery {
|
|
|
112
114
|
*/
|
|
113
115
|
async count() {
|
|
114
116
|
// Generate count SQL
|
|
115
|
-
let sql = `COUNT(${this.driver.quoteTable(this.
|
|
117
|
+
let sql = `COUNT(${this.driver.quoteTable(this.getModelClass().tableName())}.${this.driver.quoteColumn(this.getModelClass().primaryKey())})`
|
|
116
118
|
|
|
117
119
|
if (this.driver.getType() == "pgsql") sql += "::int"
|
|
118
120
|
|
|
@@ -162,6 +164,15 @@ export default class VelociousDatabaseQuery {
|
|
|
162
164
|
return this._groups
|
|
163
165
|
}
|
|
164
166
|
|
|
167
|
+
/**
|
|
168
|
+
* @returns {typeof import("../record/index.js").default}
|
|
169
|
+
*/
|
|
170
|
+
getModelClass() {
|
|
171
|
+
if (!this.modelClass) throw new Error("modelClass not set")
|
|
172
|
+
|
|
173
|
+
return this.modelClass
|
|
174
|
+
}
|
|
175
|
+
|
|
165
176
|
/**
|
|
166
177
|
* @returns {import("../query-parser/options.js").default}
|
|
167
178
|
*/
|
|
@@ -191,13 +202,13 @@ export default class VelociousDatabaseQuery {
|
|
|
191
202
|
/** @type {{[key: string]: number | string}} */
|
|
192
203
|
const conditions = {}
|
|
193
204
|
|
|
194
|
-
conditions[this.
|
|
205
|
+
conditions[this.getModelClass().primaryKey()] = recordId
|
|
195
206
|
|
|
196
207
|
const query = this.clone().where(conditions)
|
|
197
208
|
const record = await query.first()
|
|
198
209
|
|
|
199
210
|
if (!record) {
|
|
200
|
-
throw new RecordNotFoundError(`Couldn't find ${this.
|
|
211
|
+
throw new RecordNotFoundError(`Couldn't find ${this.getModelClass().name} with '${this.getModelClass().primaryKey()}'=${recordId}`)
|
|
201
212
|
}
|
|
202
213
|
|
|
203
214
|
return record
|
|
@@ -268,7 +279,8 @@ export default class VelociousDatabaseQuery {
|
|
|
268
279
|
|
|
269
280
|
if (record) return record
|
|
270
281
|
|
|
271
|
-
const
|
|
282
|
+
const ModelClass = this.getModelClass()
|
|
283
|
+
const newRecord = new ModelClass(conditions)
|
|
272
284
|
|
|
273
285
|
if (callback) {
|
|
274
286
|
callback(newRecord)
|
|
@@ -281,14 +293,14 @@ export default class VelociousDatabaseQuery {
|
|
|
281
293
|
* @returns {Promise<import("../record/index.js").default>}
|
|
282
294
|
*/
|
|
283
295
|
async first() {
|
|
284
|
-
const newQuery = this.clone().limit(1).reorder(`${this.driver.quoteTable(this.
|
|
296
|
+
const newQuery = this.clone().limit(1).reorder(`${this.driver.quoteTable(this.getModelClass().tableName())}.${this.driver.quoteColumn(this.getModelClass().orderableColumn())}`)
|
|
285
297
|
const results = await newQuery.toArray()
|
|
286
298
|
|
|
287
299
|
return results[0]
|
|
288
300
|
}
|
|
289
301
|
|
|
290
302
|
/**
|
|
291
|
-
* @param {string|
|
|
303
|
+
* @param {string|import("./from-base.js").default} from
|
|
292
304
|
* @returns {this}
|
|
293
305
|
*/
|
|
294
306
|
from(from) {
|
|
@@ -327,8 +339,8 @@ export default class VelociousDatabaseQuery {
|
|
|
327
339
|
* @returns {Promise<import("../record/index.js").default>}
|
|
328
340
|
*/
|
|
329
341
|
async last() {
|
|
330
|
-
const primaryKey = this.
|
|
331
|
-
const tableName = this.
|
|
342
|
+
const primaryKey = this.getModelClass().primaryKey()
|
|
343
|
+
const tableName = this.getModelClass().tableName()
|
|
332
344
|
const results = await this.clone().reorder(`${this.driver.quoteTable(tableName)}.${this.driver.quoteColumn(primaryKey)} DESC`).limit(1).toArray()
|
|
333
345
|
|
|
334
346
|
return results[0]
|
|
@@ -353,7 +365,7 @@ export default class VelociousDatabaseQuery {
|
|
|
353
365
|
}
|
|
354
366
|
|
|
355
367
|
/**
|
|
356
|
-
* @param {
|
|
368
|
+
* @param {string | number} order
|
|
357
369
|
* @returns {this}
|
|
358
370
|
*/
|
|
359
371
|
order(order) {
|
|
@@ -393,7 +405,7 @@ export default class VelociousDatabaseQuery {
|
|
|
393
405
|
}
|
|
394
406
|
|
|
395
407
|
/**
|
|
396
|
-
* @param {
|
|
408
|
+
* @param {NestedPreloadRecord} data
|
|
397
409
|
* @returns {this}
|
|
398
410
|
*/
|
|
399
411
|
preload(data) {
|
|
@@ -402,7 +414,7 @@ export default class VelociousDatabaseQuery {
|
|
|
402
414
|
}
|
|
403
415
|
|
|
404
416
|
/**
|
|
405
|
-
* @param {string|
|
|
417
|
+
* @param {string | number} order
|
|
406
418
|
* @returns {this}
|
|
407
419
|
*/
|
|
408
420
|
reorder(order) {
|
|
@@ -423,7 +435,7 @@ export default class VelociousDatabaseQuery {
|
|
|
423
435
|
}
|
|
424
436
|
|
|
425
437
|
/**
|
|
426
|
-
* @param {
|
|
438
|
+
* @param {SelectArgumentType} select
|
|
427
439
|
* @returns {this}
|
|
428
440
|
*/
|
|
429
441
|
select(select) {
|
|
@@ -474,7 +486,8 @@ export default class VelociousDatabaseQuery {
|
|
|
474
486
|
const results = await this.results()
|
|
475
487
|
|
|
476
488
|
for (const result of results) {
|
|
477
|
-
const
|
|
489
|
+
const ModelClass = this.getModelClass()
|
|
490
|
+
const model = new ModelClass()
|
|
478
491
|
|
|
479
492
|
model.loadExistingRecord(result)
|
|
480
493
|
models.push(model)
|
|
@@ -500,7 +513,7 @@ export default class VelociousDatabaseQuery {
|
|
|
500
513
|
toSql() { return this.driver.queryToSql(this) }
|
|
501
514
|
|
|
502
515
|
/**
|
|
503
|
-
* @param {
|
|
516
|
+
* @param {WhereArgumentType} where
|
|
504
517
|
* @returns {VelociousDatabaseQuery} This query instance
|
|
505
518
|
*/
|
|
506
519
|
where(where) {
|