@nattyjs/orm 0.0.1-beta.43 → 0.0.1-beta.45
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/dist/index.cjs +65 -43
- package/dist/index.mjs +65 -43
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -169,9 +169,10 @@ function getColumnNameAndParams$1(config) {
|
|
|
169
169
|
const params = new Array();
|
|
170
170
|
const relationProps = /* @__PURE__ */ new Map();
|
|
171
171
|
if (config.entity) {
|
|
172
|
-
for (const key of Object.keys(config.
|
|
173
|
-
|
|
174
|
-
|
|
172
|
+
for (const key of Object.keys(config.properties)) {
|
|
173
|
+
const propName = config.properties[key];
|
|
174
|
+
if (config.entity[propName] !== void 0) {
|
|
175
|
+
const paramValue = config.entity[propName];
|
|
175
176
|
if (!(Utils.isObject(paramValue) || Utils.isArray(paramValue))) {
|
|
176
177
|
columnNames.push(key);
|
|
177
178
|
params.push({
|
|
@@ -241,18 +242,22 @@ function getColumnNameAndParams(config) {
|
|
|
241
242
|
if (config.entity) {
|
|
242
243
|
let index = 1;
|
|
243
244
|
let parameterCharacter = isMsSql ? "@" : "$";
|
|
244
|
-
for (const
|
|
245
|
-
const
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
245
|
+
for (const prop of Object.keys(config.properties)) {
|
|
246
|
+
const key = config.properties[prop];
|
|
247
|
+
const value = config.entity[key];
|
|
248
|
+
if (value !== void 0) {
|
|
249
|
+
const paramProp = isMsSql ? key : index;
|
|
250
|
+
if (!(Utils.isObject(value) || Utils.isArray(value))) {
|
|
251
|
+
if (config.primaryKeys.indexOf(key) === -1)
|
|
252
|
+
sets.push(`${key}=${parameterCharacter}${paramProp}`);
|
|
253
|
+
else
|
|
254
|
+
whereClause.push(`${key}=${parameterCharacter}${paramProp}`);
|
|
255
|
+
index++;
|
|
256
|
+
params.push({
|
|
257
|
+
name: `${key}`,
|
|
258
|
+
value
|
|
259
|
+
});
|
|
260
|
+
}
|
|
256
261
|
}
|
|
257
262
|
}
|
|
258
263
|
}
|
|
@@ -842,27 +847,36 @@ class DbSet {
|
|
|
842
847
|
}
|
|
843
848
|
async add(entity) {
|
|
844
849
|
const properties = this.getProperties();
|
|
845
|
-
this.changeTracker.addItem(
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
850
|
+
this.changeTracker.addItem(
|
|
851
|
+
{
|
|
852
|
+
tableName: this.getTableName(this.type.name),
|
|
853
|
+
entity,
|
|
854
|
+
primaryKeys: this.getPrimaryKeys(this.type.name),
|
|
855
|
+
propsDbConfig: this.getPropsDbConfig(entity),
|
|
856
|
+
properties
|
|
857
|
+
},
|
|
858
|
+
EntityState.added
|
|
859
|
+
);
|
|
852
860
|
}
|
|
853
861
|
async update(entity) {
|
|
854
|
-
this.changeTracker.addItem(
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
862
|
+
this.changeTracker.addItem(
|
|
863
|
+
{
|
|
864
|
+
tableName: this.getTableName(this.type.name),
|
|
865
|
+
entity,
|
|
866
|
+
primaryKeys: this.getPrimaryKeys(this.type.name),
|
|
867
|
+
propsDbConfig: this.getPropsDbConfig(entity)
|
|
868
|
+
},
|
|
869
|
+
EntityState.updated
|
|
870
|
+
);
|
|
860
871
|
}
|
|
861
872
|
async delete(expression) {
|
|
862
|
-
this.changeTracker.addItem(
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
873
|
+
this.changeTracker.addItem(
|
|
874
|
+
{
|
|
875
|
+
tableName: this.getTableName(this.type.name),
|
|
876
|
+
whereClause: expression
|
|
877
|
+
},
|
|
878
|
+
EntityState.deleted
|
|
879
|
+
);
|
|
866
880
|
}
|
|
867
881
|
async toList() {
|
|
868
882
|
return await this.execute();
|
|
@@ -884,22 +898,30 @@ class DbSet {
|
|
|
884
898
|
const props = core.entityContainer.getProperties(name || this.type.name);
|
|
885
899
|
const jProps = {};
|
|
886
900
|
if (props)
|
|
887
|
-
props.forEach(
|
|
901
|
+
props.forEach(
|
|
902
|
+
(property) => jProps[property.name.toLowerCase()] = property.name
|
|
903
|
+
);
|
|
888
904
|
return jProps;
|
|
889
905
|
}
|
|
890
906
|
getPropsDbConfig(entity) {
|
|
891
907
|
const propsDbConfig = core.entityContainer.getPropsDbConfig(this.type.name);
|
|
908
|
+
const properties = core.entityContainer.getProperties(this.type.name);
|
|
892
909
|
const props = /* @__PURE__ */ new Map();
|
|
893
|
-
|
|
894
|
-
const
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
910
|
+
if (properties && Array.isArray(properties)) {
|
|
911
|
+
for (const property of properties) {
|
|
912
|
+
if (entity[property.name]) {
|
|
913
|
+
const propName = entity[property.name];
|
|
914
|
+
const dbFieldConfig = propsDbConfig.get(propName);
|
|
915
|
+
if (dbFieldConfig && (dbFieldConfig.oneToMany || dbFieldConfig.oneToOne)) {
|
|
916
|
+
const fieldRelationConfig = dbFieldConfig.oneToMany || dbFieldConfig.oneToOne;
|
|
917
|
+
props.set(propName, {
|
|
918
|
+
tableName: this.getTableName(fieldRelationConfig.model.name),
|
|
919
|
+
primaryKeys: this.getPrimaryKeys(fieldRelationConfig.model.name),
|
|
920
|
+
foreignKey: fieldRelationConfig.foreignKey,
|
|
921
|
+
properties: this.getProperties(fieldRelationConfig.model.name)
|
|
922
|
+
});
|
|
923
|
+
}
|
|
924
|
+
}
|
|
903
925
|
}
|
|
904
926
|
}
|
|
905
927
|
return props;
|
package/dist/index.mjs
CHANGED
|
@@ -152,9 +152,10 @@ function getColumnNameAndParams$1(config) {
|
|
|
152
152
|
const params = new Array();
|
|
153
153
|
const relationProps = /* @__PURE__ */ new Map();
|
|
154
154
|
if (config.entity) {
|
|
155
|
-
for (const key of Object.keys(config.
|
|
156
|
-
|
|
157
|
-
|
|
155
|
+
for (const key of Object.keys(config.properties)) {
|
|
156
|
+
const propName = config.properties[key];
|
|
157
|
+
if (config.entity[propName] !== void 0) {
|
|
158
|
+
const paramValue = config.entity[propName];
|
|
158
159
|
if (!(Utils.isObject(paramValue) || Utils.isArray(paramValue))) {
|
|
159
160
|
columnNames.push(key);
|
|
160
161
|
params.push({
|
|
@@ -224,18 +225,22 @@ function getColumnNameAndParams(config) {
|
|
|
224
225
|
if (config.entity) {
|
|
225
226
|
let index = 1;
|
|
226
227
|
let parameterCharacter = isMsSql ? "@" : "$";
|
|
227
|
-
for (const
|
|
228
|
-
const
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
228
|
+
for (const prop of Object.keys(config.properties)) {
|
|
229
|
+
const key = config.properties[prop];
|
|
230
|
+
const value = config.entity[key];
|
|
231
|
+
if (value !== void 0) {
|
|
232
|
+
const paramProp = isMsSql ? key : index;
|
|
233
|
+
if (!(Utils.isObject(value) || Utils.isArray(value))) {
|
|
234
|
+
if (config.primaryKeys.indexOf(key) === -1)
|
|
235
|
+
sets.push(`${key}=${parameterCharacter}${paramProp}`);
|
|
236
|
+
else
|
|
237
|
+
whereClause.push(`${key}=${parameterCharacter}${paramProp}`);
|
|
238
|
+
index++;
|
|
239
|
+
params.push({
|
|
240
|
+
name: `${key}`,
|
|
241
|
+
value
|
|
242
|
+
});
|
|
243
|
+
}
|
|
239
244
|
}
|
|
240
245
|
}
|
|
241
246
|
}
|
|
@@ -825,27 +830,36 @@ class DbSet {
|
|
|
825
830
|
}
|
|
826
831
|
async add(entity) {
|
|
827
832
|
const properties = this.getProperties();
|
|
828
|
-
this.changeTracker.addItem(
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
833
|
+
this.changeTracker.addItem(
|
|
834
|
+
{
|
|
835
|
+
tableName: this.getTableName(this.type.name),
|
|
836
|
+
entity,
|
|
837
|
+
primaryKeys: this.getPrimaryKeys(this.type.name),
|
|
838
|
+
propsDbConfig: this.getPropsDbConfig(entity),
|
|
839
|
+
properties
|
|
840
|
+
},
|
|
841
|
+
EntityState.added
|
|
842
|
+
);
|
|
835
843
|
}
|
|
836
844
|
async update(entity) {
|
|
837
|
-
this.changeTracker.addItem(
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
845
|
+
this.changeTracker.addItem(
|
|
846
|
+
{
|
|
847
|
+
tableName: this.getTableName(this.type.name),
|
|
848
|
+
entity,
|
|
849
|
+
primaryKeys: this.getPrimaryKeys(this.type.name),
|
|
850
|
+
propsDbConfig: this.getPropsDbConfig(entity)
|
|
851
|
+
},
|
|
852
|
+
EntityState.updated
|
|
853
|
+
);
|
|
843
854
|
}
|
|
844
855
|
async delete(expression) {
|
|
845
|
-
this.changeTracker.addItem(
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
856
|
+
this.changeTracker.addItem(
|
|
857
|
+
{
|
|
858
|
+
tableName: this.getTableName(this.type.name),
|
|
859
|
+
whereClause: expression
|
|
860
|
+
},
|
|
861
|
+
EntityState.deleted
|
|
862
|
+
);
|
|
849
863
|
}
|
|
850
864
|
async toList() {
|
|
851
865
|
return await this.execute();
|
|
@@ -867,22 +881,30 @@ class DbSet {
|
|
|
867
881
|
const props = entityContainer.getProperties(name || this.type.name);
|
|
868
882
|
const jProps = {};
|
|
869
883
|
if (props)
|
|
870
|
-
props.forEach(
|
|
884
|
+
props.forEach(
|
|
885
|
+
(property) => jProps[property.name.toLowerCase()] = property.name
|
|
886
|
+
);
|
|
871
887
|
return jProps;
|
|
872
888
|
}
|
|
873
889
|
getPropsDbConfig(entity) {
|
|
874
890
|
const propsDbConfig = entityContainer.getPropsDbConfig(this.type.name);
|
|
891
|
+
const properties = entityContainer.getProperties(this.type.name);
|
|
875
892
|
const props = /* @__PURE__ */ new Map();
|
|
876
|
-
|
|
877
|
-
const
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
893
|
+
if (properties && Array.isArray(properties)) {
|
|
894
|
+
for (const property of properties) {
|
|
895
|
+
if (entity[property.name]) {
|
|
896
|
+
const propName = entity[property.name];
|
|
897
|
+
const dbFieldConfig = propsDbConfig.get(propName);
|
|
898
|
+
if (dbFieldConfig && (dbFieldConfig.oneToMany || dbFieldConfig.oneToOne)) {
|
|
899
|
+
const fieldRelationConfig = dbFieldConfig.oneToMany || dbFieldConfig.oneToOne;
|
|
900
|
+
props.set(propName, {
|
|
901
|
+
tableName: this.getTableName(fieldRelationConfig.model.name),
|
|
902
|
+
primaryKeys: this.getPrimaryKeys(fieldRelationConfig.model.name),
|
|
903
|
+
foreignKey: fieldRelationConfig.foreignKey,
|
|
904
|
+
properties: this.getProperties(fieldRelationConfig.model.name)
|
|
905
|
+
});
|
|
906
|
+
}
|
|
907
|
+
}
|
|
886
908
|
}
|
|
887
909
|
}
|
|
888
910
|
return props;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nattyjs/orm",
|
|
3
|
-
"version": "0.0.1-beta.
|
|
3
|
+
"version": "0.0.1-beta.45",
|
|
4
4
|
"description": "",
|
|
5
5
|
"module": "./dist/index.mjs",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -19,9 +19,9 @@
|
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"pg": "8.16.0",
|
|
21
21
|
"mssql": "^9.1.1",
|
|
22
|
-
"@nattyjs/core": "0.0.1-beta.
|
|
23
|
-
"@nattyjs/common": "0.0.1-beta.
|
|
24
|
-
"@nattyjs/entity": "0.0.1-beta.
|
|
25
|
-
"@nattyjs/types": "0.0.1-beta.
|
|
22
|
+
"@nattyjs/core": "0.0.1-beta.45",
|
|
23
|
+
"@nattyjs/common": "0.0.1-beta.45",
|
|
24
|
+
"@nattyjs/entity": "0.0.1-beta.45",
|
|
25
|
+
"@nattyjs/types": "0.0.1-beta.45"
|
|
26
26
|
}
|
|
27
27
|
}
|