@reldens/storage 0.5.0-beta.7 → 0.10.0-beta.21

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.
package/index.js CHANGED
@@ -6,18 +6,21 @@
6
6
 
7
7
  const { BaseDataServer } = require('./lib/base-data-server');
8
8
  const { BaseDriver } = require('./lib/base-driver');
9
- const { ObjectionJsDriver } = require('./lib/objection-js-driver');
10
- const { ObjectionJsDataServer } = require('./lib/objection-js-data-server');
11
- const { MikroOrmDriver } = require('./lib/mikro-orm-driver');
12
- const { ModelClassDeprecated } = require('./lib/objection-js-model-deprecated');
9
+ const { ObjectionJsDriver } = require('./lib/objection-js/objection-js-driver');
10
+ const { ObjectionJsDataServer } = require('./lib/objection-js/objection-js-data-server');
11
+ const { Model } = require('objection');
12
+ const { MikroOrmDriver } = require('./lib/mikro-orm/mikro-orm-driver');
13
+ const { MikroOrmDataServer } = require('./lib/mikro-orm/mikro-orm-data-server');
13
14
 
14
15
  module.exports = {
15
- ModelClassDeprecated: ModelClassDeprecated,
16
- // databases:
16
+ // base:
17
17
  BaseDataServer: BaseDataServer,
18
- ObjectionJsDataServer: ObjectionJsDataServer,
19
- // drivers:
20
18
  BaseDriver: BaseDriver,
19
+ // objection-js:
20
+ ObjectionJsDataServer: ObjectionJsDataServer,
21
21
  ObjectionJsDriver: ObjectionJsDriver,
22
+ ObjectionJsRawModel: Model,
23
+ // mikro-orm:
24
+ MikroOrmDataServer: MikroOrmDataServer,
22
25
  MikroOrmDriver: MikroOrmDriver
23
26
  };
@@ -34,6 +34,11 @@ class BaseDataServer
34
34
  ErrorManager.error('BaseDriver generateEntities() not implemented.');
35
35
  }
36
36
 
37
+ getEntity(entityName)
38
+ {
39
+ return this.entityManager.get(entityName);
40
+ }
41
+
37
42
  }
38
43
 
39
44
  module.exports.BaseDataServer = BaseDataServer;
@@ -4,7 +4,7 @@
4
4
  *
5
5
  */
6
6
 
7
- const { ErrorManager, sc } = require('@reldens/utils');
7
+ const { ErrorManager, sc, Logger} = require('@reldens/utils');
8
8
 
9
9
  class BaseDriver
10
10
  {
@@ -27,99 +27,108 @@ class BaseDriver
27
27
  ErrorManager.error('BaseDriver name() not implemented.');
28
28
  }
29
29
 
30
- async create(params)
30
+ create(params)
31
31
  {
32
32
  ErrorManager.error('BaseDriver create() not implemented.');
33
33
  }
34
34
 
35
- async update(filters, updatePatch)
35
+ createWithRelations(params, relations)
36
+ {
37
+ ErrorManager.error('BaseDriver create() not implemented.');
38
+ }
39
+
40
+ update(filters, updatePatch)
36
41
  {
37
42
  ErrorManager.error('BaseDriver update() not implemented.');
38
43
  }
39
44
 
40
- async updateBy(field, fieldValue, updatePatch)
45
+ updateBy(field, fieldValue, updatePatch)
41
46
  {
42
47
  ErrorManager.error('BaseDriver updateBy() not implemented.');
43
48
  }
44
49
 
45
- async updateById(id, params)
50
+ updateById(id, params)
46
51
  {
47
52
  ErrorManager.error('BaseDriver updateById() not implemented.');
48
53
  }
49
54
 
50
- async delete(id)
55
+ delete(id)
51
56
  {
52
57
  ErrorManager.error('BaseDriver delete() not implemented.');
53
58
  }
54
59
 
55
- async count(filters)
60
+ count(filters)
56
61
  {
57
62
  ErrorManager.error('BaseDriver count() not implemented.');
58
63
  }
59
64
 
60
- async loadAll()
65
+ loadAll()
61
66
  {
62
67
  ErrorManager.error('BaseDriver loadAll() not implemented.');
63
68
  }
64
69
 
65
- async loadAllWithRelations(relations)
70
+ loadAllWithRelations(relations)
66
71
  {
67
72
  ErrorManager.error('BaseDriver loadAllWithRelations() not implemented.');
68
73
  }
69
74
 
70
- async load(filters)
75
+ load(filters)
71
76
  {
72
77
  ErrorManager.error('BaseDriver load() not implemented.');
73
78
  }
74
79
 
75
- async loadWithRelations(filters, relations)
80
+ loadWithRelations(filters, relations)
76
81
  {
77
82
  ErrorManager.error('BaseDriver loadWithRelations() not implemented.');
78
83
  }
79
84
 
80
- async loadBy(field, value)
85
+ loadBy(field, value)
81
86
  {
82
87
  ErrorManager.error('BaseDriver loadBy() not implemented.');
83
88
  }
84
89
 
85
- async loadByWithRelations(field, value, relations)
90
+ loadByWithRelations(field, value, relations)
86
91
  {
87
92
  ErrorManager.error('BaseDriver loadByWithRelations() not implemented.');
88
93
  }
89
94
 
90
- async loadById(id)
95
+ loadById(id)
91
96
  {
92
97
  ErrorManager.error('BaseDriver loadById() not implemented.');
93
98
  }
94
99
 
95
- async loadByIdWithRelations(id, relations)
100
+ loadByIdWithRelations(id, relations)
96
101
  {
97
102
  ErrorManager.error('BaseDriver loadByIdWithRelations() not implemented.');
98
103
  }
99
104
 
100
- async loadOne(filters)
105
+ loadOne(filters)
101
106
  {
102
107
  ErrorManager.error('BaseDriver load() not implemented.');
103
108
  }
104
109
 
105
- async loadOneWithRelations(filters, relations)
110
+ loadOneWithRelations(filters, relations)
106
111
  {
107
112
  ErrorManager.error('BaseDriver loadWithRelations() not implemented.');
108
113
  }
109
114
 
110
- async loadOneBy(field, value)
115
+ loadOneBy(field, value)
111
116
  {
112
117
  ErrorManager.error('BaseDriver loadBy() not implemented.');
113
118
  }
114
119
 
115
- async loadOneByWithRelations(field, value, relations)
120
+ loadOneByWithRelations(field, value, relations)
116
121
  {
117
122
  ErrorManager.error('BaseDriver loadByWithRelations() not implemented.');
118
123
  }
119
124
 
120
- async orderBy(result)
125
+ executeCustomQuery(methodName)
121
126
  {
122
- ErrorManager.error('BaseDriver orderBy() not implemented.');
127
+ if(typeof this.rawModel[methodName] !== 'function'){
128
+ Logger.error('Custom query method not found in raw model.', methodName, this.rawModel);
129
+ return false;
130
+ }
131
+ return this.rawModel[methodName]();
123
132
  }
124
133
 
125
134
  }
@@ -0,0 +1,20 @@
1
+ /**
2
+ *
3
+ * Reldens - MikroOrmDataServer
4
+ *
5
+ */
6
+
7
+ const { BaseDataServer } = require('../base-data-server');
8
+
9
+ class MikroOrmDataServer extends BaseDataServer
10
+ {
11
+
12
+ constructor(props)
13
+ {
14
+ super(props);
15
+ // @TODO: implement.
16
+ }
17
+
18
+ }
19
+
20
+ module.exports.MikroOrmDataServer = MikroOrmDataServer;
@@ -4,7 +4,7 @@
4
4
  *
5
5
  */
6
6
 
7
- const { BaseDriver } = require('./base-driver');
7
+ const { BaseDriver } = require('../base-driver');
8
8
 
9
9
  class MikroOrmDriver extends BaseDriver
10
10
  {
@@ -4,11 +4,10 @@
4
4
  *
5
5
  */
6
6
 
7
- const { BaseDataServer } = require('./base-data-server');
8
- const { ModelClassDeprecated } = require('./objection-js-model-deprecated');
7
+ const { BaseDataServer } = require('../base-data-server');
9
8
  const { ObjectionJsDriver } = require('./objection-js-driver');
9
+ const { Model } = require('objection');
10
10
  const Knex = require('knex');
11
- const { sc } = require('@reldens/utils');
12
11
 
13
12
  class ObjectionJsDataServer extends BaseDataServer
14
13
  {
@@ -16,8 +15,10 @@ class ObjectionJsDataServer extends BaseDataServer
16
15
  constructor(props)
17
16
  {
18
17
  super(props);
19
- this.rawModel = sc.getDef(props, 'rawModel', ModelClassDeprecated);
20
18
  this.knex = false;
19
+ if(!this.rawModel){
20
+ this.rawModel = Model;
21
+ }
21
22
  }
22
23
 
23
24
  connect()
@@ -4,7 +4,7 @@
4
4
  *
5
5
  */
6
6
 
7
- const { BaseDriver } = require('./base-driver');
7
+ const { BaseDriver } = require('../base-driver');
8
8
  const { sc } = require('@reldens/utils');
9
9
 
10
10
  class ObjectionJsDriver extends BaseDriver
@@ -25,105 +25,101 @@ class ObjectionJsDriver extends BaseDriver
25
25
  return this.name || this.rawModel.tableName;
26
26
  }
27
27
 
28
- async create(params)
28
+ create(params)
29
29
  {
30
30
  this.rawModel.query().insert(params);
31
31
  }
32
32
 
33
- async update(filters, updatePatch)
33
+ createWithRelations(params, relations)
34
+ {
35
+ return this.rawModel.query().insertGraphAndFetch(params);
36
+ }
37
+
38
+ update(filters, updatePatch)
34
39
  {
35
40
  return this.rawModel.query().patch(updatePatch).where(filters);
36
41
  }
37
42
 
38
- async updateBy(field, fieldValue, updatePatch)
43
+ updateBy(field, fieldValue, updatePatch)
39
44
  {
40
45
  return this.rawModel.query().patch(updatePatch).where(field, fieldValue);
41
46
  }
42
47
 
43
- async updateById(id, params)
48
+ updateById(id, params)
44
49
  {
45
- return this.rawModel.query().patch(params).where(this.id, id);
50
+ return this.rawModel.query().patchAndFetchById(id, params);
46
51
  }
47
52
 
48
- async delete(id)
53
+ delete(id)
49
54
  {
50
- return this.rawModel.delete().where(this.id, id);
55
+ return this.rawModel.query().deleteById(id);
51
56
  }
52
57
 
53
- async count(filters)
58
+ count(filters)
54
59
  {
55
60
  return this.rawModel.query().count().where(filters);
56
61
  }
57
62
 
58
- async loadAll()
63
+ loadAll()
59
64
  {
60
65
  return this.rawModel.query();
61
66
  }
62
67
 
63
- async loadAllWithRelations(relations)
68
+ loadAllWithRelations(relations)
64
69
  {
65
70
  return this.appendRelationsToQuery(this.rawModel.query(), relations);
66
71
  }
67
72
 
68
- async load(filters)
73
+ load(filters)
69
74
  {
70
75
  return this.rawModel.query().where(filters);
71
76
  }
72
77
 
73
- async loadWithRelations(filters, relations)
78
+ loadWithRelations(filters, relations)
74
79
  {
75
80
  return this.appendRelationsToQuery(this.rawModel.query().where(filters), relations);
76
81
  }
77
82
 
78
- async loadBy(field, value)
83
+ loadBy(field, value)
79
84
  {
80
85
  return this.rawModel.query().where(field, value);
81
86
  }
82
87
 
83
- async loadByWithRelations(field, value, relations)
88
+ loadByWithRelations(field, value, relations)
84
89
  {
85
90
  return this.appendRelationsToQuery(this.rawModel.query().where(field, value), relations);
86
91
  }
87
92
 
88
- async loadById(id)
93
+ loadById(id)
89
94
  {
90
95
  return this.rawModel.query().findById(id);
91
96
  }
92
97
 
93
- async loadByIdWithRelations(id, relations)
98
+ loadByIdWithRelations(id, relations)
94
99
  {
95
100
  return this.appendRelationsToQuery(this.rawModel.query().findById(id), relations);
96
101
  }
97
102
 
98
- async loadOne(filters)
103
+ loadOne(filters)
99
104
  {
100
105
  return this.rawModel.query().where(filters).limit(1).first();
101
106
  }
102
107
 
103
- async loadOneWithRelations(filters, relations)
108
+ loadOneWithRelations(filters, relations)
104
109
  {
105
110
  return this.appendRelationsToQuery(this.rawModel.query().where(field, value), relations).limit(1).first();
106
111
  }
107
112
 
108
- async loadOneBy(field, value)
113
+ loadOneBy(field, value)
109
114
  {
110
115
  return this.rawModel.query().where(field, value).first();
111
116
  }
112
117
 
113
- async loadOneByWithRelations(field, value, relations)
118
+ loadOneByWithRelations(field, value, relations)
114
119
  {
115
120
  return this.appendRelationsToQuery(this.rawModel.query().where(field, value), relations).limit(1).first();
116
121
  }
117
122
 
118
- async orderBy(result, fieldName)
119
- {
120
- return result.modifiers({
121
- orderByKey(builder){
122
- builder.orderBy(fieldName);
123
- }
124
- });
125
- }
126
-
127
123
  appendRelationsToQuery(queryBuilder, relations)
128
124
  {
129
125
  if(!sc.isArray(relations) || relations.length === 0){
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@reldens/storage",
3
3
  "scope": "@reldens",
4
- "version": "0.5.0-beta.7",
4
+ "version": "0.10.0-beta.21",
5
5
  "description": "Reldens - Storage",
6
6
  "author": "Damian A. Pastorini",
7
7
  "license": "MIT",
@@ -15,8 +15,12 @@
15
15
  "keywords": [
16
16
  "reldens",
17
17
  "storage",
18
+ "objection",
18
19
  "objectionjs",
20
+ "objection-js",
21
+ "mikro",
19
22
  "mikroorm",
23
+ "mikro-orm",
20
24
  "driver",
21
25
  "orm",
22
26
  "database",
@@ -40,9 +44,9 @@
40
44
  "url": "https://github.com/damian-pastorini/reldens-storage/issues"
41
45
  },
42
46
  "dependencies": {
43
- "@reldens/utils": "^0.4.6",
44
- "knex": "^0.21.21",
45
- "objection": "^2.2.15",
47
+ "@reldens/utils": "^0.5.0",
48
+ "knex": "^0.95.14",
49
+ "objection": "^3.0.0",
46
50
  "mysql": "^2.18.1"
47
51
  }
48
52
  }
@@ -1,51 +0,0 @@
1
- /**
2
- *
3
- * Reldens - ObjectionModel
4
- *
5
- * Objection JS Model wrapper.
6
- *
7
- */
8
-
9
- const { Model } = require('objection');
10
-
11
- class ObjectionJsModelDeprecated extends Model
12
- {
13
-
14
- static loadAll(withRelations)
15
- {
16
- let result = this.query();
17
- let relations = Object.keys(this.relationMappings || {});
18
- if(withRelations === true && relations){
19
- result.withGraphFetched('['+relations.join(',')+']');
20
- }
21
- return result;
22
- }
23
-
24
- static loadById(id, withRelations)
25
- {
26
- let result = this.query();
27
- let relations = Object.keys(this.relationMappings || {});
28
- if(withRelations === true && relations.length > 0){
29
- result.withGraphFetched('['+relations.join(',')+']');
30
- }
31
- return result.findById(id);
32
- }
33
-
34
- static loadBy(field, value, withRelations)
35
- {
36
- let result = this.query();
37
- let relations = Object.keys((this.relationMappings || {}));
38
- if(withRelations === true && relations.length > 0){
39
- result.withGraphFetched('['+relations.join(',')+']');
40
- }
41
- return result.where(field, value);
42
- }
43
-
44
- static updateBy(field, fieldValue, updatePatch)
45
- {
46
- return this.query().patch(updatePatch).where(field, fieldValue);
47
- }
48
-
49
- }
50
-
51
- module.exports.ModelClassDeprecated = ObjectionJsModelDeprecated;