Skip to content

Commit 5dc884b

Browse files
committed
fix: sync actions to be in write mode over read only mode
1 parent 80ec14a commit 5dc884b

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
# Changelog
2+
## [4.0.0-alpha.3](https://github.com/maxgaurav/indexeddb-orm/releases/tag/v4.0.0-alpha.3)
3+
4+
### Fixed
5+
- The sync actions kept staying in read only transaction mode causing write or update action to fail.
6+
- Using findOrCreate and findIndexOrCreate internally rather than find check and create.
7+
28
## [4.0.0-alpha.2](https://github.com/maxgaurav/indexeddb-orm/releases/tag/v4.0.0-alpha.2)
39

410
### Changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "indexeddb-orm",
3-
"version": "4.0.0-alpha.2",
3+
"version": "4.0.0-alpha.3",
44
"main": "./dist/index.js",
55
"types": "./src/index.d.ts",
66
"scripts": {

src/models/model.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,7 @@ export class Model extends FindOrCreateActions implements ModelInterface {
3737
*/
3838
public async sync<T>(id: any, data: any, mergeDeep?: boolean): Promise<T>;
3939
public async sync(id: any, data: any, mergeDeep = true): Promise<any> {
40-
const existing = !!(await this.find(id));
41-
if (!existing) {
42-
return this.create(data);
43-
}
40+
await this.findOrCreate(id, data);
4441
await this.save(id, this.syncObj(data), mergeDeep);
4542
return this.find(id);
4643
}
@@ -65,10 +62,7 @@ export class Model extends FindOrCreateActions implements ModelInterface {
6562
data: any,
6663
mergeDeep = true,
6764
): Promise<any> {
68-
const existing = !!(await this.findIndex(indexName, id));
69-
if (!existing) {
70-
return this.create(data);
71-
}
65+
await this.findIndexOrCreate(indexName, id, data);
7266
await this.saveIndex(indexName, id, this.syncObj(data), mergeDeep);
7367
return this.findIndex(indexName, id);
7468
}

0 commit comments

Comments
 (0)