Skip to content

Commit 4fb4673

Browse files
authored
fix(model): delete method should be synchronous (#76) (#77)
fix #76 In addition, tests are revised to reflect the synchronous behavior.
1 parent e115503 commit 4fb4673

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

src/model/Model.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ export class Model {
489489
/**
490490
* Delete the model from the database.
491491
*/
492-
async $delete(): Promise<boolean> {
492+
$delete(): boolean {
493493
const key = this.$getKeyName()
494494

495495
return isArray(key)
@@ -500,21 +500,21 @@ export class Model {
500500
/**
501501
* Delete the model from the database by ID.
502502
*/
503-
protected async $deleteByKeyName(key: string): Promise<boolean> {
504-
return !!(await this.$query().destroy(this[key]))
503+
protected $deleteByKeyName(key: string): boolean {
504+
return !!this.$query().destroy(this[key])
505505
}
506506

507507
/**
508508
* Delete the model from the database by composite key.
509509
*/
510-
protected async $deleteByCompositeKeyName(keys: string[]): Promise<boolean> {
510+
protected $deleteByCompositeKeyName(keys: string[]): boolean {
511511
const query = this.$query()
512512

513513
keys.forEach((key) => {
514514
query.where(key, this[key])
515515
})
516516

517-
return (await query.delete()).length > 0
517+
return query.delete().length > 0
518518
}
519519

520520
/**

test/feature/model/deletes_delete.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('feature/model/deletes_delete', () => {
2020

2121
const user = store.$repo(User).find(1)!
2222

23-
const result = await user.$delete()
23+
const result = user.$delete()
2424

2525
expect(result).toBe(true)
2626

test/feature/model/deletes_delete_composite_key.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe('feature/model/deletes_delete_composite_key', () => {
2323

2424
const user = store.$repo(User).where('idA', 1).where('idB', 2).first()!
2525

26-
const result = await user.$delete()
26+
const result = user.$delete()
2727

2828
expect(result).toBe(true)
2929

test/feature/relations/has_many_save.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ describe('feature/relations/has_many_save', () => {
5353
it('generates missing foreign key', async () => {
5454
const store = createStore()
5555

56-
await store.$repo(User).save({
56+
store.$repo(User).save({
5757
id: 1,
5858
name: 'John Doe',
5959
posts: [
@@ -76,7 +76,7 @@ describe('feature/relations/has_many_save', () => {
7676
it('can insert a record with missing relational key', async () => {
7777
const store = createStore()
7878

79-
await store.$repo(User).save({
79+
store.$repo(User).save({
8080
id: 1,
8181
name: 'John Doe'
8282
})

0 commit comments

Comments
 (0)