Skip to content

Commit 8e27cc7

Browse files
committed
feat(model): add findOrCreate method
1 parent 04cf727 commit 8e27cc7

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

src/database/drivers/FakeDriver.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,19 @@ export class FakeDriver {
373373
return data
374374
}
375375

376+
/**
377+
* Find a value in database or create a new one if it doesn't exist.
378+
*/
379+
public static async findOrCreate(data: Partial<any>): Promise<any> {
380+
const hasValue = await this.find()
381+
382+
if (hasValue) {
383+
return hasValue
384+
}
385+
386+
return this.create(data)
387+
}
388+
376389
/**
377390
* Find a value in database or execute closure.
378391
*/

0 commit comments

Comments
 (0)