mythix-orm 1.4.5 → 1.5.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.
- package/docs/Associations.md +2 -2
- package/docs/Certifications.md +22 -0
- package/docs/Home.md +25 -22
- package/lib/connection/connection-base.js +116 -27
- package/lib/connection/literals/average-literal.js +2 -2
- package/lib/connection/literals/count-literal.js +2 -2
- package/lib/connection/literals/distinct-literal.js +2 -2
- package/lib/connection/literals/literal-field-base.js +7 -0
- package/lib/connection/literals/max-literal.js +2 -2
- package/lib/connection/literals/min-literal.js +2 -2
- package/lib/connection/literals/sum-literal.js +2 -2
- package/lib/connection/query-generator-base.js +61 -41
- package/lib/model.js +1515 -35
- package/lib/types/concrete/date-type.js +4 -3
- package/lib/types/concrete/datetime-type.js +4 -3
- package/lib/types/concrete/index.js +9 -3
- package/lib/types/concrete/{float-type.js → numeric-type.js} +12 -9
- package/lib/types/concrete/real-type.js +47 -0
- package/lib/types/concrete/serialized-type.js +134 -0
- package/lib/types/index.js +12 -4
- package/lib/types/type.js +6 -0
- package/lib/utils/model-utils.js +39 -19
- package/lib/utils/query-utils.js +4 -4
- package/package.json +1 -1
|
@@ -20,10 +20,12 @@ class QueryGeneratorBase {
|
|
|
20
20
|
});
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
stackAssign(obj, ...
|
|
23
|
+
stackAssign(obj, ..._args) {
|
|
24
24
|
let newObj = Object.create(obj || {});
|
|
25
|
+
let args = _args.filter(Boolean);
|
|
25
26
|
|
|
26
|
-
|
|
27
|
+
if (args.length > 0)
|
|
28
|
+
Object.assign(newObj, ...args);
|
|
27
29
|
|
|
28
30
|
return newObj;
|
|
29
31
|
}
|
|
@@ -159,8 +161,14 @@ class QueryGeneratorBase {
|
|
|
159
161
|
continue;
|
|
160
162
|
|
|
161
163
|
if (LiteralBase.isLiteral(field)) {
|
|
162
|
-
let result = field.toString(this.connection);
|
|
163
|
-
let projectionField
|
|
164
|
+
let result = field.toString(this.connection, options);
|
|
165
|
+
let projectionField;
|
|
166
|
+
|
|
167
|
+
if (typeof field.getField === 'function')
|
|
168
|
+
projectionField = field.getField(this.connection);
|
|
169
|
+
else
|
|
170
|
+
projectionField = this.parseFieldProjection(result, true);
|
|
171
|
+
|
|
164
172
|
if (projectionField === result) {
|
|
165
173
|
// not able to parse projection
|
|
166
174
|
continue;
|
|
@@ -188,7 +196,7 @@ class QueryGeneratorBase {
|
|
|
188
196
|
return orderFieldMap;
|
|
189
197
|
}
|
|
190
198
|
|
|
191
|
-
sortedProjectedFields(projectedFields) {
|
|
199
|
+
sortedProjectedFields(projectedFields, options) {
|
|
192
200
|
return projectedFields.sort((a, b) => {
|
|
193
201
|
// If either value is a distinct literal
|
|
194
202
|
// then make certain it comes first in
|
|
@@ -197,8 +205,8 @@ class QueryGeneratorBase {
|
|
|
197
205
|
const distinctSortOrder = (a, b) => {
|
|
198
206
|
let x = LiteralBase.isLiteral(a);
|
|
199
207
|
let y = LiteralBase.isLiteral(b);
|
|
200
|
-
let xStr = (x) ? a.toString(this.connection) : a;
|
|
201
|
-
let yStr = (y) ? b.toString(this.connection) : b;
|
|
208
|
+
let xStr = (x) ? a.toString(this.connection, options) : a;
|
|
209
|
+
let yStr = (y) ? b.toString(this.connection, options) : b;
|
|
202
210
|
let xIsDistinct = (typeof xStr === 'string' && LITERAL_IS_DISTINCT_RE.test(xStr));
|
|
203
211
|
let yIsDistinct = (typeof yStr === 'string' && LITERAL_IS_DISTINCT_RE.test(yStr));
|
|
204
212
|
|
|
@@ -383,7 +391,7 @@ class QueryGeneratorBase {
|
|
|
383
391
|
result = Array.from(projectedFields.values());
|
|
384
392
|
|
|
385
393
|
// Convert projection fields to array and sort
|
|
386
|
-
result = this.sortedProjectedFields(result);
|
|
394
|
+
result = this.sortedProjectedFields(result, options);
|
|
387
395
|
|
|
388
396
|
// Now prefix the projection fields with the distinct
|
|
389
397
|
// literal if one exists on the query
|
|
@@ -442,7 +450,7 @@ class QueryGeneratorBase {
|
|
|
442
450
|
if (hasDistinct && Literals.DistinctLiteral.isLiteralType(projectionValue))
|
|
443
451
|
continue;
|
|
444
452
|
|
|
445
|
-
let key = projectionValue.toString(this.connection);
|
|
453
|
+
let key = projectionValue.toString(this.connection, options);
|
|
446
454
|
if (isAdding)
|
|
447
455
|
projectedFields.set(key, projectionValue);
|
|
448
456
|
else
|
|
@@ -556,8 +564,13 @@ class QueryGeneratorBase {
|
|
|
556
564
|
return result;
|
|
557
565
|
}
|
|
558
566
|
|
|
567
|
+
isFieldIdentifier(str) {
|
|
568
|
+
return (/^"[^"]+"."[^"]+"|"\w+:[\w.]+"/i).test(str);
|
|
569
|
+
}
|
|
570
|
+
|
|
559
571
|
getProjectedFields(queryEngine, _options, asMap) {
|
|
560
|
-
let
|
|
572
|
+
let options = _options || {};
|
|
573
|
+
let queryProjection = this.getProjectionFromQueryEngine(queryEngine, options);
|
|
561
574
|
let allProjectionFields = new Map();
|
|
562
575
|
|
|
563
576
|
for (let i = 0, il = queryProjection.length; i < il; i++) {
|
|
@@ -566,15 +579,20 @@ class QueryGeneratorBase {
|
|
|
566
579
|
continue;
|
|
567
580
|
|
|
568
581
|
if (LiteralBase.isLiteral(projectionField)) {
|
|
569
|
-
let result = projectionField.toString(this.connection);
|
|
570
|
-
let fullFieldName
|
|
582
|
+
let result = projectionField.toString(this.connection, options);
|
|
583
|
+
let fullFieldName;
|
|
584
|
+
|
|
585
|
+
if (typeof projectionField.getFullyQualifiedFieldName === 'function')
|
|
586
|
+
fullFieldName = projectionField.getFullyQualifiedFieldName();
|
|
587
|
+
else
|
|
588
|
+
fullFieldName = this.parseFieldProjection(result);
|
|
589
|
+
|
|
571
590
|
if (!fullFieldName)
|
|
572
591
|
fullFieldName = result;
|
|
573
592
|
|
|
574
593
|
if (fullFieldName && result)
|
|
575
594
|
allProjectionFields.set(fullFieldName, result);
|
|
576
|
-
|
|
577
|
-
if (result && !this.isFieldProjection(result))
|
|
595
|
+
else
|
|
578
596
|
allProjectionFields.set(result, result);
|
|
579
597
|
|
|
580
598
|
continue;
|
|
@@ -708,6 +726,11 @@ class QueryGeneratorBase {
|
|
|
708
726
|
order = queryPart.value;
|
|
709
727
|
}
|
|
710
728
|
|
|
729
|
+
if (Nife.isEmpty(order)) {
|
|
730
|
+
if (options && options.selectStatement === true)
|
|
731
|
+
order = this.connection.getDefaultOrder(rootModel, options);
|
|
732
|
+
}
|
|
733
|
+
|
|
711
734
|
if (Nife.isNotEmpty(order) && !LiteralBase.isLiteral(order)) {
|
|
712
735
|
let allModels = this.getAllModelsUsedInQuery(queryEngine, options);
|
|
713
736
|
|
|
@@ -740,9 +763,6 @@ class QueryGeneratorBase {
|
|
|
740
763
|
direction,
|
|
741
764
|
};
|
|
742
765
|
});
|
|
743
|
-
} else if (Nife.isEmpty(order)) {
|
|
744
|
-
if (options && options.selectStatement === true)
|
|
745
|
-
order = this.connection.getDefaultOrder(rootModel, options);
|
|
746
766
|
}
|
|
747
767
|
|
|
748
768
|
let orderLimitOffset = { limit, order, offset };
|
|
@@ -773,33 +793,33 @@ class QueryGeneratorBase {
|
|
|
773
793
|
return queryRoot.slice(index);
|
|
774
794
|
}
|
|
775
795
|
|
|
776
|
-
_averageLiteralToString(literal) {
|
|
796
|
+
_averageLiteralToString(literal, options) {
|
|
777
797
|
if (!literal || !LiteralBase.isLiteral(literal))
|
|
778
798
|
return;
|
|
779
799
|
|
|
780
|
-
let field = literal.
|
|
800
|
+
let field = literal.getField(this.connection);
|
|
781
801
|
let escapedFieldName;
|
|
782
802
|
|
|
783
803
|
if (LiteralBase.isLiteral(field))
|
|
784
|
-
escapedFieldName = field.toString(this.connection);
|
|
804
|
+
escapedFieldName = field.toString(this.connection, options);
|
|
785
805
|
else
|
|
786
|
-
escapedFieldName = this.getEscapedColumnName(field.Model, field, literal.options);
|
|
806
|
+
escapedFieldName = this.getEscapedColumnName(field.Model, field, this.stackAssign(options, literal.options));
|
|
787
807
|
|
|
788
808
|
return `AVG(${escapedFieldName})`;
|
|
789
809
|
}
|
|
790
810
|
|
|
791
|
-
_countLiteralToString(literal) {
|
|
811
|
+
_countLiteralToString(literal, options) {
|
|
792
812
|
if (!literal || !LiteralBase.isLiteral(literal))
|
|
793
813
|
return;
|
|
794
814
|
|
|
795
|
-
let field =
|
|
815
|
+
let field = literal.getField(this.connection);
|
|
796
816
|
let escapedFieldName;
|
|
797
817
|
|
|
798
818
|
if (field) {
|
|
799
819
|
if (LiteralBase.isLiteral(field))
|
|
800
|
-
escapedFieldName = field.toString(this.connection);
|
|
820
|
+
escapedFieldName = field.toString(this.connection, options);
|
|
801
821
|
else
|
|
802
|
-
escapedFieldName = this.getEscapedColumnName(field.Model, field, literal.options);
|
|
822
|
+
escapedFieldName = this.getEscapedColumnName(field.Model, field, this.stackAssign(options, literal.options));
|
|
803
823
|
} else {
|
|
804
824
|
escapedFieldName = '*';
|
|
805
825
|
}
|
|
@@ -807,58 +827,58 @@ class QueryGeneratorBase {
|
|
|
807
827
|
return `COUNT(${escapedFieldName})`;
|
|
808
828
|
}
|
|
809
829
|
|
|
810
|
-
_distinctLiteralToString(literal) {
|
|
830
|
+
_distinctLiteralToString(literal, options) {
|
|
811
831
|
if (!literal || !LiteralBase.isLiteral(literal))
|
|
812
832
|
return;
|
|
813
833
|
|
|
814
|
-
let field = literal.
|
|
834
|
+
let field = literal.getField(this.connection);
|
|
815
835
|
if (LiteralBase.isLiteral(field))
|
|
816
|
-
return `DISTINCT ${field.toString(this.connection)}`;
|
|
836
|
+
return `DISTINCT ${field.toString(this.connection, options)}`;
|
|
817
837
|
|
|
818
|
-
return `DISTINCT ${this.getEscapedProjectionName(field.Model, field, literal.options)}`;
|
|
838
|
+
return `DISTINCT ${this.getEscapedProjectionName(field.Model, field, this.stackAssign(options, literal.options))}`;
|
|
819
839
|
}
|
|
820
840
|
|
|
821
|
-
_maxLiteralToString(literal) {
|
|
841
|
+
_maxLiteralToString(literal, options) {
|
|
822
842
|
if (!literal || !LiteralBase.isLiteral(literal))
|
|
823
843
|
return;
|
|
824
844
|
|
|
825
|
-
let field = literal.
|
|
845
|
+
let field = literal.getField(this.connection);
|
|
826
846
|
let escapedFieldName;
|
|
827
847
|
|
|
828
848
|
if (LiteralBase.isLiteral(field))
|
|
829
|
-
escapedFieldName = field.toString(this.connection);
|
|
849
|
+
escapedFieldName = field.toString(this.connection, options);
|
|
830
850
|
else
|
|
831
|
-
escapedFieldName = this.getEscapedColumnName(field.Model, field, literal.options);
|
|
851
|
+
escapedFieldName = this.getEscapedColumnName(field.Model, field, this.stackAssign(options, literal.options));
|
|
832
852
|
|
|
833
853
|
return `MAX(${escapedFieldName})`;
|
|
834
854
|
}
|
|
835
855
|
|
|
836
|
-
_minLiteralToString(literal) {
|
|
856
|
+
_minLiteralToString(literal, options) {
|
|
837
857
|
if (!literal || !LiteralBase.isLiteral(literal))
|
|
838
858
|
return;
|
|
839
859
|
|
|
840
|
-
let field = literal.
|
|
860
|
+
let field = literal.getField(this.connection);
|
|
841
861
|
let escapedFieldName;
|
|
842
862
|
|
|
843
863
|
if (LiteralBase.isLiteral(field))
|
|
844
|
-
escapedFieldName = field.toString(this.connection);
|
|
864
|
+
escapedFieldName = field.toString(this.connection, options);
|
|
845
865
|
else
|
|
846
|
-
escapedFieldName = this.getEscapedColumnName(field.Model, field, literal.options);
|
|
866
|
+
escapedFieldName = this.getEscapedColumnName(field.Model, field, this.stackAssign(options, literal.options));
|
|
847
867
|
|
|
848
868
|
return `MIN(${escapedFieldName})`;
|
|
849
869
|
}
|
|
850
870
|
|
|
851
|
-
_sumLiteralToString(literal) {
|
|
871
|
+
_sumLiteralToString(literal, options) {
|
|
852
872
|
if (!literal || !LiteralBase.isLiteral(literal))
|
|
853
873
|
return;
|
|
854
874
|
|
|
855
|
-
let field = literal.
|
|
875
|
+
let field = literal.getField(this.connection);
|
|
856
876
|
let escapedFieldName;
|
|
857
877
|
|
|
858
878
|
if (LiteralBase.isLiteral(field))
|
|
859
|
-
escapedFieldName = field.toString(this.connection);
|
|
879
|
+
escapedFieldName = field.toString(this.connection, options);
|
|
860
880
|
else
|
|
861
|
-
escapedFieldName = this.getEscapedColumnName(field.Model, field, literal.options);
|
|
881
|
+
escapedFieldName = this.getEscapedColumnName(field.Model, field, this.stackAssign(options, literal.options));
|
|
862
882
|
|
|
863
883
|
return `SUM(${escapedFieldName})`;
|
|
864
884
|
}
|