velocious 1.0.15 → 1.0.16
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
CHANGED
|
@@ -14,4 +14,19 @@ describe("Record - destroy", () => {
|
|
|
14
14
|
expect(foundTask).toEqual(undefined)
|
|
15
15
|
})
|
|
16
16
|
})
|
|
17
|
+
|
|
18
|
+
it("destroys all records in a collection", async () => {
|
|
19
|
+
await Dummy.run(async () => {
|
|
20
|
+
const task1 = await Task.create({name: "Test task 1"})
|
|
21
|
+
const task2 = await Task.create({name: "Test task 2"})
|
|
22
|
+
|
|
23
|
+
await Task.where({id: task1.id()}).destroyAll()
|
|
24
|
+
|
|
25
|
+
const foundTask1 = await Task.where({id: task1.id()}).first()
|
|
26
|
+
const foundTask2 = await Task.where({id: task2.id()}).first()
|
|
27
|
+
|
|
28
|
+
expect(foundTask1).toEqual(undefined)
|
|
29
|
+
expect(foundTask2).toBeDefined()
|
|
30
|
+
})
|
|
31
|
+
})
|
|
17
32
|
})
|
|
@@ -47,6 +47,14 @@ export default class VelociousDatabaseQuery {
|
|
|
47
47
|
|
|
48
48
|
getOptions = () => this.driver.options()
|
|
49
49
|
|
|
50
|
+
async destroyAll() {
|
|
51
|
+
const records = await this.toArray()
|
|
52
|
+
|
|
53
|
+
for (const record of records) {
|
|
54
|
+
await record.destroy()
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
50
58
|
async find(recordId) {
|
|
51
59
|
const conditions = {}
|
|
52
60
|
|
|
@@ -457,6 +457,10 @@ export default class VelociousDatabaseRecord {
|
|
|
457
457
|
return this._newQuery()
|
|
458
458
|
}
|
|
459
459
|
|
|
460
|
+
static async destroyAll(...args) {
|
|
461
|
+
return this._newQuery().destroyAll(...args)
|
|
462
|
+
}
|
|
463
|
+
|
|
460
464
|
static async find(...args) {
|
|
461
465
|
return this._newQuery().find(...args)
|
|
462
466
|
}
|