Skip to content

Commit

Permalink
fix: params.adapter.Model race condition (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
FossPrime authored Sep 27, 2023
1 parent cf1e585 commit d786b9f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Advanced

- [Contributors Replit](https://replit.com/@fossprime/feathers-lowdb)
- [Bypass hooks for semi-direct DB access](https://stackblitz.com/edit/feathers-v5-database-hookless?file=app.ts%3AL67)
- [Swap Model via hooks or params](https://stackblitz.com/edit/feathers-v5-adapter-swapping?file=app.ts)

## LowDB benefits over NeDB, SQLite and others

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "feathers-lowdb",
"description": "A LowDB feathers database adapter service with yaml and json support",
"type": "module",
"version": "1.0.0-alpha.11",
"version": "1.0.0-alpha.13",
"homepage": "https://vblip.com",
"main": "lib/src/index.js",
"types": "lib/src/index.d.ts",
Expand Down
7 changes: 5 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,16 @@ export class LowDBAdapter<
this._uId = this.options.startId
this.defaultModel = this.options.Model || new Low(yaml(options))
this.partition = options.partition
this.waitForDisk = !!(options.waitForDisk || this.partition)
}

async getModel(params: any) {
let model = this.defaultModel
let model
if (params.adapter?.Model) {
model = params.adapter.Model
this.waitForDisk = true
} else {
model = this.defaultModel
this.waitForDisk = !!(this.options.waitForDisk || this.partition)
}
if (model.data === null) {
await model.read()
Expand Down

0 comments on commit d786b9f

Please sign in to comment.