pure-orm 4.0.3 → 4.1.4
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/.benchmarks/bench-core-baseline.json +303 -0
- package/README.md +0 -7
- package/babel.config.js +4 -1
- package/coverage/clover.xml +1492 -1231
- package/coverage/coverage-final.json +103 -103
- package/coverage/lcov-report/dist/src/core.js.html +590 -383
- package/coverage/lcov-report/dist/src/driver-integrations/index.html +20 -20
- package/coverage/lcov-report/dist/src/driver-integrations/pgp.js.html +52 -52
- package/coverage/lcov-report/dist/src/index.html +28 -28
- package/coverage/lcov-report/dist/src/index.js.html +2 -2
- package/coverage/lcov-report/dist/src/orm.js.html +392 -209
- package/coverage/lcov-report/dist/test-utils/blog/entities.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/blog/index.html +1 -1
- package/coverage/lcov-report/dist/test-utils/blog/models/article.js.html +15 -15
- package/coverage/lcov-report/dist/test-utils/blog/models/article_tag.js.html +2 -2
- package/coverage/lcov-report/dist/test-utils/blog/models/index.html +1 -1
- package/coverage/lcov-report/dist/test-utils/blog/models/person.js.html +13 -13
- package/coverage/lcov-report/dist/test-utils/blog/models/tag.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/five/entities.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/five/index.html +1 -1
- package/coverage/lcov-report/dist/test-utils/five/models/index.html +1 -1
- package/coverage/lcov-report/dist/test-utils/five/models/line-item.js.html +4 -4
- package/coverage/lcov-report/dist/test-utils/five/models/order.js.html +3 -3
- package/coverage/lcov-report/dist/test-utils/five/models/parcel-event.js.html +6 -6
- package/coverage/lcov-report/dist/test-utils/five/models/parcel-line-item.js.html +7 -7
- package/coverage/lcov-report/dist/test-utils/five/models/parcel.js.html +2 -2
- package/coverage/lcov-report/dist/test-utils/fourteen/entities.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/fourteen/index.html +1 -1
- package/coverage/lcov-report/dist/test-utils/fourteen/models/customer.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/fourteen/models/index.html +1 -1
- package/coverage/lcov-report/dist/test-utils/fourteen/models/person.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/nine/entities.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/nine/index.html +1 -1
- package/coverage/lcov-report/dist/test-utils/nine/models/feature-switch.js.html +6 -6
- package/coverage/lcov-report/dist/test-utils/nine/models/index.html +1 -1
- package/coverage/lcov-report/dist/test-utils/order/entities.js.html +9 -9
- package/coverage/lcov-report/dist/test-utils/order/index.html +1 -1
- package/coverage/lcov-report/dist/test-utils/order/models/index.html +14 -14
- package/coverage/lcov-report/dist/test-utils/order/models/line-item.js.html +11 -11
- package/coverage/lcov-report/dist/test-utils/order/models/order.js.html +41 -41
- package/coverage/lcov-report/dist/test-utils/order/models/product-variant.js.html +18 -18
- package/coverage/lcov-report/dist/test-utils/order/models/product.js.html +17 -17
- package/coverage/lcov-report/dist/test-utils/order/models/utm-source.js.html +12 -12
- package/coverage/lcov-report/dist/test-utils/order-more/entities.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/order-more/index.html +1 -1
- package/coverage/lcov-report/dist/test-utils/order-more/models/actual-product-variant.js.html +3 -3
- package/coverage/lcov-report/dist/test-utils/order-more/models/color.js.html +6 -6
- package/coverage/lcov-report/dist/test-utils/order-more/models/customer.js.html +3 -3
- package/coverage/lcov-report/dist/test-utils/order-more/models/gender.js.html +4 -4
- package/coverage/lcov-report/dist/test-utils/order-more/models/index.html +23 -23
- package/coverage/lcov-report/dist/test-utils/order-more/models/inventory-level.js.html +11 -11
- package/coverage/lcov-report/dist/test-utils/order-more/models/line-item.js.html +15 -15
- package/coverage/lcov-report/dist/test-utils/order-more/models/order.js.html +39 -39
- package/coverage/lcov-report/dist/test-utils/order-more/models/parcel-event.js.html +6 -6
- package/coverage/lcov-report/dist/test-utils/order-more/models/parcel-line-item.js.html +7 -7
- package/coverage/lcov-report/dist/test-utils/order-more/models/parcel.js.html +2 -2
- package/coverage/lcov-report/dist/test-utils/order-more/models/physical-address.js.html +12 -12
- package/coverage/lcov-report/dist/test-utils/order-more/models/product-variant-image.js.html +7 -7
- package/coverage/lcov-report/dist/test-utils/order-more/models/product-variant.js.html +22 -22
- package/coverage/lcov-report/dist/test-utils/order-more/models/product.js.html +11 -11
- package/coverage/lcov-report/dist/test-utils/order-more/models/refund.js.html +11 -11
- package/coverage/lcov-report/dist/test-utils/order-more/models/shipment-actual-product-variant.js.html +9 -9
- package/coverage/lcov-report/dist/test-utils/order-more/models/shipment.js.html +4 -4
- package/coverage/lcov-report/dist/test-utils/order-more/models/size.js.html +4 -4
- package/coverage/lcov-report/dist/test-utils/order-more/models/utm-medium.js.html +15 -15
- package/coverage/lcov-report/dist/test-utils/order-more/models/utm-source.js.html +17 -17
- package/coverage/lcov-report/dist/test-utils/six/entities.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/six/index.html +1 -1
- package/coverage/lcov-report/dist/test-utils/six/models/customer.js.html +3 -3
- package/coverage/lcov-report/dist/test-utils/six/models/index.html +21 -21
- package/coverage/lcov-report/dist/test-utils/six/models/line-item.js.html +10 -10
- package/coverage/lcov-report/dist/test-utils/six/models/order.js.html +13 -13
- package/coverage/lcov-report/dist/test-utils/six/models/parcel-line-item.js.html +2 -2
- package/coverage/lcov-report/dist/test-utils/six/models/parcel.js.html +2 -2
- package/coverage/lcov-report/dist/test-utils/thirteen/entities.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/thirteen/index.html +1 -1
- package/coverage/lcov-report/dist/test-utils/thirteen/models/audience.js.html +2 -2
- package/coverage/lcov-report/dist/test-utils/thirteen/models/brand.js.html +2 -2
- package/coverage/lcov-report/dist/test-utils/thirteen/models/category.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/thirteen/models/index.html +14 -14
- package/coverage/lcov-report/dist/test-utils/thirteen/models/member.js.html +2 -2
- package/coverage/lcov-report/dist/test-utils/thirteen/models/passion.js.html +2 -2
- package/coverage/lcov-report/dist/test-utils/thirteen/models/product.js.html +10 -10
- package/coverage/lcov-report/dist/test-utils/thirteen/models/recommendation-audience.js.html +2 -2
- package/coverage/lcov-report/dist/test-utils/thirteen/models/recommendation.js.html +2 -2
- package/coverage/lcov-report/dist/test-utils/three/index.html +1 -1
- package/coverage/lcov-report/dist/test-utils/three/results.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/twelve/entities.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/twelve/index.html +1 -1
- package/coverage/lcov-report/dist/test-utils/twelve/models/index.html +1 -1
- package/coverage/lcov-report/dist/test-utils/twelve/models/member.js.html +1 -1
- package/coverage/lcov-report/dist/test-utils/twelve/models/prompt.js.html +2 -2
- package/coverage/lcov-report/dist/test-utils/two/index.html +1 -1
- package/coverage/lcov-report/dist/test-utils/two/results.js.html +1 -1
- package/coverage/lcov-report/index.html +103 -103
- package/coverage/lcov-report/src/core.ts.html +841 -415
- package/coverage/lcov-report/src/driver-integrations/index.html +20 -20
- package/coverage/lcov-report/src/driver-integrations/pgp.ts.html +58 -58
- package/coverage/lcov-report/src/index.html +28 -28
- package/coverage/lcov-report/src/index.ts.html +1 -1
- package/coverage/lcov-report/src/orm.ts.html +361 -298
- package/coverage/lcov-report/test-utils/blog/entities.ts.html +1 -1
- package/coverage/lcov-report/test-utils/blog/index.html +1 -1
- package/coverage/lcov-report/test-utils/blog/models/article.ts.html +15 -15
- package/coverage/lcov-report/test-utils/blog/models/article_tag.ts.html +2 -2
- package/coverage/lcov-report/test-utils/blog/models/index.html +1 -1
- package/coverage/lcov-report/test-utils/blog/models/person.ts.html +13 -13
- package/coverage/lcov-report/test-utils/blog/models/tag.ts.html +1 -1
- package/coverage/lcov-report/test-utils/five/entities.ts.html +1 -1
- package/coverage/lcov-report/test-utils/five/index.html +1 -1
- package/coverage/lcov-report/test-utils/five/models/index.html +1 -1
- package/coverage/lcov-report/test-utils/five/models/line-item.ts.html +4 -4
- package/coverage/lcov-report/test-utils/five/models/order.ts.html +3 -3
- package/coverage/lcov-report/test-utils/five/models/parcel-event.ts.html +6 -6
- package/coverage/lcov-report/test-utils/five/models/parcel-line-item.ts.html +7 -7
- package/coverage/lcov-report/test-utils/five/models/parcel.ts.html +2 -2
- package/coverage/lcov-report/test-utils/fourteen/entities.ts.html +1 -1
- package/coverage/lcov-report/test-utils/fourteen/index.html +1 -1
- package/coverage/lcov-report/test-utils/fourteen/models/customer.ts.html +1 -1
- package/coverage/lcov-report/test-utils/fourteen/models/index.html +1 -1
- package/coverage/lcov-report/test-utils/fourteen/models/person.ts.html +1 -1
- package/coverage/lcov-report/test-utils/nine/entities.ts.html +1 -1
- package/coverage/lcov-report/test-utils/nine/index.html +1 -1
- package/coverage/lcov-report/test-utils/nine/models/feature-switch.ts.html +8 -8
- package/coverage/lcov-report/test-utils/nine/models/index.html +1 -1
- package/coverage/lcov-report/test-utils/order/entities.ts.html +2 -2
- package/coverage/lcov-report/test-utils/order/index.html +1 -1
- package/coverage/lcov-report/test-utils/order/models/index.html +14 -14
- package/coverage/lcov-report/test-utils/order/models/line-item.ts.html +5 -5
- package/coverage/lcov-report/test-utils/order/models/order.ts.html +36 -36
- package/coverage/lcov-report/test-utils/order/models/product-variant.ts.html +13 -13
- package/coverage/lcov-report/test-utils/order/models/product.ts.html +13 -13
- package/coverage/lcov-report/test-utils/order/models/utm-source.ts.html +8 -8
- package/coverage/lcov-report/test-utils/order-more/entities.ts.html +1 -1
- package/coverage/lcov-report/test-utils/order-more/index.html +1 -1
- package/coverage/lcov-report/test-utils/order-more/models/actual-product-variant.ts.html +3 -3
- package/coverage/lcov-report/test-utils/order-more/models/color.ts.html +6 -6
- package/coverage/lcov-report/test-utils/order-more/models/customer.ts.html +3 -3
- package/coverage/lcov-report/test-utils/order-more/models/gender.ts.html +4 -4
- package/coverage/lcov-report/test-utils/order-more/models/index.html +23 -23
- package/coverage/lcov-report/test-utils/order-more/models/inventory-level.ts.html +11 -11
- package/coverage/lcov-report/test-utils/order-more/models/line-item.ts.html +15 -15
- package/coverage/lcov-report/test-utils/order-more/models/order.ts.html +45 -45
- package/coverage/lcov-report/test-utils/order-more/models/parcel-event.ts.html +6 -6
- package/coverage/lcov-report/test-utils/order-more/models/parcel-line-item.ts.html +7 -7
- package/coverage/lcov-report/test-utils/order-more/models/parcel.ts.html +2 -2
- package/coverage/lcov-report/test-utils/order-more/models/physical-address.ts.html +12 -12
- package/coverage/lcov-report/test-utils/order-more/models/product-variant-image.ts.html +7 -7
- package/coverage/lcov-report/test-utils/order-more/models/product-variant.ts.html +22 -22
- package/coverage/lcov-report/test-utils/order-more/models/product.ts.html +11 -11
- package/coverage/lcov-report/test-utils/order-more/models/refund.ts.html +11 -11
- package/coverage/lcov-report/test-utils/order-more/models/shipment-actual-product-variant.ts.html +9 -9
- package/coverage/lcov-report/test-utils/order-more/models/shipment.ts.html +4 -4
- package/coverage/lcov-report/test-utils/order-more/models/size.ts.html +4 -4
- package/coverage/lcov-report/test-utils/order-more/models/utm-medium.ts.html +15 -15
- package/coverage/lcov-report/test-utils/order-more/models/utm-source.ts.html +17 -17
- package/coverage/lcov-report/test-utils/six/entities.ts.html +1 -1
- package/coverage/lcov-report/test-utils/six/index.html +1 -1
- package/coverage/lcov-report/test-utils/six/models/customer.ts.html +3 -3
- package/coverage/lcov-report/test-utils/six/models/index.html +21 -21
- package/coverage/lcov-report/test-utils/six/models/line-item.ts.html +10 -10
- package/coverage/lcov-report/test-utils/six/models/order.ts.html +13 -13
- package/coverage/lcov-report/test-utils/six/models/parcel-line-item.ts.html +2 -2
- package/coverage/lcov-report/test-utils/six/models/parcel.ts.html +2 -2
- package/coverage/lcov-report/test-utils/thirteen/entities.ts.html +1 -1
- package/coverage/lcov-report/test-utils/thirteen/index.html +1 -1
- package/coverage/lcov-report/test-utils/thirteen/models/audience.ts.html +2 -2
- package/coverage/lcov-report/test-utils/thirteen/models/brand.ts.html +2 -2
- package/coverage/lcov-report/test-utils/thirteen/models/category.ts.html +1 -1
- package/coverage/lcov-report/test-utils/thirteen/models/index.html +14 -14
- package/coverage/lcov-report/test-utils/thirteen/models/member.ts.html +2 -2
- package/coverage/lcov-report/test-utils/thirteen/models/passion.ts.html +2 -2
- package/coverage/lcov-report/test-utils/thirteen/models/product.ts.html +10 -10
- package/coverage/lcov-report/test-utils/thirteen/models/recommendation-audience.ts.html +2 -2
- package/coverage/lcov-report/test-utils/thirteen/models/recommendation.ts.html +2 -2
- package/coverage/lcov-report/test-utils/three/index.html +1 -1
- package/coverage/lcov-report/test-utils/three/results.js.html +1 -1
- package/coverage/lcov-report/test-utils/twelve/entities.ts.html +1 -1
- package/coverage/lcov-report/test-utils/twelve/index.html +1 -1
- package/coverage/lcov-report/test-utils/twelve/models/index.html +1 -1
- package/coverage/lcov-report/test-utils/twelve/models/member.ts.html +1 -1
- package/coverage/lcov-report/test-utils/twelve/models/prompt.ts.html +2 -2
- package/coverage/lcov-report/test-utils/two/index.html +1 -1
- package/coverage/lcov-report/test-utils/two/results.js.html +1 -1
- package/coverage/lcov.info +2134 -1989
- package/dist/src/core.d.ts +6 -0
- package/dist/src/core.js +258 -189
- package/dist/src/core.spec.js +413 -0
- package/dist/src/driver-integrations/pgp.spec.d.ts +1 -0
- package/dist/src/driver-integrations/pgp.spec.js +376 -0
- package/dist/src/orm.d.ts +1 -1
- package/dist/src/orm.js +137 -76
- package/dist/src/orm.spec.js +535 -85
- package/dist/test-utils/nine/models/feature-switch.d.ts +2 -2
- package/dist/test-utils/nine/models/feature-switch.ts +2 -2
- package/package.json +5 -3
- package/scripts/bench-core.js +636 -0
- package/scripts/check-bench-scenarios.js +47 -0
- package/src/core.spec.ts +485 -2
- package/src/core.ts +369 -227
- package/src/driver-integrations/pgp.spec.ts +444 -0
- package/src/orm.spec.ts +592 -88
- package/src/orm.ts +149 -128
- package/test-utils/nine/models/feature-switch.ts +2 -2
package/src/orm.ts
CHANGED
|
@@ -27,7 +27,7 @@ export interface IPureORM extends ICoreIntegratedDriver {
|
|
|
27
27
|
) => Promise<T | void>;
|
|
28
28
|
getAllMatching: <T extends ICollection<IModel>>(model: IModel) => Promise<T>;
|
|
29
29
|
create: <T extends IModel>(model: T) => Promise<T>;
|
|
30
|
-
update: <T extends IModel>(model: T, options
|
|
30
|
+
update: <T extends IModel>(model: T, options?: { on: string }) => Promise<T>;
|
|
31
31
|
delete: <T extends IModel>(model: T) => Promise<void>;
|
|
32
32
|
deleteMatching: <T extends IModel>(model: T) => Promise<void>;
|
|
33
33
|
|
|
@@ -77,30 +77,61 @@ export const create = ({
|
|
|
77
77
|
/* Helper Utilities for CRUD functions ------------------------------------*/
|
|
78
78
|
/* ------------------------------------------------------------------------*/
|
|
79
79
|
|
|
80
|
+
interface IOrmHelperPlan {
|
|
81
|
+
quotedColumns: Array<string>;
|
|
82
|
+
updateClausePrefixes: Array<string>;
|
|
83
|
+
wherePositionalPrefixes: Array<string>;
|
|
84
|
+
whereNamedPrefixes: Array<string>;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const helperPlanByEntity = new Map<any, IOrmHelperPlan>();
|
|
88
|
+
const getHelperPlan = (entity: any): IOrmHelperPlan => {
|
|
89
|
+
let plan = helperPlanByEntity.get(entity);
|
|
90
|
+
if (!plan) {
|
|
91
|
+
const quotedColumns = new Array(entity.columnNames.length);
|
|
92
|
+
const updateClausePrefixes = new Array(entity.columnNames.length);
|
|
93
|
+
const wherePositionalPrefixes = new Array(entity.columnNames.length);
|
|
94
|
+
const whereNamedPrefixes = new Array(entity.columnNames.length);
|
|
95
|
+
for (let i = 0; i < entity.columnNames.length; i++) {
|
|
96
|
+
const column = entity.columnNames[i];
|
|
97
|
+
quotedColumns[i] = `"${column}"`;
|
|
98
|
+
updateClausePrefixes[i] = `"${column}" = $`;
|
|
99
|
+
wherePositionalPrefixes[i] = `"${entity.tableName}"."${column}" = $`;
|
|
100
|
+
whereNamedPrefixes[i] = `"${entity.tableName}"."${column}" = $(`;
|
|
101
|
+
}
|
|
102
|
+
plan = {
|
|
103
|
+
quotedColumns,
|
|
104
|
+
updateClausePrefixes,
|
|
105
|
+
wherePositionalPrefixes,
|
|
106
|
+
whereNamedPrefixes
|
|
107
|
+
};
|
|
108
|
+
helperPlanByEntity.set(entity, plan);
|
|
109
|
+
}
|
|
110
|
+
return plan;
|
|
111
|
+
};
|
|
112
|
+
|
|
80
113
|
const getSqlInsertParts = (
|
|
81
114
|
model: IModel
|
|
82
115
|
): { columns: string; values: Array<string>; valuesVar: Array<string> } => {
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
)
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
(
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
(value: any, index: number) => `$${index + 1}`
|
|
103
|
-
);
|
|
116
|
+
const entity = orm.getEntityByModel(model);
|
|
117
|
+
const { columnNames, propertyNames } = entity;
|
|
118
|
+
const helperPlan = getHelperPlan(entity);
|
|
119
|
+
let columns = '';
|
|
120
|
+
const values: Array<any> = [];
|
|
121
|
+
const valuesVar: Array<string> = [];
|
|
122
|
+
let paramIndex = 1;
|
|
123
|
+
for (let i = 0; i < columnNames.length; i++) {
|
|
124
|
+
const val = model[propertyNames[i] as keyof typeof model];
|
|
125
|
+
if (val !== void 0) {
|
|
126
|
+
if (columns) {
|
|
127
|
+
columns += ', ';
|
|
128
|
+
}
|
|
129
|
+
columns += helperPlan.quotedColumns[i];
|
|
130
|
+
values.push(val);
|
|
131
|
+
valuesVar.push(`$${paramIndex}`);
|
|
132
|
+
paramIndex++;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
104
135
|
return { columns, values, valuesVar };
|
|
105
136
|
};
|
|
106
137
|
|
|
@@ -108,54 +139,48 @@ export const create = ({
|
|
|
108
139
|
model: IModel,
|
|
109
140
|
on = 'id'
|
|
110
141
|
): { clause: string; idVar: string; values: Array<string> } => {
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
)
|
|
131
|
-
.filter((value: any) => value !== void 0);
|
|
132
|
-
const values = [..._values, model[on as keyof typeof model]];
|
|
142
|
+
const entity = orm.getEntityByModel(model);
|
|
143
|
+
const { columnNames, propertyNames } = entity;
|
|
144
|
+
const helperPlan = getHelperPlan(entity);
|
|
145
|
+
let clause = '';
|
|
146
|
+
const values: Array<any> = [];
|
|
147
|
+
let paramIndex = 1;
|
|
148
|
+
for (let i = 0; i < columnNames.length; i++) {
|
|
149
|
+
const val = model[propertyNames[i] as keyof typeof model];
|
|
150
|
+
if (val !== void 0) {
|
|
151
|
+
if (clause) {
|
|
152
|
+
clause += ', ';
|
|
153
|
+
}
|
|
154
|
+
clause += helperPlan.updateClausePrefixes[i] + paramIndex;
|
|
155
|
+
values.push(val);
|
|
156
|
+
paramIndex++;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
const idVar = `$${paramIndex}`;
|
|
160
|
+
values.push(model[on as keyof typeof model]);
|
|
133
161
|
return { clause, idVar, values };
|
|
134
162
|
};
|
|
135
163
|
|
|
136
164
|
const getMatchingParts = (
|
|
137
165
|
model: IModel
|
|
138
166
|
): { whereClause: string; values: Array<string> } => {
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
)
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
: null
|
|
157
|
-
)
|
|
158
|
-
.filter((x: any) => x != null);
|
|
167
|
+
const entity = orm.getEntityByModel(model);
|
|
168
|
+
const { propertyNames, columnNames } = entity;
|
|
169
|
+
const helperPlan = getHelperPlan(entity);
|
|
170
|
+
const values: Array<any> = [];
|
|
171
|
+
let paramIndex = 1;
|
|
172
|
+
let whereClause = '';
|
|
173
|
+
for (let i = 0; i < propertyNames.length; i++) {
|
|
174
|
+
const val = model[propertyNames[i] as keyof typeof model];
|
|
175
|
+
if (val != null) {
|
|
176
|
+
if (whereClause) {
|
|
177
|
+
whereClause += ' AND ';
|
|
178
|
+
}
|
|
179
|
+
whereClause += helperPlan.wherePositionalPrefixes[i] + paramIndex;
|
|
180
|
+
values.push(val);
|
|
181
|
+
paramIndex++;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
159
184
|
return { whereClause, values };
|
|
160
185
|
};
|
|
161
186
|
|
|
@@ -164,67 +189,54 @@ export const create = ({
|
|
|
164
189
|
const getMatchingPartsObject = (
|
|
165
190
|
model: IModel
|
|
166
191
|
): { whereClause: string; values: Array<string> } => {
|
|
167
|
-
const
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
)
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
: null
|
|
185
|
-
)
|
|
186
|
-
.filter((x: any) => x != null)
|
|
187
|
-
.reduce(
|
|
188
|
-
(accum: any, val: any, index: number) =>
|
|
189
|
-
Object.assign({}, accum, { [index + 1]: val }),
|
|
190
|
-
{}
|
|
191
|
-
);
|
|
192
|
+
const entity = orm.getEntityByModel(model);
|
|
193
|
+
const { propertyNames, columnNames } = entity;
|
|
194
|
+
const helperPlan = getHelperPlan(entity);
|
|
195
|
+
const values: any = {};
|
|
196
|
+
let paramIndex = 1;
|
|
197
|
+
let whereClause = '';
|
|
198
|
+
for (let i = 0; i < propertyNames.length; i++) {
|
|
199
|
+
const val = model[propertyNames[i] as keyof typeof model];
|
|
200
|
+
if (val != null) {
|
|
201
|
+
if (whereClause) {
|
|
202
|
+
whereClause += ' AND ';
|
|
203
|
+
}
|
|
204
|
+
whereClause += helperPlan.whereNamedPrefixes[i] + paramIndex + ')';
|
|
205
|
+
values[paramIndex] = val;
|
|
206
|
+
paramIndex++;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
192
209
|
return { whereClause, values };
|
|
193
210
|
};
|
|
194
211
|
|
|
195
212
|
const getNewWith = (model: IModel, sqlColumns: any, values: any): IModel => {
|
|
196
213
|
const Constructor = model.constructor as any;
|
|
197
|
-
const
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
data[key] = values[index];
|
|
206
|
-
return data;
|
|
207
|
-
},
|
|
208
|
-
{}
|
|
209
|
-
);
|
|
214
|
+
const entity = orm.getEntityByModel(model);
|
|
215
|
+
const modelData: any = {};
|
|
216
|
+
for (let i = 0; i < sqlColumns.length; i++) {
|
|
217
|
+
const propertyName = entity.columnToPropertyMap.get(sqlColumns[i]);
|
|
218
|
+
if (propertyName) {
|
|
219
|
+
modelData[propertyName] = values[i];
|
|
220
|
+
}
|
|
221
|
+
}
|
|
210
222
|
return new Constructor(modelData);
|
|
211
223
|
};
|
|
212
224
|
|
|
213
225
|
const getValueBySqlColumn = (model: IModel, sqlColumn: string): string => {
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
226
|
+
const entity = orm.getEntityByModel(model);
|
|
227
|
+
const propertyName = entity.columnToPropertyMap.get(sqlColumn);
|
|
228
|
+
return propertyName
|
|
229
|
+
? model[propertyName as keyof typeof model]
|
|
230
|
+
: (undefined as any);
|
|
219
231
|
};
|
|
220
232
|
|
|
221
233
|
const getSqlColumnForPropertyName = (
|
|
222
234
|
model: IModel,
|
|
223
235
|
propertyName: string
|
|
224
236
|
): string => {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
237
|
+
const entity = orm.getEntityByModel(model);
|
|
238
|
+
const column = entity.propertyToColumnMap.get(propertyName);
|
|
239
|
+
return column as string;
|
|
228
240
|
};
|
|
229
241
|
|
|
230
242
|
/* ------------------------------------------------------------------------*/
|
|
@@ -233,11 +245,12 @@ export const create = ({
|
|
|
233
245
|
|
|
234
246
|
// Standard create
|
|
235
247
|
const create = <T extends IModel>(model: T): Promise<T> => {
|
|
248
|
+
const entity = orm.getEntityByModel(model);
|
|
236
249
|
const { columns, values, valuesVar } = getSqlInsertParts(model);
|
|
237
250
|
const query = `
|
|
238
|
-
INSERT INTO "${
|
|
251
|
+
INSERT INTO "${entity.tableName}" ( ${columns} )
|
|
239
252
|
VALUES ( ${valuesVar} )
|
|
240
|
-
RETURNING ${
|
|
253
|
+
RETURNING ${entity.selectColumnsClause};
|
|
241
254
|
`;
|
|
242
255
|
return orm.one<T>(query, values);
|
|
243
256
|
};
|
|
@@ -247,42 +260,47 @@ export const create = ({
|
|
|
247
260
|
model: T,
|
|
248
261
|
{ on = 'id' } = {}
|
|
249
262
|
): Promise<T> => {
|
|
263
|
+
const entity = orm.getEntityByModel(model);
|
|
250
264
|
const { clause, idVar, values } = getSqlUpdateParts(model, on);
|
|
251
265
|
const query = `
|
|
252
|
-
UPDATE "${
|
|
266
|
+
UPDATE "${entity.tableName}"
|
|
253
267
|
SET ${clause}
|
|
254
|
-
WHERE "${
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
268
|
+
WHERE "${entity.tableName}".${getSqlColumnForPropertyName(
|
|
269
|
+
model,
|
|
270
|
+
on
|
|
271
|
+
)} = ${idVar}
|
|
272
|
+
RETURNING ${entity.selectColumnsClause};
|
|
258
273
|
`;
|
|
259
274
|
return orm.one<T>(query, values);
|
|
260
275
|
};
|
|
261
276
|
|
|
262
277
|
// Standard delete
|
|
263
278
|
const _delete = <T extends IModel>(model: T): Promise<void> => {
|
|
279
|
+
const entity = orm.getEntityByModel(model);
|
|
264
280
|
const id = (model as any).id;
|
|
265
281
|
const query = `
|
|
266
|
-
DELETE FROM "${
|
|
267
|
-
WHERE "${
|
|
282
|
+
DELETE FROM "${entity.tableName}"
|
|
283
|
+
WHERE "${entity.tableName}".id = $(id)
|
|
268
284
|
`;
|
|
269
285
|
return orm.none(query, { id });
|
|
270
286
|
};
|
|
271
287
|
|
|
272
288
|
const deleteMatching = <T extends IModel>(model: T): Promise<void> => {
|
|
289
|
+
const entity = orm.getEntityByModel(model);
|
|
273
290
|
const { whereClause, values } = getMatchingParts(model);
|
|
274
291
|
const query = `
|
|
275
|
-
DELETE FROM "${
|
|
292
|
+
DELETE FROM "${entity.tableName}"
|
|
276
293
|
WHERE ${whereClause};
|
|
277
294
|
`;
|
|
278
295
|
return orm.none(query, values);
|
|
279
296
|
};
|
|
280
297
|
|
|
281
298
|
const getMatching = <T extends IModel>(model: T): Promise<T> => {
|
|
299
|
+
const entity = orm.getEntityByModel(model);
|
|
282
300
|
const { whereClause, values } = getMatchingParts(model);
|
|
283
301
|
const query = `
|
|
284
|
-
SELECT ${
|
|
285
|
-
FROM "${
|
|
302
|
+
SELECT ${entity.selectColumnsClause}
|
|
303
|
+
FROM "${entity.tableName}"
|
|
286
304
|
WHERE ${whereClause};
|
|
287
305
|
`;
|
|
288
306
|
return orm.one<T>(query, values);
|
|
@@ -291,10 +309,11 @@ export const create = ({
|
|
|
291
309
|
const getOneOrNoneMatching = <T extends IModel>(
|
|
292
310
|
model: T
|
|
293
311
|
): Promise<T | void> => {
|
|
312
|
+
const entity = orm.getEntityByModel(model);
|
|
294
313
|
const { whereClause, values } = getMatchingParts(model);
|
|
295
314
|
const query = `
|
|
296
|
-
SELECT ${
|
|
297
|
-
FROM "${
|
|
315
|
+
SELECT ${entity.selectColumnsClause}
|
|
316
|
+
FROM "${entity.tableName}"
|
|
298
317
|
WHERE ${whereClause};
|
|
299
318
|
`;
|
|
300
319
|
return orm.oneOrNone<T>(query, values);
|
|
@@ -303,10 +322,11 @@ export const create = ({
|
|
|
303
322
|
const getAnyMatching = <T extends ICollection<IModel>>(
|
|
304
323
|
model: IModel
|
|
305
324
|
): Promise<T | void> => {
|
|
325
|
+
const entity = orm.getEntityByModel(model);
|
|
306
326
|
const { whereClause, values } = getMatchingParts(model);
|
|
307
327
|
const query = `
|
|
308
|
-
SELECT ${
|
|
309
|
-
FROM "${
|
|
328
|
+
SELECT ${entity.selectColumnsClause}
|
|
329
|
+
FROM "${entity.tableName}"
|
|
310
330
|
WHERE ${whereClause};
|
|
311
331
|
`;
|
|
312
332
|
return orm.any<T>(query, values);
|
|
@@ -315,10 +335,11 @@ export const create = ({
|
|
|
315
335
|
const getAllMatching = <T extends ICollection<IModel>>(
|
|
316
336
|
model: IModel
|
|
317
337
|
): Promise<T> => {
|
|
338
|
+
const entity = orm.getEntityByModel(model);
|
|
318
339
|
const { whereClause, values } = getMatchingParts(model);
|
|
319
340
|
const query = `
|
|
320
|
-
SELECT ${
|
|
321
|
-
FROM "${
|
|
341
|
+
SELECT ${entity.selectColumnsClause}
|
|
342
|
+
FROM "${entity.tableName}"
|
|
322
343
|
WHERE ${whereClause};
|
|
323
344
|
`;
|
|
324
345
|
return orm.many<T>(query, values);
|
|
@@ -5,13 +5,13 @@ export const tableName: string = 'feature_switch';
|
|
|
5
5
|
export const columns: IColumns = ['id', 'label', 'on'];
|
|
6
6
|
|
|
7
7
|
interface IFeatureSwitchProps {
|
|
8
|
-
id: number;
|
|
8
|
+
id: string | number;
|
|
9
9
|
label: string;
|
|
10
10
|
on: boolean;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export class FeatureSwitch implements IModel {
|
|
14
|
-
id: number;
|
|
14
|
+
id: string | number;
|
|
15
15
|
label: string;
|
|
16
16
|
on: boolean;
|
|
17
17
|
|