@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 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.entity)) {
173
- if (config.properties[key.toLowerCase()]) {
174
- const paramValue = config.entity[key];
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 [key, value] of Object.entries(config.entity)) {
245
- const paramProp = isMsSql ? key : index;
246
- if (!(Utils.isObject(value) || Utils.isArray(value))) {
247
- if (config.primaryKeys.indexOf(key) === -1)
248
- sets.push(`${key}=${parameterCharacter}${paramProp}`);
249
- else
250
- whereClause.push(`${key}=${parameterCharacter}${paramProp}`);
251
- index++;
252
- params.push({
253
- name: `${key}`,
254
- value
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
- tableName: this.getTableName(this.type.name),
847
- entity,
848
- primaryKeys: this.getPrimaryKeys(this.type.name),
849
- propsDbConfig: this.getPropsDbConfig(entity),
850
- properties
851
- }, EntityState.added);
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
- tableName: this.getTableName(this.type.name),
856
- entity,
857
- primaryKeys: this.getPrimaryKeys(this.type.name),
858
- propsDbConfig: this.getPropsDbConfig(entity)
859
- }, EntityState.updated);
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
- tableName: this.getTableName(this.type.name),
864
- whereClause: expression
865
- }, EntityState.deleted);
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((property) => jProps[property.name.toLowerCase()] = property.name);
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
- for (const propName of Object.keys(entity)) {
894
- const dbFieldConfig = propsDbConfig.get(propName);
895
- if (dbFieldConfig && (dbFieldConfig.oneToMany || dbFieldConfig.oneToOne)) {
896
- const fieldRelationConfig = dbFieldConfig.oneToMany || dbFieldConfig.oneToOne;
897
- props.set(propName, {
898
- tableName: this.getTableName(fieldRelationConfig.model.name),
899
- primaryKeys: this.getPrimaryKeys(fieldRelationConfig.model.name),
900
- foreignKey: fieldRelationConfig.foreignKey,
901
- properties: this.getProperties(fieldRelationConfig.model.name)
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.entity)) {
156
- if (config.properties[key.toLowerCase()]) {
157
- const paramValue = config.entity[key];
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 [key, value] of Object.entries(config.entity)) {
228
- const paramProp = isMsSql ? key : index;
229
- if (!(Utils.isObject(value) || Utils.isArray(value))) {
230
- if (config.primaryKeys.indexOf(key) === -1)
231
- sets.push(`${key}=${parameterCharacter}${paramProp}`);
232
- else
233
- whereClause.push(`${key}=${parameterCharacter}${paramProp}`);
234
- index++;
235
- params.push({
236
- name: `${key}`,
237
- value
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
- tableName: this.getTableName(this.type.name),
830
- entity,
831
- primaryKeys: this.getPrimaryKeys(this.type.name),
832
- propsDbConfig: this.getPropsDbConfig(entity),
833
- properties
834
- }, EntityState.added);
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
- tableName: this.getTableName(this.type.name),
839
- entity,
840
- primaryKeys: this.getPrimaryKeys(this.type.name),
841
- propsDbConfig: this.getPropsDbConfig(entity)
842
- }, EntityState.updated);
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
- tableName: this.getTableName(this.type.name),
847
- whereClause: expression
848
- }, EntityState.deleted);
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((property) => jProps[property.name.toLowerCase()] = property.name);
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
- for (const propName of Object.keys(entity)) {
877
- const dbFieldConfig = propsDbConfig.get(propName);
878
- if (dbFieldConfig && (dbFieldConfig.oneToMany || dbFieldConfig.oneToOne)) {
879
- const fieldRelationConfig = dbFieldConfig.oneToMany || dbFieldConfig.oneToOne;
880
- props.set(propName, {
881
- tableName: this.getTableName(fieldRelationConfig.model.name),
882
- primaryKeys: this.getPrimaryKeys(fieldRelationConfig.model.name),
883
- foreignKey: fieldRelationConfig.foreignKey,
884
- properties: this.getProperties(fieldRelationConfig.model.name)
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.43",
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.43",
23
- "@nattyjs/common": "0.0.1-beta.43",
24
- "@nattyjs/entity": "0.0.1-beta.43",
25
- "@nattyjs/types": "0.0.1-beta.43"
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
  }