@reldens/storage 0.22.0 → 0.24.0

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.
@@ -71,6 +71,11 @@ class BaseDriver
71
71
  ErrorManager.error('BaseDriver updateById() not implemented.');
72
72
  }
73
73
 
74
+ upsert(params, filters)
75
+ {
76
+ ErrorManager.error('BaseDriver upsert() not implemented.');
77
+ }
78
+
74
79
  delete(filters)
75
80
  {
76
81
  ErrorManager.error('BaseDriver delete() not implemented.');
@@ -56,7 +56,7 @@ class ObjectionJsDataServer extends BaseDataServer
56
56
  for(let i of Object.keys(this.rawEntities)){
57
57
  let rawEntity = this.rawEntities[i];
58
58
  if(!rawEntity?.knex){
59
- Logger.critical('Invalid raw entity ""'+i+'".');
59
+ Logger.critical('Invalid raw entity "'+i+'".');
60
60
  continue;
61
61
  }
62
62
  this.entities[i] = new ObjectionJsDriver({rawModel: rawEntity, id: i, name: i, config: rawEntity.knex});
@@ -64,12 +64,33 @@ class ObjectionJsDriver extends BaseDriver
64
64
  return this.queryBuilder().patchAndFetchById(id, params);
65
65
  }
66
66
 
67
- deleteBy(filters)
67
+ async upsert(params, filters)
68
+ {
69
+ if(params.id){
70
+ let patch = Object.assign({}, params);
71
+ delete patch.id;
72
+ return this.queryBuilder().patchAndFetchById(params.id, patch).onConflict().merge();
73
+ }
74
+ if(filters){
75
+ let existent = await this.loadOne(filters);
76
+ if(existent){
77
+ return this.queryBuilder().patchAndFetchById(existent.id, params).onConflict().merge();
78
+ }
79
+ }
80
+ return this.create(params);
81
+ }
82
+
83
+ delete(filters)
68
84
  {
69
85
  let queryBuilder = this.queryBuilder(true, true, true);
70
86
  return this.appendFilters(queryBuilder, filters).delete();
71
87
  }
72
88
 
89
+ deleteBy(filters)
90
+ {
91
+ this.delete(filters);
92
+ }
93
+
73
94
  deleteById(id)
74
95
  {
75
96
  return this.queryBuilder().deleteById(id);
@@ -144,6 +165,10 @@ class ObjectionJsDriver extends BaseDriver
144
165
  return this.queryBuilder().findByIds(ids);
145
166
  }
146
167
 
168
+ /**
169
+ * @param filters
170
+ * @returns {*}
171
+ */
147
172
  loadOne(filters)
148
173
  {
149
174
  let queryBuilder = this.queryBuilder(false, true, true);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@reldens/storage",
3
3
  "scope": "@reldens",
4
- "version": "0.22.0",
4
+ "version": "0.24.0",
5
5
  "description": "Reldens - Storage",
6
6
  "author": "Damian A. Pastorini",
7
7
  "license": "MIT",