@nymphjs/driver-postgresql 1.0.0-beta.109 → 1.0.0-beta.110
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/CHANGELOG.md +8 -0
- package/dist/PostgreSQLDriver.d.ts +2 -1
- package/dist/PostgreSQLDriver.js +523 -267
- package/dist/PostgreSQLDriver.js.map +1 -1
- package/package.json +5 -5
- package/src/PostgreSQLDriver.ts +623 -270
package/dist/PostgreSQLDriver.js
CHANGED
|
@@ -685,7 +685,7 @@ export default class PostgreSQLDriver extends NymphDriver {
|
|
|
685
685
|
const etypes = await this.getEtypes();
|
|
686
686
|
for (const etype of etypes) {
|
|
687
687
|
// Export entities.
|
|
688
|
-
const dataIterator = await this.queryIter(`SELECT encode(e."guid", 'hex') AS "guid", e."tags", e."cdate", e."mdate", d."name", d."value", d."json", d."string", d."number"
|
|
688
|
+
const dataIterator = await this.queryIter(`SELECT encode(e."guid", 'hex') AS "guid", e."tags", e."cdate", e."mdate", encode(e."user", 'hex') AS "user", encode(e."group", 'hex') AS "group", e."acUser", e."acGroup", e."acOther", array(SELECT encode(n, 'hex') FROM unnest(e."acRead") AS n) as "acRead", array(SELECT encode(n, 'hex') FROM unnest(e."acWrite") AS n) as "acWrite", array(SELECT encode(n, 'hex') FROM unnest(e."acFull") AS n) as "acFull", d."name", d."value", d."json", d."string", d."number"
|
|
689
689
|
FROM ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}`)} e
|
|
690
690
|
LEFT JOIN ${PostgreSQLDriver.escape(`${this.prefix}data_${etype}`)} d ON e."guid"=d."guid"
|
|
691
691
|
ORDER BY e."guid";`);
|
|
@@ -695,10 +695,44 @@ export default class PostgreSQLDriver extends NymphDriver {
|
|
|
695
695
|
const tags = datum.value.tags.filter((tag) => tag).join(',');
|
|
696
696
|
const cdate = datum.value.cdate;
|
|
697
697
|
const mdate = datum.value.mdate;
|
|
698
|
+
const user = datum.value.user;
|
|
699
|
+
const group = datum.value.group;
|
|
700
|
+
const acUser = datum.value.acUser;
|
|
701
|
+
const acGroup = datum.value.acGroup;
|
|
702
|
+
const acOther = datum.value.acOther;
|
|
703
|
+
const acRead = datum.value.acRead?.filter((guid) => guid);
|
|
704
|
+
const acWrite = datum.value.acWrite?.filter((guid) => guid);
|
|
705
|
+
const acFull = datum.value.acFull?.filter((guid) => guid);
|
|
698
706
|
let currentEntityExport = [];
|
|
699
707
|
currentEntityExport.push(`{${guid}}<${etype}>[${tags}]`);
|
|
700
708
|
currentEntityExport.push(`\tcdate=${JSON.stringify(cdate)}`);
|
|
701
709
|
currentEntityExport.push(`\tmdate=${JSON.stringify(mdate)}`);
|
|
710
|
+
if (this.nymph.tilmeld != null) {
|
|
711
|
+
if (user != null) {
|
|
712
|
+
currentEntityExport.push(`\tuser=${JSON.stringify(['nymph_entity_reference', user, 'User'])}`);
|
|
713
|
+
}
|
|
714
|
+
if (group != null) {
|
|
715
|
+
currentEntityExport.push(`\tgroup=${JSON.stringify(['nymph_entity_reference', group, 'Group'])}`);
|
|
716
|
+
}
|
|
717
|
+
if (acUser != null) {
|
|
718
|
+
currentEntityExport.push(`\tacUser=${JSON.stringify(acUser)}`);
|
|
719
|
+
}
|
|
720
|
+
if (acGroup != null) {
|
|
721
|
+
currentEntityExport.push(`\tacGroup=${JSON.stringify(acGroup)}`);
|
|
722
|
+
}
|
|
723
|
+
if (acOther != null) {
|
|
724
|
+
currentEntityExport.push(`\tacOther=${JSON.stringify(acOther)}`);
|
|
725
|
+
}
|
|
726
|
+
if (acRead != null) {
|
|
727
|
+
currentEntityExport.push(`\tacRead=${JSON.stringify(acRead)}`);
|
|
728
|
+
}
|
|
729
|
+
if (acWrite != null) {
|
|
730
|
+
currentEntityExport.push(`\tacWrite=${JSON.stringify(acWrite)}`);
|
|
731
|
+
}
|
|
732
|
+
if (acFull != null) {
|
|
733
|
+
currentEntityExport.push(`\tacFull=${JSON.stringify(acFull)}`);
|
|
734
|
+
}
|
|
735
|
+
}
|
|
702
736
|
if (datum.value.name != null) {
|
|
703
737
|
// This do will keep going and adding the data until the
|
|
704
738
|
// next entity is reached. $row will end on the next entity.
|
|
@@ -735,7 +769,7 @@ export default class PostgreSQLDriver extends NymphDriver {
|
|
|
735
769
|
* @param subquery Whether only a subquery should be returned.
|
|
736
770
|
* @returns The SQL query.
|
|
737
771
|
*/
|
|
738
|
-
makeEntityQuery(options, formattedSelectors, etype, count = { i: 0 }, params = {}, subquery = false, tableSuffix = '', etypes = [], guidSelector = undefined) {
|
|
772
|
+
makeEntityQuery(options, formattedSelectors, etype, count = { i: 0 }, params = {}, subquery = false, tableSuffix = '', etypes = [], guidSelector = undefined, guidExplicitSelector = undefined) {
|
|
739
773
|
if (typeof options.class?.alterOptions === 'function') {
|
|
740
774
|
options = options.class.alterOptions(options);
|
|
741
775
|
}
|
|
@@ -788,17 +822,38 @@ export default class PostgreSQLDriver extends NymphDriver {
|
|
|
788
822
|
if (curQuery) {
|
|
789
823
|
curQuery += typeIsOr ? ' OR ' : ' AND ';
|
|
790
824
|
}
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
(
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
825
|
+
if (curVar === 'cdate' ||
|
|
826
|
+
curVar === 'mdate' ||
|
|
827
|
+
(this.nymph.tilmeld != null &&
|
|
828
|
+
(curVar === 'user' ||
|
|
829
|
+
curVar === 'group' ||
|
|
830
|
+
curVar === 'acUser' ||
|
|
831
|
+
curVar === 'acGroup' ||
|
|
832
|
+
curVar === 'acOther' ||
|
|
833
|
+
curVar === 'acRead' ||
|
|
834
|
+
curVar === 'acWrite' ||
|
|
835
|
+
curVar === 'acFull'))) {
|
|
836
|
+
curQuery +=
|
|
837
|
+
(xor(typeIsNot, clauseNot) ? 'NOT ' : '') +
|
|
838
|
+
'(' +
|
|
839
|
+
ieTable +
|
|
840
|
+
'.' +
|
|
841
|
+
PostgreSQLDriver.escape(curVar) +
|
|
842
|
+
' IS NOT NULL)';
|
|
843
|
+
}
|
|
844
|
+
else {
|
|
845
|
+
const name = `param${++count.i}`;
|
|
846
|
+
curQuery +=
|
|
847
|
+
(xor(typeIsNot, clauseNot) ? 'NOT ' : '') +
|
|
848
|
+
'EXISTS (SELECT "guid" FROM ' +
|
|
849
|
+
PostgreSQLDriver.escape(this.prefix + 'data_' + etype) +
|
|
850
|
+
' WHERE "guid"=' +
|
|
851
|
+
ieTable +
|
|
852
|
+
'."guid" AND "name"=@' +
|
|
853
|
+
name +
|
|
854
|
+
')';
|
|
855
|
+
params[name] = curVar;
|
|
856
|
+
}
|
|
802
857
|
}
|
|
803
858
|
break;
|
|
804
859
|
case 'truthy':
|
|
@@ -807,21 +862,24 @@ export default class PostgreSQLDriver extends NymphDriver {
|
|
|
807
862
|
if (curQuery) {
|
|
808
863
|
curQuery += typeIsOr ? ' OR ' : ' AND ';
|
|
809
864
|
}
|
|
810
|
-
if (curVar === 'cdate'
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
865
|
+
if (curVar === 'cdate' ||
|
|
866
|
+
curVar === 'mdate' ||
|
|
867
|
+
(this.nymph.tilmeld != null &&
|
|
868
|
+
(curVar === 'user' ||
|
|
869
|
+
curVar === 'group' ||
|
|
870
|
+
curVar === 'acUser' ||
|
|
871
|
+
curVar === 'acGroup' ||
|
|
872
|
+
curVar === 'acOther' ||
|
|
873
|
+
curVar === 'acRead' ||
|
|
874
|
+
curVar === 'acWrite' ||
|
|
875
|
+
curVar === 'acFull'))) {
|
|
819
876
|
curQuery +=
|
|
820
877
|
(xor(typeIsNot, clauseNot) ? 'NOT ' : '') +
|
|
821
878
|
'(' +
|
|
822
879
|
ieTable +
|
|
823
|
-
'.
|
|
824
|
-
|
|
880
|
+
'.' +
|
|
881
|
+
PostgreSQLDriver.escape(curVar) +
|
|
882
|
+
' IS NOT NULL)';
|
|
825
883
|
}
|
|
826
884
|
else {
|
|
827
885
|
const name = `param${++count.i}`;
|
|
@@ -840,35 +898,63 @@ export default class PostgreSQLDriver extends NymphDriver {
|
|
|
840
898
|
break;
|
|
841
899
|
case 'equal':
|
|
842
900
|
case '!equal':
|
|
843
|
-
if (curValue[0] === 'cdate'
|
|
901
|
+
if (curValue[0] === 'cdate' ||
|
|
902
|
+
curValue[0] === 'mdate' ||
|
|
903
|
+
(this.nymph.tilmeld != null &&
|
|
904
|
+
(curValue[0] === 'acUser' ||
|
|
905
|
+
curValue[0] === 'acGroup' ||
|
|
906
|
+
curValue[0] === 'acOther'))) {
|
|
844
907
|
if (curQuery) {
|
|
845
908
|
curQuery += typeIsOr ? ' OR ' : ' AND ';
|
|
846
909
|
}
|
|
847
|
-
const
|
|
910
|
+
const value = `param${++count.i}`;
|
|
848
911
|
curQuery +=
|
|
849
912
|
(xor(typeIsNot, clauseNot) ? 'NOT ' : '') +
|
|
850
913
|
ieTable +
|
|
851
|
-
'.
|
|
852
|
-
|
|
853
|
-
|
|
914
|
+
'.' +
|
|
915
|
+
PostgreSQLDriver.escape(curValue[0]) +
|
|
916
|
+
'=@' +
|
|
917
|
+
value;
|
|
918
|
+
params[value] = isNaN(Number(curValue[1]))
|
|
854
919
|
? null
|
|
855
920
|
: Number(curValue[1]);
|
|
856
|
-
break;
|
|
857
921
|
}
|
|
858
|
-
else if (
|
|
922
|
+
else if (this.nymph.tilmeld != null &&
|
|
923
|
+
(curValue[0] === 'user' || curValue[0] === 'group')) {
|
|
859
924
|
if (curQuery) {
|
|
860
925
|
curQuery += typeIsOr ? ' OR ' : ' AND ';
|
|
861
926
|
}
|
|
862
|
-
const
|
|
927
|
+
const value = `param${++count.i}`;
|
|
863
928
|
curQuery +=
|
|
864
929
|
(xor(typeIsNot, clauseNot) ? 'NOT ' : '') +
|
|
865
930
|
ieTable +
|
|
866
|
-
'.
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
931
|
+
'.' +
|
|
932
|
+
PostgreSQLDriver.escape(curValue[0]) +
|
|
933
|
+
'=decode(@' +
|
|
934
|
+
value +
|
|
935
|
+
", 'hex')";
|
|
936
|
+
params[value] = `${curValue[1]}`;
|
|
937
|
+
}
|
|
938
|
+
else if (this.nymph.tilmeld != null &&
|
|
939
|
+
(curValue[0] === 'acRead' ||
|
|
940
|
+
curValue[0] === 'acWrite' ||
|
|
941
|
+
curValue[0] === 'acFull')) {
|
|
942
|
+
if (curQuery) {
|
|
943
|
+
curQuery += typeIsOr ? ' OR ' : ' AND ';
|
|
944
|
+
}
|
|
945
|
+
const value = `param${++count.i}`;
|
|
946
|
+
curQuery +=
|
|
947
|
+
(xor(typeIsNot, clauseNot) ? 'NOT ' : '') +
|
|
948
|
+
ieTable +
|
|
949
|
+
'.' +
|
|
950
|
+
PostgreSQLDriver.escape(curValue[0]) +
|
|
951
|
+
'=' +
|
|
952
|
+
!curValue[1]?.length
|
|
953
|
+
? '@' + value
|
|
954
|
+
: "array(SELECT decode(n, 'hex') FROM unnest(@" +
|
|
955
|
+
value +
|
|
956
|
+
'::text[]) AS n)';
|
|
957
|
+
params[value] = Array.isArray(curValue[1]) ? curValue[1] : '';
|
|
872
958
|
}
|
|
873
959
|
else if (typeof curValue[1] === 'number') {
|
|
874
960
|
if (curQuery) {
|
|
@@ -943,35 +1029,61 @@ export default class PostgreSQLDriver extends NymphDriver {
|
|
|
943
1029
|
break;
|
|
944
1030
|
case 'contain':
|
|
945
1031
|
case '!contain':
|
|
946
|
-
if (curValue[0] === 'cdate'
|
|
1032
|
+
if (curValue[0] === 'cdate' ||
|
|
1033
|
+
curValue[0] === 'mdate' ||
|
|
1034
|
+
(this.nymph.tilmeld != null &&
|
|
1035
|
+
(curValue[0] === 'acUser' ||
|
|
1036
|
+
curValue[0] === 'acGroup' ||
|
|
1037
|
+
curValue[0] === 'acOther'))) {
|
|
947
1038
|
if (curQuery) {
|
|
948
1039
|
curQuery += typeIsOr ? ' OR ' : ' AND ';
|
|
949
1040
|
}
|
|
950
|
-
const
|
|
1041
|
+
const value = `param${++count.i}`;
|
|
951
1042
|
curQuery +=
|
|
952
1043
|
(xor(typeIsNot, clauseNot) ? 'NOT ' : '') +
|
|
953
1044
|
ieTable +
|
|
954
|
-
'.
|
|
955
|
-
|
|
956
|
-
|
|
1045
|
+
'.' +
|
|
1046
|
+
PostgreSQLDriver.escape(curValue[0]) +
|
|
1047
|
+
'=@' +
|
|
1048
|
+
value;
|
|
1049
|
+
params[value] = isNaN(Number(curValue[1]))
|
|
957
1050
|
? null
|
|
958
1051
|
: Number(curValue[1]);
|
|
959
|
-
break;
|
|
960
1052
|
}
|
|
961
|
-
else if (
|
|
1053
|
+
else if (this.nymph.tilmeld != null &&
|
|
1054
|
+
(curValue[0] === 'user' || curValue[0] === 'group')) {
|
|
962
1055
|
if (curQuery) {
|
|
963
1056
|
curQuery += typeIsOr ? ' OR ' : ' AND ';
|
|
964
1057
|
}
|
|
965
|
-
const
|
|
1058
|
+
const value = `param${++count.i}`;
|
|
966
1059
|
curQuery +=
|
|
967
1060
|
(xor(typeIsNot, clauseNot) ? 'NOT ' : '') +
|
|
968
1061
|
ieTable +
|
|
969
|
-
'.
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
1062
|
+
'.' +
|
|
1063
|
+
PostgreSQLDriver.escape(curValue[0]) +
|
|
1064
|
+
'=decode(@' +
|
|
1065
|
+
value +
|
|
1066
|
+
", 'hex')";
|
|
1067
|
+
params[value] = `${curValue[1]}`;
|
|
1068
|
+
}
|
|
1069
|
+
else if (this.nymph.tilmeld != null &&
|
|
1070
|
+
(curValue[0] === 'acRead' ||
|
|
1071
|
+
curValue[0] === 'acWrite' ||
|
|
1072
|
+
curValue[0] === 'acFull')) {
|
|
1073
|
+
if (curQuery) {
|
|
1074
|
+
curQuery += typeIsOr ? ' OR ' : ' AND ';
|
|
1075
|
+
}
|
|
1076
|
+
const value = `param${++count.i}`;
|
|
1077
|
+
curQuery +=
|
|
1078
|
+
(xor(typeIsNot, clauseNot) ? 'NOT ' : '') +
|
|
1079
|
+
'decode(@' +
|
|
1080
|
+
value +
|
|
1081
|
+
", 'hex')=ANY(" +
|
|
1082
|
+
ieTable +
|
|
1083
|
+
'.' +
|
|
1084
|
+
PostgreSQLDriver.escape(curValue[0]) +
|
|
1085
|
+
')';
|
|
1086
|
+
params[value] = `${curValue[1]}`;
|
|
975
1087
|
}
|
|
976
1088
|
else {
|
|
977
1089
|
if (curQuery) {
|
|
@@ -1008,13 +1120,22 @@ export default class PostgreSQLDriver extends NymphDriver {
|
|
|
1008
1120
|
break;
|
|
1009
1121
|
case 'search':
|
|
1010
1122
|
case '!search':
|
|
1011
|
-
if (curValue[0] === 'cdate' ||
|
|
1123
|
+
if (curValue[0] === 'cdate' ||
|
|
1124
|
+
curValue[0] === 'mdate' ||
|
|
1125
|
+
(this.nymph.tilmeld != null &&
|
|
1126
|
+
(curValue[0] === 'user' ||
|
|
1127
|
+
curValue[0] === 'group' ||
|
|
1128
|
+
curValue[0] === 'acUser' ||
|
|
1129
|
+
curValue[0] === 'acGroup' ||
|
|
1130
|
+
curValue[0] === 'acOther' ||
|
|
1131
|
+
curValue[0] === 'acRead' ||
|
|
1132
|
+
curValue[0] === 'acWrite' ||
|
|
1133
|
+
curValue[0] === 'acFull'))) {
|
|
1012
1134
|
if (curQuery) {
|
|
1013
1135
|
curQuery += typeIsOr ? ' OR ' : ' AND ';
|
|
1014
1136
|
}
|
|
1015
1137
|
curQuery +=
|
|
1016
1138
|
(xor(typeIsNot, clauseNot) ? 'NOT ' : '') + '(FALSE)';
|
|
1017
|
-
break;
|
|
1018
1139
|
}
|
|
1019
1140
|
else {
|
|
1020
1141
|
if (curQuery) {
|
|
@@ -1133,35 +1254,31 @@ export default class PostgreSQLDriver extends NymphDriver {
|
|
|
1133
1254
|
break;
|
|
1134
1255
|
case 'match':
|
|
1135
1256
|
case '!match':
|
|
1136
|
-
if (curValue[0] === 'cdate'
|
|
1257
|
+
if (curValue[0] === 'cdate' ||
|
|
1258
|
+
curValue[0] === 'mdate' ||
|
|
1259
|
+
(this.nymph.tilmeld != null &&
|
|
1260
|
+
(curValue[0] === 'user' ||
|
|
1261
|
+
curValue[0] === 'group' ||
|
|
1262
|
+
curValue[0] === 'acUser' ||
|
|
1263
|
+
curValue[0] === 'acGroup' ||
|
|
1264
|
+
curValue[0] === 'acOther' ||
|
|
1265
|
+
curValue[0] === 'acRead' ||
|
|
1266
|
+
curValue[0] === 'acWrite' ||
|
|
1267
|
+
curValue[0] === 'acFull'))) {
|
|
1137
1268
|
if (curQuery) {
|
|
1138
1269
|
curQuery += typeIsOr ? ' OR ' : ' AND ';
|
|
1139
1270
|
}
|
|
1140
|
-
const
|
|
1141
|
-
curQuery +=
|
|
1142
|
-
(xor(typeIsNot, clauseNot) ? 'NOT ' : '') +
|
|
1143
|
-
'(' +
|
|
1144
|
-
ieTable +
|
|
1145
|
-
'."cdate" ~ @' +
|
|
1146
|
-
cdate +
|
|
1147
|
-
')';
|
|
1148
|
-
params[cdate] = curValue[1];
|
|
1149
|
-
break;
|
|
1150
|
-
}
|
|
1151
|
-
else if (curValue[0] === 'mdate') {
|
|
1152
|
-
if (curQuery) {
|
|
1153
|
-
curQuery += typeIsOr ? ' OR ' : ' AND ';
|
|
1154
|
-
}
|
|
1155
|
-
const mdate = `param${++count.i}`;
|
|
1271
|
+
const value = `param${++count.i}`;
|
|
1156
1272
|
curQuery +=
|
|
1157
1273
|
(xor(typeIsNot, clauseNot) ? 'NOT ' : '') +
|
|
1158
1274
|
'(' +
|
|
1159
1275
|
ieTable +
|
|
1160
|
-
'.
|
|
1161
|
-
|
|
1276
|
+
'.' +
|
|
1277
|
+
PostgreSQLDriver.escape(curValue[0]) +
|
|
1278
|
+
' ~ @' +
|
|
1279
|
+
value +
|
|
1162
1280
|
')';
|
|
1163
|
-
params[
|
|
1164
|
-
break;
|
|
1281
|
+
params[value] = curValue[1];
|
|
1165
1282
|
}
|
|
1166
1283
|
else {
|
|
1167
1284
|
if (curQuery) {
|
|
@@ -1186,35 +1303,31 @@ export default class PostgreSQLDriver extends NymphDriver {
|
|
|
1186
1303
|
break;
|
|
1187
1304
|
case 'imatch':
|
|
1188
1305
|
case '!imatch':
|
|
1189
|
-
if (curValue[0] === 'cdate'
|
|
1306
|
+
if (curValue[0] === 'cdate' ||
|
|
1307
|
+
curValue[0] === 'mdate' ||
|
|
1308
|
+
(this.nymph.tilmeld != null &&
|
|
1309
|
+
(curValue[0] === 'user' ||
|
|
1310
|
+
curValue[0] === 'group' ||
|
|
1311
|
+
curValue[0] === 'acUser' ||
|
|
1312
|
+
curValue[0] === 'acGroup' ||
|
|
1313
|
+
curValue[0] === 'acOther' ||
|
|
1314
|
+
curValue[0] === 'acRead' ||
|
|
1315
|
+
curValue[0] === 'acWrite' ||
|
|
1316
|
+
curValue[0] === 'acFull'))) {
|
|
1190
1317
|
if (curQuery) {
|
|
1191
1318
|
curQuery += typeIsOr ? ' OR ' : ' AND ';
|
|
1192
1319
|
}
|
|
1193
|
-
const
|
|
1194
|
-
curQuery +=
|
|
1195
|
-
(xor(typeIsNot, clauseNot) ? 'NOT ' : '') +
|
|
1196
|
-
'(' +
|
|
1197
|
-
ieTable +
|
|
1198
|
-
'."cdate" ~* @' +
|
|
1199
|
-
cdate +
|
|
1200
|
-
')';
|
|
1201
|
-
params[cdate] = curValue[1];
|
|
1202
|
-
break;
|
|
1203
|
-
}
|
|
1204
|
-
else if (curValue[0] === 'mdate') {
|
|
1205
|
-
if (curQuery) {
|
|
1206
|
-
curQuery += typeIsOr ? ' OR ' : ' AND ';
|
|
1207
|
-
}
|
|
1208
|
-
const mdate = `param${++count.i}`;
|
|
1320
|
+
const value = `param${++count.i}`;
|
|
1209
1321
|
curQuery +=
|
|
1210
1322
|
(xor(typeIsNot, clauseNot) ? 'NOT ' : '') +
|
|
1211
1323
|
'(' +
|
|
1212
1324
|
ieTable +
|
|
1213
|
-
'.
|
|
1214
|
-
|
|
1325
|
+
'.' +
|
|
1326
|
+
PostgreSQLDriver.escape(curValue[0]) +
|
|
1327
|
+
' ~* @' +
|
|
1328
|
+
value +
|
|
1215
1329
|
')';
|
|
1216
|
-
params[
|
|
1217
|
-
break;
|
|
1330
|
+
params[value] = curValue[1];
|
|
1218
1331
|
}
|
|
1219
1332
|
else {
|
|
1220
1333
|
if (curQuery) {
|
|
@@ -1239,35 +1352,31 @@ export default class PostgreSQLDriver extends NymphDriver {
|
|
|
1239
1352
|
break;
|
|
1240
1353
|
case 'like':
|
|
1241
1354
|
case '!like':
|
|
1242
|
-
if (curValue[0] === 'cdate'
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
'
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
')';
|
|
1254
|
-
params[cdate] = curValue[1];
|
|
1255
|
-
break;
|
|
1256
|
-
}
|
|
1257
|
-
else if (curValue[0] === 'mdate') {
|
|
1355
|
+
if (curValue[0] === 'cdate' ||
|
|
1356
|
+
curValue[0] === 'mdate' ||
|
|
1357
|
+
(this.nymph.tilmeld != null &&
|
|
1358
|
+
(curValue[0] === 'user' ||
|
|
1359
|
+
curValue[0] === 'group' ||
|
|
1360
|
+
curValue[0] === 'acUser' ||
|
|
1361
|
+
curValue[0] === 'acGroup' ||
|
|
1362
|
+
curValue[0] === 'acOther' ||
|
|
1363
|
+
curValue[0] === 'acRead' ||
|
|
1364
|
+
curValue[0] === 'acWrite' ||
|
|
1365
|
+
curValue[0] === 'acFull'))) {
|
|
1258
1366
|
if (curQuery) {
|
|
1259
1367
|
curQuery += typeIsOr ? ' OR ' : ' AND ';
|
|
1260
1368
|
}
|
|
1261
|
-
const
|
|
1369
|
+
const value = `param${++count.i}`;
|
|
1262
1370
|
curQuery +=
|
|
1263
1371
|
(xor(typeIsNot, clauseNot) ? 'NOT ' : '') +
|
|
1264
1372
|
'(' +
|
|
1265
1373
|
ieTable +
|
|
1266
|
-
'.
|
|
1267
|
-
|
|
1374
|
+
'.' +
|
|
1375
|
+
PostgreSQLDriver.escape(curValue[0]) +
|
|
1376
|
+
' LIKE @' +
|
|
1377
|
+
value +
|
|
1268
1378
|
')';
|
|
1269
|
-
params[
|
|
1270
|
-
break;
|
|
1379
|
+
params[value] = curValue[1];
|
|
1271
1380
|
}
|
|
1272
1381
|
else {
|
|
1273
1382
|
if (curQuery) {
|
|
@@ -1292,35 +1401,31 @@ export default class PostgreSQLDriver extends NymphDriver {
|
|
|
1292
1401
|
break;
|
|
1293
1402
|
case 'ilike':
|
|
1294
1403
|
case '!ilike':
|
|
1295
|
-
if (curValue[0] === 'cdate'
|
|
1404
|
+
if (curValue[0] === 'cdate' ||
|
|
1405
|
+
curValue[0] === 'mdate' ||
|
|
1406
|
+
(this.nymph.tilmeld != null &&
|
|
1407
|
+
(curValue[0] === 'user' ||
|
|
1408
|
+
curValue[0] === 'group' ||
|
|
1409
|
+
curValue[0] === 'acUser' ||
|
|
1410
|
+
curValue[0] === 'acGroup' ||
|
|
1411
|
+
curValue[0] === 'acOther' ||
|
|
1412
|
+
curValue[0] === 'acRead' ||
|
|
1413
|
+
curValue[0] === 'acWrite' ||
|
|
1414
|
+
curValue[0] === 'acFull'))) {
|
|
1296
1415
|
if (curQuery) {
|
|
1297
1416
|
curQuery += typeIsOr ? ' OR ' : ' AND ';
|
|
1298
1417
|
}
|
|
1299
|
-
const
|
|
1300
|
-
curQuery +=
|
|
1301
|
-
(xor(typeIsNot, clauseNot) ? 'NOT ' : '') +
|
|
1302
|
-
'(' +
|
|
1303
|
-
ieTable +
|
|
1304
|
-
'."cdate" ILIKE @' +
|
|
1305
|
-
cdate +
|
|
1306
|
-
')';
|
|
1307
|
-
params[cdate] = curValue[1];
|
|
1308
|
-
break;
|
|
1309
|
-
}
|
|
1310
|
-
else if (curValue[0] === 'mdate') {
|
|
1311
|
-
if (curQuery) {
|
|
1312
|
-
curQuery += typeIsOr ? ' OR ' : ' AND ';
|
|
1313
|
-
}
|
|
1314
|
-
const mdate = `param${++count.i}`;
|
|
1418
|
+
const value = `param${++count.i}`;
|
|
1315
1419
|
curQuery +=
|
|
1316
1420
|
(xor(typeIsNot, clauseNot) ? 'NOT ' : '') +
|
|
1317
1421
|
'(' +
|
|
1318
1422
|
ieTable +
|
|
1319
|
-
'.
|
|
1320
|
-
|
|
1423
|
+
'.' +
|
|
1424
|
+
PostgreSQLDriver.escape(curValue[0]) +
|
|
1425
|
+
' ILIKE @' +
|
|
1426
|
+
value +
|
|
1321
1427
|
')';
|
|
1322
|
-
params[
|
|
1323
|
-
break;
|
|
1428
|
+
params[value] = curValue[1];
|
|
1324
1429
|
}
|
|
1325
1430
|
else {
|
|
1326
1431
|
if (curQuery) {
|
|
@@ -1345,35 +1450,31 @@ export default class PostgreSQLDriver extends NymphDriver {
|
|
|
1345
1450
|
break;
|
|
1346
1451
|
case 'gt':
|
|
1347
1452
|
case '!gt':
|
|
1348
|
-
if (curValue[0] === 'cdate'
|
|
1453
|
+
if (curValue[0] === 'cdate' ||
|
|
1454
|
+
curValue[0] === 'mdate' ||
|
|
1455
|
+
(this.nymph.tilmeld != null &&
|
|
1456
|
+
(curValue[0] === 'user' ||
|
|
1457
|
+
curValue[0] === 'group' ||
|
|
1458
|
+
curValue[0] === 'acUser' ||
|
|
1459
|
+
curValue[0] === 'acGroup' ||
|
|
1460
|
+
curValue[0] === 'acOther' ||
|
|
1461
|
+
curValue[0] === 'acRead' ||
|
|
1462
|
+
curValue[0] === 'acWrite' ||
|
|
1463
|
+
curValue[0] === 'acFull'))) {
|
|
1349
1464
|
if (curQuery) {
|
|
1350
1465
|
curQuery += typeIsOr ? ' OR ' : ' AND ';
|
|
1351
1466
|
}
|
|
1352
|
-
const
|
|
1353
|
-
curQuery +=
|
|
1354
|
-
(xor(typeIsNot, clauseNot) ? 'NOT ' : '') +
|
|
1355
|
-
ieTable +
|
|
1356
|
-
'."cdate">@' +
|
|
1357
|
-
cdate;
|
|
1358
|
-
params[cdate] = isNaN(Number(curValue[1]))
|
|
1359
|
-
? null
|
|
1360
|
-
: Number(curValue[1]);
|
|
1361
|
-
break;
|
|
1362
|
-
}
|
|
1363
|
-
else if (curValue[0] === 'mdate') {
|
|
1364
|
-
if (curQuery) {
|
|
1365
|
-
curQuery += typeIsOr ? ' OR ' : ' AND ';
|
|
1366
|
-
}
|
|
1367
|
-
const mdate = `param${++count.i}`;
|
|
1467
|
+
const value = `param${++count.i}`;
|
|
1368
1468
|
curQuery +=
|
|
1369
1469
|
(xor(typeIsNot, clauseNot) ? 'NOT ' : '') +
|
|
1370
1470
|
ieTable +
|
|
1371
|
-
'.
|
|
1372
|
-
|
|
1373
|
-
|
|
1471
|
+
'.' +
|
|
1472
|
+
PostgreSQLDriver.escape(curValue[0]) +
|
|
1473
|
+
'>@' +
|
|
1474
|
+
value;
|
|
1475
|
+
params[value] = isNaN(Number(curValue[1]))
|
|
1374
1476
|
? null
|
|
1375
1477
|
: Number(curValue[1]);
|
|
1376
|
-
break;
|
|
1377
1478
|
}
|
|
1378
1479
|
else {
|
|
1379
1480
|
if (curQuery) {
|
|
@@ -1400,35 +1501,31 @@ export default class PostgreSQLDriver extends NymphDriver {
|
|
|
1400
1501
|
break;
|
|
1401
1502
|
case 'gte':
|
|
1402
1503
|
case '!gte':
|
|
1403
|
-
if (curValue[0] === 'cdate'
|
|
1504
|
+
if (curValue[0] === 'cdate' ||
|
|
1505
|
+
curValue[0] === 'mdate' ||
|
|
1506
|
+
(this.nymph.tilmeld != null &&
|
|
1507
|
+
(curValue[0] === 'user' ||
|
|
1508
|
+
curValue[0] === 'group' ||
|
|
1509
|
+
curValue[0] === 'acUser' ||
|
|
1510
|
+
curValue[0] === 'acGroup' ||
|
|
1511
|
+
curValue[0] === 'acOther' ||
|
|
1512
|
+
curValue[0] === 'acRead' ||
|
|
1513
|
+
curValue[0] === 'acWrite' ||
|
|
1514
|
+
curValue[0] === 'acFull'))) {
|
|
1404
1515
|
if (curQuery) {
|
|
1405
1516
|
curQuery += typeIsOr ? ' OR ' : ' AND ';
|
|
1406
1517
|
}
|
|
1407
|
-
const
|
|
1408
|
-
curQuery +=
|
|
1409
|
-
(xor(typeIsNot, clauseNot) ? 'NOT ' : '') +
|
|
1410
|
-
ieTable +
|
|
1411
|
-
'."cdate">=@' +
|
|
1412
|
-
cdate;
|
|
1413
|
-
params[cdate] = isNaN(Number(curValue[1]))
|
|
1414
|
-
? null
|
|
1415
|
-
: Number(curValue[1]);
|
|
1416
|
-
break;
|
|
1417
|
-
}
|
|
1418
|
-
else if (curValue[0] === 'mdate') {
|
|
1419
|
-
if (curQuery) {
|
|
1420
|
-
curQuery += typeIsOr ? ' OR ' : ' AND ';
|
|
1421
|
-
}
|
|
1422
|
-
const mdate = `param${++count.i}`;
|
|
1518
|
+
const value = `param${++count.i}`;
|
|
1423
1519
|
curQuery +=
|
|
1424
1520
|
(xor(typeIsNot, clauseNot) ? 'NOT ' : '') +
|
|
1425
1521
|
ieTable +
|
|
1426
|
-
'.
|
|
1427
|
-
|
|
1428
|
-
|
|
1522
|
+
'.' +
|
|
1523
|
+
PostgreSQLDriver.escape(curValue[0]) +
|
|
1524
|
+
'>=@' +
|
|
1525
|
+
value;
|
|
1526
|
+
params[value] = isNaN(Number(curValue[1]))
|
|
1429
1527
|
? null
|
|
1430
1528
|
: Number(curValue[1]);
|
|
1431
|
-
break;
|
|
1432
1529
|
}
|
|
1433
1530
|
else {
|
|
1434
1531
|
if (curQuery) {
|
|
@@ -1455,35 +1552,31 @@ export default class PostgreSQLDriver extends NymphDriver {
|
|
|
1455
1552
|
break;
|
|
1456
1553
|
case 'lt':
|
|
1457
1554
|
case '!lt':
|
|
1458
|
-
if (curValue[0] === 'cdate'
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
'
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
? null
|
|
1470
|
-
: Number(curValue[1]);
|
|
1471
|
-
break;
|
|
1472
|
-
}
|
|
1473
|
-
else if (curValue[0] === 'mdate') {
|
|
1555
|
+
if (curValue[0] === 'cdate' ||
|
|
1556
|
+
curValue[0] === 'mdate' ||
|
|
1557
|
+
(this.nymph.tilmeld != null &&
|
|
1558
|
+
(curValue[0] === 'user' ||
|
|
1559
|
+
curValue[0] === 'group' ||
|
|
1560
|
+
curValue[0] === 'acUser' ||
|
|
1561
|
+
curValue[0] === 'acGroup' ||
|
|
1562
|
+
curValue[0] === 'acOther' ||
|
|
1563
|
+
curValue[0] === 'acRead' ||
|
|
1564
|
+
curValue[0] === 'acWrite' ||
|
|
1565
|
+
curValue[0] === 'acFull'))) {
|
|
1474
1566
|
if (curQuery) {
|
|
1475
1567
|
curQuery += typeIsOr ? ' OR ' : ' AND ';
|
|
1476
1568
|
}
|
|
1477
|
-
const
|
|
1569
|
+
const value = `param${++count.i}`;
|
|
1478
1570
|
curQuery +=
|
|
1479
1571
|
(xor(typeIsNot, clauseNot) ? 'NOT ' : '') +
|
|
1480
1572
|
ieTable +
|
|
1481
|
-
'.
|
|
1482
|
-
|
|
1483
|
-
|
|
1573
|
+
'.' +
|
|
1574
|
+
PostgreSQLDriver.escape(curValue[0]) +
|
|
1575
|
+
'<@' +
|
|
1576
|
+
value;
|
|
1577
|
+
params[value] = isNaN(Number(curValue[1]))
|
|
1484
1578
|
? null
|
|
1485
1579
|
: Number(curValue[1]);
|
|
1486
|
-
break;
|
|
1487
1580
|
}
|
|
1488
1581
|
else {
|
|
1489
1582
|
if (curQuery) {
|
|
@@ -1510,35 +1603,31 @@ export default class PostgreSQLDriver extends NymphDriver {
|
|
|
1510
1603
|
break;
|
|
1511
1604
|
case 'lte':
|
|
1512
1605
|
case '!lte':
|
|
1513
|
-
if (curValue[0] === 'cdate'
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
'
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
? null
|
|
1525
|
-
: Number(curValue[1]);
|
|
1526
|
-
break;
|
|
1527
|
-
}
|
|
1528
|
-
else if (curValue[0] === 'mdate') {
|
|
1606
|
+
if (curValue[0] === 'cdate' ||
|
|
1607
|
+
curValue[0] === 'mdate' ||
|
|
1608
|
+
(this.nymph.tilmeld != null &&
|
|
1609
|
+
(curValue[0] === 'user' ||
|
|
1610
|
+
curValue[0] === 'group' ||
|
|
1611
|
+
curValue[0] === 'acUser' ||
|
|
1612
|
+
curValue[0] === 'acGroup' ||
|
|
1613
|
+
curValue[0] === 'acOther' ||
|
|
1614
|
+
curValue[0] === 'acRead' ||
|
|
1615
|
+
curValue[0] === 'acWrite' ||
|
|
1616
|
+
curValue[0] === 'acFull'))) {
|
|
1529
1617
|
if (curQuery) {
|
|
1530
1618
|
curQuery += typeIsOr ? ' OR ' : ' AND ';
|
|
1531
1619
|
}
|
|
1532
|
-
const
|
|
1620
|
+
const value = `param${++count.i}`;
|
|
1533
1621
|
curQuery +=
|
|
1534
1622
|
(xor(typeIsNot, clauseNot) ? 'NOT ' : '') +
|
|
1535
1623
|
ieTable +
|
|
1536
|
-
'.
|
|
1537
|
-
|
|
1538
|
-
|
|
1624
|
+
'.' +
|
|
1625
|
+
PostgreSQLDriver.escape(curValue[0]) +
|
|
1626
|
+
'<=@' +
|
|
1627
|
+
value;
|
|
1628
|
+
params[value] = isNaN(Number(curValue[1]))
|
|
1539
1629
|
? null
|
|
1540
1630
|
: Number(curValue[1]);
|
|
1541
|
-
break;
|
|
1542
1631
|
}
|
|
1543
1632
|
else {
|
|
1544
1633
|
if (curQuery) {
|
|
@@ -1578,21 +1667,52 @@ export default class PostgreSQLDriver extends NymphDriver {
|
|
|
1578
1667
|
if (curQuery) {
|
|
1579
1668
|
curQuery += typeIsOr ? ' OR ' : ' AND ';
|
|
1580
1669
|
}
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1670
|
+
if (this.nymph.tilmeld != null &&
|
|
1671
|
+
(curValue[0] === 'user' || curValue[0] === 'group')) {
|
|
1672
|
+
const guid = `param${++count.i}`;
|
|
1673
|
+
curQuery +=
|
|
1674
|
+
(xor(typeIsNot, clauseNot) ? 'NOT ' : '') +
|
|
1675
|
+
ieTable +
|
|
1676
|
+
'.' +
|
|
1677
|
+
PostgreSQLDriver.escape(curValue[0]) +
|
|
1678
|
+
'=decode(@' +
|
|
1679
|
+
guid +
|
|
1680
|
+
", 'hex')";
|
|
1681
|
+
params[guid] = curQguid;
|
|
1682
|
+
}
|
|
1683
|
+
else if (this.nymph.tilmeld != null &&
|
|
1684
|
+
(curValue[0] === 'acRead' ||
|
|
1685
|
+
curValue[0] === 'acWrite' ||
|
|
1686
|
+
curValue[0] === 'acFull')) {
|
|
1687
|
+
const guid = `param${++count.i}`;
|
|
1688
|
+
curQuery +=
|
|
1689
|
+
(xor(typeIsNot, clauseNot) ? 'NOT ' : '') +
|
|
1690
|
+
'decode(@' +
|
|
1691
|
+
guid +
|
|
1692
|
+
", 'hex')=ANY(" +
|
|
1693
|
+
ieTable +
|
|
1694
|
+
'.' +
|
|
1695
|
+
PostgreSQLDriver.escape(curValue[0]) +
|
|
1696
|
+
')';
|
|
1697
|
+
params[guid] = curQguid;
|
|
1698
|
+
}
|
|
1699
|
+
else {
|
|
1700
|
+
const name = `param${++count.i}`;
|
|
1701
|
+
const guid = `param${++count.i}`;
|
|
1702
|
+
curQuery +=
|
|
1703
|
+
(xor(typeIsNot, clauseNot) ? 'NOT ' : '') +
|
|
1704
|
+
'EXISTS (SELECT "guid" FROM ' +
|
|
1705
|
+
PostgreSQLDriver.escape(this.prefix + 'references_' + etype) +
|
|
1706
|
+
' WHERE "guid"=' +
|
|
1707
|
+
ieTable +
|
|
1708
|
+
'."guid" AND "name"=@' +
|
|
1709
|
+
name +
|
|
1710
|
+
' AND "reference"=decode(@' +
|
|
1711
|
+
guid +
|
|
1712
|
+
", 'hex'))";
|
|
1713
|
+
params[name] = curValue[0];
|
|
1714
|
+
params[guid] = curQguid;
|
|
1715
|
+
}
|
|
1596
1716
|
break;
|
|
1597
1717
|
case 'selector':
|
|
1598
1718
|
case '!selector':
|
|
@@ -1612,34 +1732,82 @@ export default class PostgreSQLDriver extends NymphDriver {
|
|
|
1612
1732
|
const [qrefOptions, ...qrefSelectors] = curValue[1];
|
|
1613
1733
|
const QrefEntityClass = qrefOptions.class;
|
|
1614
1734
|
etypes.push(QrefEntityClass.ETYPE);
|
|
1615
|
-
const qrefQuery = this.makeEntityQuery({
|
|
1616
|
-
...qrefOptions,
|
|
1617
|
-
sort: qrefOptions.sort ?? null,
|
|
1618
|
-
return: 'guid',
|
|
1619
|
-
class: QrefEntityClass,
|
|
1620
|
-
}, qrefSelectors, QrefEntityClass.ETYPE, count, params, false, makeTableSuffix(), etypes, 'r' + referenceTableSuffix + '."reference"');
|
|
1621
1735
|
if (curQuery) {
|
|
1622
1736
|
curQuery += typeIsOr ? ' OR ' : ' AND ';
|
|
1623
1737
|
}
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1738
|
+
if (this.nymph.tilmeld != null &&
|
|
1739
|
+
(curValue[0] === 'user' || curValue[0] === 'group')) {
|
|
1740
|
+
const qrefQuery = this.makeEntityQuery({
|
|
1741
|
+
...qrefOptions,
|
|
1742
|
+
sort: qrefOptions.sort ?? null,
|
|
1743
|
+
return: 'guid',
|
|
1744
|
+
class: QrefEntityClass,
|
|
1745
|
+
}, qrefSelectors, QrefEntityClass.ETYPE, count, params, false, makeTableSuffix(), etypes, 'r' +
|
|
1630
1746
|
referenceTableSuffix +
|
|
1631
|
-
'
|
|
1632
|
-
|
|
1633
|
-
|
|
1747
|
+
'.' +
|
|
1748
|
+
PostgreSQLDriver.escape(curValue[0]));
|
|
1749
|
+
curQuery +=
|
|
1750
|
+
(xor(typeIsNot, clauseNot) ? 'NOT ' : '') +
|
|
1751
|
+
'EXISTS (SELECT "guid" FROM ' +
|
|
1752
|
+
PostgreSQLDriver.escape(this.prefix + 'entities_' + etype) +
|
|
1753
|
+
' r' +
|
|
1754
|
+
referenceTableSuffix +
|
|
1755
|
+
' WHERE r' +
|
|
1756
|
+
referenceTableSuffix +
|
|
1757
|
+
'."guid"=' +
|
|
1758
|
+
ieTable +
|
|
1759
|
+
'."guid" AND EXISTS (' +
|
|
1760
|
+
qrefQuery.query +
|
|
1761
|
+
'))';
|
|
1762
|
+
}
|
|
1763
|
+
else if (this.nymph.tilmeld != null &&
|
|
1764
|
+
(curValue[0] === 'acRead' ||
|
|
1765
|
+
curValue[0] === 'acWrite' ||
|
|
1766
|
+
curValue[0] === 'acFull')) {
|
|
1767
|
+
const qrefQuery = this.makeEntityQuery({
|
|
1768
|
+
...qrefOptions,
|
|
1769
|
+
sort: qrefOptions.sort ?? null,
|
|
1770
|
+
return: 'guid',
|
|
1771
|
+
class: QrefEntityClass,
|
|
1772
|
+
}, qrefSelectors, QrefEntityClass.ETYPE, count, params, false, makeTableSuffix(), etypes, undefined, (guid) => guid +
|
|
1773
|
+
'=ANY(' +
|
|
1634
1774
|
ieTable +
|
|
1635
|
-
'.
|
|
1636
|
-
|
|
1637
|
-
'
|
|
1638
|
-
|
|
1639
|
-
'
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1775
|
+
'.' +
|
|
1776
|
+
PostgreSQLDriver.escape(curValue[0]) +
|
|
1777
|
+
')');
|
|
1778
|
+
curQuery +=
|
|
1779
|
+
(xor(typeIsNot, clauseNot) ? 'NOT ' : '') +
|
|
1780
|
+
'EXISTS (' +
|
|
1781
|
+
qrefQuery.query +
|
|
1782
|
+
')';
|
|
1783
|
+
}
|
|
1784
|
+
else {
|
|
1785
|
+
const qrefQuery = this.makeEntityQuery({
|
|
1786
|
+
...qrefOptions,
|
|
1787
|
+
sort: qrefOptions.sort ?? null,
|
|
1788
|
+
return: 'guid',
|
|
1789
|
+
class: QrefEntityClass,
|
|
1790
|
+
}, qrefSelectors, QrefEntityClass.ETYPE, count, params, false, makeTableSuffix(), etypes, 'r' + referenceTableSuffix + '."reference"');
|
|
1791
|
+
const qrefName = `param${++count.i}`;
|
|
1792
|
+
curQuery +=
|
|
1793
|
+
(xor(typeIsNot, clauseNot) ? 'NOT ' : '') +
|
|
1794
|
+
'EXISTS (SELECT "guid" FROM ' +
|
|
1795
|
+
PostgreSQLDriver.escape(this.prefix + 'references_' + etype) +
|
|
1796
|
+
' r' +
|
|
1797
|
+
referenceTableSuffix +
|
|
1798
|
+
' WHERE r' +
|
|
1799
|
+
referenceTableSuffix +
|
|
1800
|
+
'."guid"=' +
|
|
1801
|
+
ieTable +
|
|
1802
|
+
'."guid" AND r' +
|
|
1803
|
+
referenceTableSuffix +
|
|
1804
|
+
'."name"=@' +
|
|
1805
|
+
qrefName +
|
|
1806
|
+
' AND EXISTS (' +
|
|
1807
|
+
qrefQuery.query +
|
|
1808
|
+
'))';
|
|
1809
|
+
params[qrefName] = curValue[0];
|
|
1810
|
+
}
|
|
1643
1811
|
break;
|
|
1644
1812
|
}
|
|
1645
1813
|
}
|
|
@@ -1699,9 +1867,11 @@ export default class PostgreSQLDriver extends NymphDriver {
|
|
|
1699
1867
|
offset = ` OFFSET ${Math.floor(isNaN(Number(options.offset)) ? 0 : Number(options.offset))}`;
|
|
1700
1868
|
}
|
|
1701
1869
|
const whereClause = queryParts.join(') AND (');
|
|
1702
|
-
const guidClause =
|
|
1703
|
-
? `${ieTable}."guid"
|
|
1704
|
-
:
|
|
1870
|
+
const guidClause = guidExplicitSelector
|
|
1871
|
+
? `${guidExplicitSelector(`${ieTable}."guid"`)} AND `
|
|
1872
|
+
: guidSelector
|
|
1873
|
+
? `${ieTable}."guid"=${guidSelector} AND `
|
|
1874
|
+
: '';
|
|
1705
1875
|
if (options.return === 'count') {
|
|
1706
1876
|
if (limit || offset) {
|
|
1707
1877
|
query = `SELECT COUNT(${countTable}."guid") AS "count" FROM (
|
|
@@ -1732,6 +1902,14 @@ export default class PostgreSQLDriver extends NymphDriver {
|
|
|
1732
1902
|
${eTable}."tags",
|
|
1733
1903
|
${eTable}."cdate",
|
|
1734
1904
|
${eTable}."mdate",
|
|
1905
|
+
encode(${eTable}."user", 'hex') AS "user",
|
|
1906
|
+
encode(${eTable}."group", 'hex') AS "group",
|
|
1907
|
+
${eTable}."acUser",
|
|
1908
|
+
${eTable}."acGroup",
|
|
1909
|
+
${eTable}."acOther",
|
|
1910
|
+
array(SELECT encode(n, 'hex') FROM unnest(${eTable}."acRead") AS n) as "acRead",
|
|
1911
|
+
array(SELECT encode(n, 'hex') FROM unnest(${eTable}."acWrite") AS n) as "acWrite",
|
|
1912
|
+
array(SELECT encode(n, 'hex') FROM unnest(${eTable}."acFull") AS n) as "acFull",
|
|
1735
1913
|
${dTable}."name",
|
|
1736
1914
|
${dTable}."value",
|
|
1737
1915
|
${dTable}."json",
|
|
@@ -1764,9 +1942,11 @@ export default class PostgreSQLDriver extends NymphDriver {
|
|
|
1764
1942
|
if ('offset' in options) {
|
|
1765
1943
|
offset = ` OFFSET ${Math.floor(isNaN(Number(options.offset)) ? 0 : Number(options.offset))}`;
|
|
1766
1944
|
}
|
|
1767
|
-
const guidClause =
|
|
1768
|
-
? ` WHERE ${ieTable}."guid"
|
|
1769
|
-
:
|
|
1945
|
+
const guidClause = guidExplicitSelector
|
|
1946
|
+
? ` WHERE ${guidExplicitSelector(`${ieTable}."guid"`)}`
|
|
1947
|
+
: guidSelector
|
|
1948
|
+
? ` WHERE ${ieTable}."guid"=${guidSelector}`
|
|
1949
|
+
: '';
|
|
1770
1950
|
if (options.return === 'count') {
|
|
1771
1951
|
if (limit || offset) {
|
|
1772
1952
|
query = `SELECT COUNT(${countTable}."guid") AS "count" FROM (
|
|
@@ -1796,6 +1976,14 @@ export default class PostgreSQLDriver extends NymphDriver {
|
|
|
1796
1976
|
${eTable}."tags",
|
|
1797
1977
|
${eTable}."cdate",
|
|
1798
1978
|
${eTable}."mdate",
|
|
1979
|
+
encode(${eTable}."user", 'hex') AS "user",
|
|
1980
|
+
encode(${eTable}."group", 'hex') AS "group",
|
|
1981
|
+
${eTable}."acUser",
|
|
1982
|
+
${eTable}."acGroup",
|
|
1983
|
+
${eTable}."acOther",
|
|
1984
|
+
array(SELECT encode(n, 'hex') FROM unnest(${eTable}."acRead") AS n) as "acRead",
|
|
1985
|
+
array(SELECT encode(n, 'hex') FROM unnest(${eTable}."acWrite") AS n) as "acWrite",
|
|
1986
|
+
array(SELECT encode(n, 'hex') FROM unnest(${eTable}."acFull") AS n) as "acFull",
|
|
1799
1987
|
${dTable}."name",
|
|
1800
1988
|
${dTable}."value",
|
|
1801
1989
|
${dTable}."json",
|
|
@@ -1819,6 +2007,14 @@ export default class PostgreSQLDriver extends NymphDriver {
|
|
|
1819
2007
|
${eTable}."tags",
|
|
1820
2008
|
${eTable}."cdate",
|
|
1821
2009
|
${eTable}."mdate",
|
|
2010
|
+
encode(${eTable}."user", 'hex') AS "user",
|
|
2011
|
+
encode(${eTable}."group", 'hex') AS "group",
|
|
2012
|
+
${eTable}."acUser",
|
|
2013
|
+
${eTable}."acGroup",
|
|
2014
|
+
${eTable}."acOther",
|
|
2015
|
+
array(SELECT encode(n, 'hex') FROM unnest(${eTable}."acRead") AS n) as "acRead",
|
|
2016
|
+
array(SELECT encode(n, 'hex') FROM unnest(${eTable}."acWrite") AS n) as "acWrite",
|
|
2017
|
+
array(SELECT encode(n, 'hex') FROM unnest(${eTable}."acFull") AS n) as "acFull",
|
|
1822
2018
|
${dTable}."name",
|
|
1823
2019
|
${dTable}."value",
|
|
1824
2020
|
${dTable}."json",
|
|
@@ -1827,7 +2023,7 @@ export default class PostgreSQLDriver extends NymphDriver {
|
|
|
1827
2023
|
FROM ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}`)} ${eTable}
|
|
1828
2024
|
LEFT JOIN ${PostgreSQLDriver.escape(`${this.prefix}data_${etype}`)} ${dTable} ON ${eTable}."guid"=${dTable}."guid"
|
|
1829
2025
|
${sortJoin}
|
|
1830
|
-
${guidSelector ? `WHERE ${eTable}."guid"=${guidSelector}` : ''}
|
|
2026
|
+
${guidExplicitSelector ? `WHERE ${guidExplicitSelector(`${eTable}."guid"`)}` : guidSelector ? `WHERE ${eTable}."guid"=${guidSelector}` : ''}
|
|
1831
2027
|
${sortBy ? sortBy + ', ' : 'ORDER BY '}${eTable}."guid"`;
|
|
1832
2028
|
}
|
|
1833
2029
|
}
|
|
@@ -1859,6 +2055,14 @@ export default class PostgreSQLDriver extends NymphDriver {
|
|
|
1859
2055
|
tags: row.tags.filter((tag) => tag),
|
|
1860
2056
|
cdate: isNaN(Number(row.cdate)) ? Date.now() : Number(row.cdate),
|
|
1861
2057
|
mdate: isNaN(Number(row.mdate)) ? Date.now() : Number(row.mdate),
|
|
2058
|
+
user: row.user,
|
|
2059
|
+
group: row.group,
|
|
2060
|
+
acUser: row.acUser,
|
|
2061
|
+
acGroup: row.acGroup,
|
|
2062
|
+
acOther: row.acOther,
|
|
2063
|
+
acRead: row.acRead?.filter((guid) => guid) ?? [],
|
|
2064
|
+
acWrite: row.acWrite?.filter((guid) => guid) ?? [],
|
|
2065
|
+
acFull: row.acFull?.filter((guid) => guid) ?? [],
|
|
1862
2066
|
}), (row) => ({
|
|
1863
2067
|
name: row.name,
|
|
1864
2068
|
svalue: row.value === 'N'
|
|
@@ -2470,6 +2674,50 @@ export default class PostgreSQLDriver extends NymphDriver {
|
|
|
2470
2674
|
nymph.driver.transaction = transaction;
|
|
2471
2675
|
return nymph;
|
|
2472
2676
|
}
|
|
2677
|
+
async removeTilmeldOldRows(etype, connection) {
|
|
2678
|
+
await this.internalTransaction('nymph-remove-tilmeld-rows');
|
|
2679
|
+
try {
|
|
2680
|
+
for (let name of [
|
|
2681
|
+
'user',
|
|
2682
|
+
'group',
|
|
2683
|
+
'acUser',
|
|
2684
|
+
'acGroup',
|
|
2685
|
+
'acOther',
|
|
2686
|
+
'acRead',
|
|
2687
|
+
'acWrite',
|
|
2688
|
+
'acFull',
|
|
2689
|
+
]) {
|
|
2690
|
+
await this.queryRun(`DELETE FROM ${PostgreSQLDriver.escape(`${this.prefix}data_${etype}`)} WHERE "name"=@name;`, {
|
|
2691
|
+
etypes: [etype],
|
|
2692
|
+
params: {
|
|
2693
|
+
name,
|
|
2694
|
+
},
|
|
2695
|
+
connection,
|
|
2696
|
+
});
|
|
2697
|
+
await this.queryRun(`DELETE FROM ${PostgreSQLDriver.escape(`${this.prefix}references_${etype}`)} WHERE "name"=@name;`, {
|
|
2698
|
+
etypes: [etype],
|
|
2699
|
+
params: {
|
|
2700
|
+
name,
|
|
2701
|
+
},
|
|
2702
|
+
connection,
|
|
2703
|
+
});
|
|
2704
|
+
await this.queryRun(`DELETE FROM ${PostgreSQLDriver.escape(`${this.prefix}tokens_${etype}`)} WHERE "name"=@name;`, {
|
|
2705
|
+
etypes: [etype],
|
|
2706
|
+
params: {
|
|
2707
|
+
name,
|
|
2708
|
+
},
|
|
2709
|
+
connection,
|
|
2710
|
+
});
|
|
2711
|
+
}
|
|
2712
|
+
}
|
|
2713
|
+
catch (e) {
|
|
2714
|
+
this.nymph.config.debugError('postgresql', `Remove tilmeld rows error: "${e}"`);
|
|
2715
|
+
await this.rollback('nymph-remove-tilmeld-rows');
|
|
2716
|
+
throw e;
|
|
2717
|
+
}
|
|
2718
|
+
await this.commit('nymph-remove-tilmeld-rows');
|
|
2719
|
+
return true;
|
|
2720
|
+
}
|
|
2473
2721
|
async needsMigration() {
|
|
2474
2722
|
const table = await this.queryGet('SELECT "table_name" AS "table_name" FROM "information_schema"."tables" WHERE "table_catalog"=@db AND "table_schema"=\'public\' AND "table_name" LIKE @prefix LIMIT 1;', {
|
|
2475
2723
|
params: {
|
|
@@ -2533,6 +2781,14 @@ export default class PostgreSQLDriver extends NymphDriver {
|
|
|
2533
2781
|
}
|
|
2534
2782
|
connection.done();
|
|
2535
2783
|
}
|
|
2784
|
+
else if (migrationType === 'tilmeldRemoveOldRows') {
|
|
2785
|
+
const etypes = await this.getEtypes();
|
|
2786
|
+
const connection = await this.getConnection(true);
|
|
2787
|
+
for (let etype of etypes) {
|
|
2788
|
+
await this.removeTilmeldOldRows(etype, connection);
|
|
2789
|
+
}
|
|
2790
|
+
connection.done();
|
|
2791
|
+
}
|
|
2536
2792
|
}
|
|
2537
2793
|
}
|
|
2538
2794
|
//# sourceMappingURL=PostgreSQLDriver.js.map
|