@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.
@@ -1620,7 +1620,7 @@ export default class PostgreSQLDriver extends NymphDriver {
1620
1620
  for (const etype of etypes) {
1621
1621
  // Export entities.
1622
1622
  const dataIterator = await this.queryIter(
1623
- `SELECT encode(e."guid", 'hex') AS "guid", e."tags", e."cdate", e."mdate", d."name", d."value", d."json", d."string", d."number"
1623
+ `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"
1624
1624
  FROM ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}`)} e
1625
1625
  LEFT JOIN ${PostgreSQLDriver.escape(
1626
1626
  `${this.prefix}data_${etype}`,
@@ -1633,10 +1633,48 @@ export default class PostgreSQLDriver extends NymphDriver {
1633
1633
  const tags = datum.value.tags.filter((tag: string) => tag).join(',');
1634
1634
  const cdate = datum.value.cdate;
1635
1635
  const mdate = datum.value.mdate;
1636
+ const user = datum.value.user;
1637
+ const group = datum.value.group;
1638
+ const acUser = datum.value.acUser;
1639
+ const acGroup = datum.value.acGroup;
1640
+ const acOther = datum.value.acOther;
1641
+ const acRead = datum.value.acRead?.filter((guid: string) => guid);
1642
+ const acWrite = datum.value.acWrite?.filter((guid: string) => guid);
1643
+ const acFull = datum.value.acFull?.filter((guid: string) => guid);
1636
1644
  let currentEntityExport: string[] = [];
1637
1645
  currentEntityExport.push(`{${guid}}<${etype}>[${tags}]`);
1638
1646
  currentEntityExport.push(`\tcdate=${JSON.stringify(cdate)}`);
1639
1647
  currentEntityExport.push(`\tmdate=${JSON.stringify(mdate)}`);
1648
+ if (this.nymph.tilmeld != null) {
1649
+ if (user != null) {
1650
+ currentEntityExport.push(
1651
+ `\tuser=${JSON.stringify(['nymph_entity_reference', user, 'User'])}`,
1652
+ );
1653
+ }
1654
+ if (group != null) {
1655
+ currentEntityExport.push(
1656
+ `\tgroup=${JSON.stringify(['nymph_entity_reference', group, 'Group'])}`,
1657
+ );
1658
+ }
1659
+ if (acUser != null) {
1660
+ currentEntityExport.push(`\tacUser=${JSON.stringify(acUser)}`);
1661
+ }
1662
+ if (acGroup != null) {
1663
+ currentEntityExport.push(`\tacGroup=${JSON.stringify(acGroup)}`);
1664
+ }
1665
+ if (acOther != null) {
1666
+ currentEntityExport.push(`\tacOther=${JSON.stringify(acOther)}`);
1667
+ }
1668
+ if (acRead != null) {
1669
+ currentEntityExport.push(`\tacRead=${JSON.stringify(acRead)}`);
1670
+ }
1671
+ if (acWrite != null) {
1672
+ currentEntityExport.push(`\tacWrite=${JSON.stringify(acWrite)}`);
1673
+ }
1674
+ if (acFull != null) {
1675
+ currentEntityExport.push(`\tacFull=${JSON.stringify(acFull)}`);
1676
+ }
1677
+ }
1640
1678
  if (datum.value.name != null) {
1641
1679
  // This do will keep going and adding the data until the
1642
1680
  // next entity is reached. $row will end on the next entity.
@@ -1689,6 +1727,7 @@ export default class PostgreSQLDriver extends NymphDriver {
1689
1727
  tableSuffix = '',
1690
1728
  etypes: string[] = [],
1691
1729
  guidSelector: string | undefined = undefined,
1730
+ guidExplicitSelector: ((guid: string) => string) | undefined = undefined,
1692
1731
  ) {
1693
1732
  if (typeof options.class?.alterOptions === 'function') {
1694
1733
  options = options.class.alterOptions(options);
@@ -1744,17 +1783,39 @@ export default class PostgreSQLDriver extends NymphDriver {
1744
1783
  if (curQuery) {
1745
1784
  curQuery += typeIsOr ? ' OR ' : ' AND ';
1746
1785
  }
1747
- const name = `param${++count.i}`;
1748
- curQuery +=
1749
- (xor(typeIsNot, clauseNot) ? 'NOT ' : '') +
1750
- 'EXISTS (SELECT "guid" FROM ' +
1751
- PostgreSQLDriver.escape(this.prefix + 'data_' + etype) +
1752
- ' WHERE "guid"=' +
1753
- ieTable +
1754
- '."guid" AND "name"=@' +
1755
- name +
1756
- ')';
1757
- params[name] = curVar;
1786
+ if (
1787
+ curVar === 'cdate' ||
1788
+ curVar === 'mdate' ||
1789
+ (this.nymph.tilmeld != null &&
1790
+ (curVar === 'user' ||
1791
+ curVar === 'group' ||
1792
+ curVar === 'acUser' ||
1793
+ curVar === 'acGroup' ||
1794
+ curVar === 'acOther' ||
1795
+ curVar === 'acRead' ||
1796
+ curVar === 'acWrite' ||
1797
+ curVar === 'acFull'))
1798
+ ) {
1799
+ curQuery +=
1800
+ (xor(typeIsNot, clauseNot) ? 'NOT ' : '') +
1801
+ '(' +
1802
+ ieTable +
1803
+ '.' +
1804
+ PostgreSQLDriver.escape(curVar) +
1805
+ ' IS NOT NULL)';
1806
+ } else {
1807
+ const name = `param${++count.i}`;
1808
+ curQuery +=
1809
+ (xor(typeIsNot, clauseNot) ? 'NOT ' : '') +
1810
+ 'EXISTS (SELECT "guid" FROM ' +
1811
+ PostgreSQLDriver.escape(this.prefix + 'data_' + etype) +
1812
+ ' WHERE "guid"=' +
1813
+ ieTable +
1814
+ '."guid" AND "name"=@' +
1815
+ name +
1816
+ ')';
1817
+ params[name] = curVar;
1818
+ }
1758
1819
  }
1759
1820
  break;
1760
1821
  case 'truthy':
@@ -1763,20 +1824,26 @@ export default class PostgreSQLDriver extends NymphDriver {
1763
1824
  if (curQuery) {
1764
1825
  curQuery += typeIsOr ? ' OR ' : ' AND ';
1765
1826
  }
1766
- if (curVar === 'cdate') {
1767
- curQuery +=
1768
- (xor(typeIsNot, clauseNot) ? 'NOT ' : '') +
1769
- '(' +
1770
- ieTable +
1771
- '."cdate" NOT NULL)';
1772
- break;
1773
- } else if (curVar === 'mdate') {
1827
+ if (
1828
+ curVar === 'cdate' ||
1829
+ curVar === 'mdate' ||
1830
+ (this.nymph.tilmeld != null &&
1831
+ (curVar === 'user' ||
1832
+ curVar === 'group' ||
1833
+ curVar === 'acUser' ||
1834
+ curVar === 'acGroup' ||
1835
+ curVar === 'acOther' ||
1836
+ curVar === 'acRead' ||
1837
+ curVar === 'acWrite' ||
1838
+ curVar === 'acFull'))
1839
+ ) {
1774
1840
  curQuery +=
1775
1841
  (xor(typeIsNot, clauseNot) ? 'NOT ' : '') +
1776
1842
  '(' +
1777
1843
  ieTable +
1778
- '."mdate" NOT NULL)';
1779
- break;
1844
+ '.' +
1845
+ PostgreSQLDriver.escape(curVar) +
1846
+ ' IS NOT NULL)';
1780
1847
  } else {
1781
1848
  const name = `param${++count.i}`;
1782
1849
  curQuery +=
@@ -1794,34 +1861,67 @@ export default class PostgreSQLDriver extends NymphDriver {
1794
1861
  break;
1795
1862
  case 'equal':
1796
1863
  case '!equal':
1797
- if (curValue[0] === 'cdate') {
1864
+ if (
1865
+ curValue[0] === 'cdate' ||
1866
+ curValue[0] === 'mdate' ||
1867
+ (this.nymph.tilmeld != null &&
1868
+ (curValue[0] === 'acUser' ||
1869
+ curValue[0] === 'acGroup' ||
1870
+ curValue[0] === 'acOther'))
1871
+ ) {
1798
1872
  if (curQuery) {
1799
1873
  curQuery += typeIsOr ? ' OR ' : ' AND ';
1800
1874
  }
1801
- const cdate = `param${++count.i}`;
1875
+ const value = `param${++count.i}`;
1802
1876
  curQuery +=
1803
1877
  (xor(typeIsNot, clauseNot) ? 'NOT ' : '') +
1804
1878
  ieTable +
1805
- '."cdate"=@' +
1806
- cdate;
1807
- params[cdate] = isNaN(Number(curValue[1]))
1879
+ '.' +
1880
+ PostgreSQLDriver.escape(curValue[0]) +
1881
+ '=@' +
1882
+ value;
1883
+ params[value] = isNaN(Number(curValue[1]))
1808
1884
  ? null
1809
1885
  : Number(curValue[1]);
1810
- break;
1811
- } else if (curValue[0] === 'mdate') {
1886
+ } else if (
1887
+ this.nymph.tilmeld != null &&
1888
+ (curValue[0] === 'user' || curValue[0] === 'group')
1889
+ ) {
1812
1890
  if (curQuery) {
1813
1891
  curQuery += typeIsOr ? ' OR ' : ' AND ';
1814
1892
  }
1815
- const mdate = `param${++count.i}`;
1893
+ const value = `param${++count.i}`;
1816
1894
  curQuery +=
1817
1895
  (xor(typeIsNot, clauseNot) ? 'NOT ' : '') +
1818
1896
  ieTable +
1819
- '."mdate"=@' +
1820
- mdate;
1821
- params[mdate] = isNaN(Number(curValue[1]))
1822
- ? null
1823
- : Number(curValue[1]);
1824
- break;
1897
+ '.' +
1898
+ PostgreSQLDriver.escape(curValue[0]) +
1899
+ '=decode(@' +
1900
+ value +
1901
+ ", 'hex')";
1902
+ params[value] = `${curValue[1]}`;
1903
+ } else if (
1904
+ this.nymph.tilmeld != null &&
1905
+ (curValue[0] === 'acRead' ||
1906
+ curValue[0] === 'acWrite' ||
1907
+ curValue[0] === 'acFull')
1908
+ ) {
1909
+ if (curQuery) {
1910
+ curQuery += typeIsOr ? ' OR ' : ' AND ';
1911
+ }
1912
+ const value = `param${++count.i}`;
1913
+ curQuery +=
1914
+ (xor(typeIsNot, clauseNot) ? 'NOT ' : '') +
1915
+ ieTable +
1916
+ '.' +
1917
+ PostgreSQLDriver.escape(curValue[0]) +
1918
+ '=' +
1919
+ !curValue[1]?.length
1920
+ ? '@' + value
1921
+ : "array(SELECT decode(n, 'hex') FROM unnest(@" +
1922
+ value +
1923
+ '::text[]) AS n)';
1924
+ params[value] = Array.isArray(curValue[1]) ? curValue[1] : '';
1825
1925
  } else if (typeof curValue[1] === 'number') {
1826
1926
  if (curQuery) {
1827
1927
  curQuery += typeIsOr ? ' OR ' : ' AND ';
@@ -1894,34 +1994,65 @@ export default class PostgreSQLDriver extends NymphDriver {
1894
1994
  break;
1895
1995
  case 'contain':
1896
1996
  case '!contain':
1897
- if (curValue[0] === 'cdate') {
1997
+ if (
1998
+ curValue[0] === 'cdate' ||
1999
+ curValue[0] === 'mdate' ||
2000
+ (this.nymph.tilmeld != null &&
2001
+ (curValue[0] === 'acUser' ||
2002
+ curValue[0] === 'acGroup' ||
2003
+ curValue[0] === 'acOther'))
2004
+ ) {
1898
2005
  if (curQuery) {
1899
2006
  curQuery += typeIsOr ? ' OR ' : ' AND ';
1900
2007
  }
1901
- const cdate = `param${++count.i}`;
2008
+ const value = `param${++count.i}`;
1902
2009
  curQuery +=
1903
2010
  (xor(typeIsNot, clauseNot) ? 'NOT ' : '') +
1904
2011
  ieTable +
1905
- '."cdate"=@' +
1906
- cdate;
1907
- params[cdate] = isNaN(Number(curValue[1]))
2012
+ '.' +
2013
+ PostgreSQLDriver.escape(curValue[0]) +
2014
+ '=@' +
2015
+ value;
2016
+ params[value] = isNaN(Number(curValue[1]))
1908
2017
  ? null
1909
2018
  : Number(curValue[1]);
1910
- break;
1911
- } else if (curValue[0] === 'mdate') {
2019
+ } else if (
2020
+ this.nymph.tilmeld != null &&
2021
+ (curValue[0] === 'user' || curValue[0] === 'group')
2022
+ ) {
1912
2023
  if (curQuery) {
1913
2024
  curQuery += typeIsOr ? ' OR ' : ' AND ';
1914
2025
  }
1915
- const mdate = `param${++count.i}`;
2026
+ const value = `param${++count.i}`;
1916
2027
  curQuery +=
1917
2028
  (xor(typeIsNot, clauseNot) ? 'NOT ' : '') +
1918
2029
  ieTable +
1919
- '."mdate"=@' +
1920
- mdate;
1921
- params[mdate] = isNaN(Number(curValue[1]))
1922
- ? null
1923
- : Number(curValue[1]);
1924
- break;
2030
+ '.' +
2031
+ PostgreSQLDriver.escape(curValue[0]) +
2032
+ '=decode(@' +
2033
+ value +
2034
+ ", 'hex')";
2035
+ params[value] = `${curValue[1]}`;
2036
+ } else if (
2037
+ this.nymph.tilmeld != null &&
2038
+ (curValue[0] === 'acRead' ||
2039
+ curValue[0] === 'acWrite' ||
2040
+ curValue[0] === 'acFull')
2041
+ ) {
2042
+ if (curQuery) {
2043
+ curQuery += typeIsOr ? ' OR ' : ' AND ';
2044
+ }
2045
+ const value = `param${++count.i}`;
2046
+ curQuery +=
2047
+ (xor(typeIsNot, clauseNot) ? 'NOT ' : '') +
2048
+ 'decode(@' +
2049
+ value +
2050
+ ", 'hex')=ANY(" +
2051
+ ieTable +
2052
+ '.' +
2053
+ PostgreSQLDriver.escape(curValue[0]) +
2054
+ ')';
2055
+ params[value] = `${curValue[1]}`;
1925
2056
  } else {
1926
2057
  if (curQuery) {
1927
2058
  curQuery += typeIsOr ? ' OR ' : ' AND ';
@@ -1959,13 +2090,24 @@ export default class PostgreSQLDriver extends NymphDriver {
1959
2090
  break;
1960
2091
  case 'search':
1961
2092
  case '!search':
1962
- if (curValue[0] === 'cdate' || curValue[0] === 'mdate') {
2093
+ if (
2094
+ curValue[0] === 'cdate' ||
2095
+ curValue[0] === 'mdate' ||
2096
+ (this.nymph.tilmeld != null &&
2097
+ (curValue[0] === 'user' ||
2098
+ curValue[0] === 'group' ||
2099
+ curValue[0] === 'acUser' ||
2100
+ curValue[0] === 'acGroup' ||
2101
+ curValue[0] === 'acOther' ||
2102
+ curValue[0] === 'acRead' ||
2103
+ curValue[0] === 'acWrite' ||
2104
+ curValue[0] === 'acFull'))
2105
+ ) {
1963
2106
  if (curQuery) {
1964
2107
  curQuery += typeIsOr ? ' OR ' : ' AND ';
1965
2108
  }
1966
2109
  curQuery +=
1967
2110
  (xor(typeIsNot, clauseNot) ? 'NOT ' : '') + '(FALSE)';
1968
- break;
1969
2111
  } else {
1970
2112
  if (curQuery) {
1971
2113
  curQuery += typeIsOr ? ' OR ' : ' AND ';
@@ -2106,34 +2248,33 @@ export default class PostgreSQLDriver extends NymphDriver {
2106
2248
  break;
2107
2249
  case 'match':
2108
2250
  case '!match':
2109
- if (curValue[0] === 'cdate') {
2110
- if (curQuery) {
2111
- curQuery += typeIsOr ? ' OR ' : ' AND ';
2112
- }
2113
- const cdate = `param${++count.i}`;
2114
- curQuery +=
2115
- (xor(typeIsNot, clauseNot) ? 'NOT ' : '') +
2116
- '(' +
2117
- ieTable +
2118
- '."cdate" ~ @' +
2119
- cdate +
2120
- ')';
2121
- params[cdate] = curValue[1];
2122
- break;
2123
- } else if (curValue[0] === 'mdate') {
2251
+ if (
2252
+ curValue[0] === 'cdate' ||
2253
+ curValue[0] === 'mdate' ||
2254
+ (this.nymph.tilmeld != null &&
2255
+ (curValue[0] === 'user' ||
2256
+ curValue[0] === 'group' ||
2257
+ curValue[0] === 'acUser' ||
2258
+ curValue[0] === 'acGroup' ||
2259
+ curValue[0] === 'acOther' ||
2260
+ curValue[0] === 'acRead' ||
2261
+ curValue[0] === 'acWrite' ||
2262
+ curValue[0] === 'acFull'))
2263
+ ) {
2124
2264
  if (curQuery) {
2125
2265
  curQuery += typeIsOr ? ' OR ' : ' AND ';
2126
2266
  }
2127
- const mdate = `param${++count.i}`;
2267
+ const value = `param${++count.i}`;
2128
2268
  curQuery +=
2129
2269
  (xor(typeIsNot, clauseNot) ? 'NOT ' : '') +
2130
2270
  '(' +
2131
2271
  ieTable +
2132
- '."mdate" ~ @' +
2133
- mdate +
2272
+ '.' +
2273
+ PostgreSQLDriver.escape(curValue[0]) +
2274
+ ' ~ @' +
2275
+ value +
2134
2276
  ')';
2135
- params[mdate] = curValue[1];
2136
- break;
2277
+ params[value] = curValue[1];
2137
2278
  } else {
2138
2279
  if (curQuery) {
2139
2280
  curQuery += typeIsOr ? ' OR ' : ' AND ';
@@ -2157,34 +2298,33 @@ export default class PostgreSQLDriver extends NymphDriver {
2157
2298
  break;
2158
2299
  case 'imatch':
2159
2300
  case '!imatch':
2160
- if (curValue[0] === 'cdate') {
2301
+ if (
2302
+ curValue[0] === 'cdate' ||
2303
+ curValue[0] === 'mdate' ||
2304
+ (this.nymph.tilmeld != null &&
2305
+ (curValue[0] === 'user' ||
2306
+ curValue[0] === 'group' ||
2307
+ curValue[0] === 'acUser' ||
2308
+ curValue[0] === 'acGroup' ||
2309
+ curValue[0] === 'acOther' ||
2310
+ curValue[0] === 'acRead' ||
2311
+ curValue[0] === 'acWrite' ||
2312
+ curValue[0] === 'acFull'))
2313
+ ) {
2161
2314
  if (curQuery) {
2162
2315
  curQuery += typeIsOr ? ' OR ' : ' AND ';
2163
2316
  }
2164
- const cdate = `param${++count.i}`;
2165
- curQuery +=
2166
- (xor(typeIsNot, clauseNot) ? 'NOT ' : '') +
2167
- '(' +
2168
- ieTable +
2169
- '."cdate" ~* @' +
2170
- cdate +
2171
- ')';
2172
- params[cdate] = curValue[1];
2173
- break;
2174
- } else if (curValue[0] === 'mdate') {
2175
- if (curQuery) {
2176
- curQuery += typeIsOr ? ' OR ' : ' AND ';
2177
- }
2178
- const mdate = `param${++count.i}`;
2317
+ const value = `param${++count.i}`;
2179
2318
  curQuery +=
2180
2319
  (xor(typeIsNot, clauseNot) ? 'NOT ' : '') +
2181
2320
  '(' +
2182
2321
  ieTable +
2183
- '."mdate" ~* @' +
2184
- mdate +
2322
+ '.' +
2323
+ PostgreSQLDriver.escape(curValue[0]) +
2324
+ ' ~* @' +
2325
+ value +
2185
2326
  ')';
2186
- params[mdate] = curValue[1];
2187
- break;
2327
+ params[value] = curValue[1];
2188
2328
  } else {
2189
2329
  if (curQuery) {
2190
2330
  curQuery += typeIsOr ? ' OR ' : ' AND ';
@@ -2208,34 +2348,33 @@ export default class PostgreSQLDriver extends NymphDriver {
2208
2348
  break;
2209
2349
  case 'like':
2210
2350
  case '!like':
2211
- if (curValue[0] === 'cdate') {
2351
+ if (
2352
+ curValue[0] === 'cdate' ||
2353
+ curValue[0] === 'mdate' ||
2354
+ (this.nymph.tilmeld != null &&
2355
+ (curValue[0] === 'user' ||
2356
+ curValue[0] === 'group' ||
2357
+ curValue[0] === 'acUser' ||
2358
+ curValue[0] === 'acGroup' ||
2359
+ curValue[0] === 'acOther' ||
2360
+ curValue[0] === 'acRead' ||
2361
+ curValue[0] === 'acWrite' ||
2362
+ curValue[0] === 'acFull'))
2363
+ ) {
2212
2364
  if (curQuery) {
2213
2365
  curQuery += typeIsOr ? ' OR ' : ' AND ';
2214
2366
  }
2215
- const cdate = `param${++count.i}`;
2216
- curQuery +=
2217
- (xor(typeIsNot, clauseNot) ? 'NOT ' : '') +
2218
- '(' +
2219
- ieTable +
2220
- '."cdate" LIKE @' +
2221
- cdate +
2222
- ')';
2223
- params[cdate] = curValue[1];
2224
- break;
2225
- } else if (curValue[0] === 'mdate') {
2226
- if (curQuery) {
2227
- curQuery += typeIsOr ? ' OR ' : ' AND ';
2228
- }
2229
- const mdate = `param${++count.i}`;
2367
+ const value = `param${++count.i}`;
2230
2368
  curQuery +=
2231
2369
  (xor(typeIsNot, clauseNot) ? 'NOT ' : '') +
2232
2370
  '(' +
2233
2371
  ieTable +
2234
- '."mdate" LIKE @' +
2235
- mdate +
2372
+ '.' +
2373
+ PostgreSQLDriver.escape(curValue[0]) +
2374
+ ' LIKE @' +
2375
+ value +
2236
2376
  ')';
2237
- params[mdate] = curValue[1];
2238
- break;
2377
+ params[value] = curValue[1];
2239
2378
  } else {
2240
2379
  if (curQuery) {
2241
2380
  curQuery += typeIsOr ? ' OR ' : ' AND ';
@@ -2259,34 +2398,33 @@ export default class PostgreSQLDriver extends NymphDriver {
2259
2398
  break;
2260
2399
  case 'ilike':
2261
2400
  case '!ilike':
2262
- if (curValue[0] === 'cdate') {
2401
+ if (
2402
+ curValue[0] === 'cdate' ||
2403
+ curValue[0] === 'mdate' ||
2404
+ (this.nymph.tilmeld != null &&
2405
+ (curValue[0] === 'user' ||
2406
+ curValue[0] === 'group' ||
2407
+ curValue[0] === 'acUser' ||
2408
+ curValue[0] === 'acGroup' ||
2409
+ curValue[0] === 'acOther' ||
2410
+ curValue[0] === 'acRead' ||
2411
+ curValue[0] === 'acWrite' ||
2412
+ curValue[0] === 'acFull'))
2413
+ ) {
2263
2414
  if (curQuery) {
2264
2415
  curQuery += typeIsOr ? ' OR ' : ' AND ';
2265
2416
  }
2266
- const cdate = `param${++count.i}`;
2267
- curQuery +=
2268
- (xor(typeIsNot, clauseNot) ? 'NOT ' : '') +
2269
- '(' +
2270
- ieTable +
2271
- '."cdate" ILIKE @' +
2272
- cdate +
2273
- ')';
2274
- params[cdate] = curValue[1];
2275
- break;
2276
- } else if (curValue[0] === 'mdate') {
2277
- if (curQuery) {
2278
- curQuery += typeIsOr ? ' OR ' : ' AND ';
2279
- }
2280
- const mdate = `param${++count.i}`;
2417
+ const value = `param${++count.i}`;
2281
2418
  curQuery +=
2282
2419
  (xor(typeIsNot, clauseNot) ? 'NOT ' : '') +
2283
2420
  '(' +
2284
2421
  ieTable +
2285
- '."mdate" ILIKE @' +
2286
- mdate +
2422
+ '.' +
2423
+ PostgreSQLDriver.escape(curValue[0]) +
2424
+ ' ILIKE @' +
2425
+ value +
2287
2426
  ')';
2288
- params[mdate] = curValue[1];
2289
- break;
2427
+ params[value] = curValue[1];
2290
2428
  } else {
2291
2429
  if (curQuery) {
2292
2430
  curQuery += typeIsOr ? ' OR ' : ' AND ';
@@ -2310,34 +2448,33 @@ export default class PostgreSQLDriver extends NymphDriver {
2310
2448
  break;
2311
2449
  case 'gt':
2312
2450
  case '!gt':
2313
- if (curValue[0] === 'cdate') {
2314
- if (curQuery) {
2315
- curQuery += typeIsOr ? ' OR ' : ' AND ';
2316
- }
2317
- const cdate = `param${++count.i}`;
2318
- curQuery +=
2319
- (xor(typeIsNot, clauseNot) ? 'NOT ' : '') +
2320
- ieTable +
2321
- '."cdate">@' +
2322
- cdate;
2323
- params[cdate] = isNaN(Number(curValue[1]))
2324
- ? null
2325
- : Number(curValue[1]);
2326
- break;
2327
- } else if (curValue[0] === 'mdate') {
2451
+ if (
2452
+ curValue[0] === 'cdate' ||
2453
+ curValue[0] === 'mdate' ||
2454
+ (this.nymph.tilmeld != null &&
2455
+ (curValue[0] === 'user' ||
2456
+ curValue[0] === 'group' ||
2457
+ curValue[0] === 'acUser' ||
2458
+ curValue[0] === 'acGroup' ||
2459
+ curValue[0] === 'acOther' ||
2460
+ curValue[0] === 'acRead' ||
2461
+ curValue[0] === 'acWrite' ||
2462
+ curValue[0] === 'acFull'))
2463
+ ) {
2328
2464
  if (curQuery) {
2329
2465
  curQuery += typeIsOr ? ' OR ' : ' AND ';
2330
2466
  }
2331
- const mdate = `param${++count.i}`;
2467
+ const value = `param${++count.i}`;
2332
2468
  curQuery +=
2333
2469
  (xor(typeIsNot, clauseNot) ? 'NOT ' : '') +
2334
2470
  ieTable +
2335
- '."mdate">@' +
2336
- mdate;
2337
- params[mdate] = isNaN(Number(curValue[1]))
2471
+ '.' +
2472
+ PostgreSQLDriver.escape(curValue[0]) +
2473
+ '>@' +
2474
+ value;
2475
+ params[value] = isNaN(Number(curValue[1]))
2338
2476
  ? null
2339
2477
  : Number(curValue[1]);
2340
- break;
2341
2478
  } else {
2342
2479
  if (curQuery) {
2343
2480
  curQuery += typeIsOr ? ' OR ' : ' AND ';
@@ -2363,34 +2500,33 @@ export default class PostgreSQLDriver extends NymphDriver {
2363
2500
  break;
2364
2501
  case 'gte':
2365
2502
  case '!gte':
2366
- if (curValue[0] === 'cdate') {
2367
- if (curQuery) {
2368
- curQuery += typeIsOr ? ' OR ' : ' AND ';
2369
- }
2370
- const cdate = `param${++count.i}`;
2371
- curQuery +=
2372
- (xor(typeIsNot, clauseNot) ? 'NOT ' : '') +
2373
- ieTable +
2374
- '."cdate">=@' +
2375
- cdate;
2376
- params[cdate] = isNaN(Number(curValue[1]))
2377
- ? null
2378
- : Number(curValue[1]);
2379
- break;
2380
- } else if (curValue[0] === 'mdate') {
2503
+ if (
2504
+ curValue[0] === 'cdate' ||
2505
+ curValue[0] === 'mdate' ||
2506
+ (this.nymph.tilmeld != null &&
2507
+ (curValue[0] === 'user' ||
2508
+ curValue[0] === 'group' ||
2509
+ curValue[0] === 'acUser' ||
2510
+ curValue[0] === 'acGroup' ||
2511
+ curValue[0] === 'acOther' ||
2512
+ curValue[0] === 'acRead' ||
2513
+ curValue[0] === 'acWrite' ||
2514
+ curValue[0] === 'acFull'))
2515
+ ) {
2381
2516
  if (curQuery) {
2382
2517
  curQuery += typeIsOr ? ' OR ' : ' AND ';
2383
2518
  }
2384
- const mdate = `param${++count.i}`;
2519
+ const value = `param${++count.i}`;
2385
2520
  curQuery +=
2386
2521
  (xor(typeIsNot, clauseNot) ? 'NOT ' : '') +
2387
2522
  ieTable +
2388
- '."mdate">=@' +
2389
- mdate;
2390
- params[mdate] = isNaN(Number(curValue[1]))
2523
+ '.' +
2524
+ PostgreSQLDriver.escape(curValue[0]) +
2525
+ '>=@' +
2526
+ value;
2527
+ params[value] = isNaN(Number(curValue[1]))
2391
2528
  ? null
2392
2529
  : Number(curValue[1]);
2393
- break;
2394
2530
  } else {
2395
2531
  if (curQuery) {
2396
2532
  curQuery += typeIsOr ? ' OR ' : ' AND ';
@@ -2416,34 +2552,33 @@ export default class PostgreSQLDriver extends NymphDriver {
2416
2552
  break;
2417
2553
  case 'lt':
2418
2554
  case '!lt':
2419
- if (curValue[0] === 'cdate') {
2555
+ if (
2556
+ curValue[0] === 'cdate' ||
2557
+ curValue[0] === 'mdate' ||
2558
+ (this.nymph.tilmeld != null &&
2559
+ (curValue[0] === 'user' ||
2560
+ curValue[0] === 'group' ||
2561
+ curValue[0] === 'acUser' ||
2562
+ curValue[0] === 'acGroup' ||
2563
+ curValue[0] === 'acOther' ||
2564
+ curValue[0] === 'acRead' ||
2565
+ curValue[0] === 'acWrite' ||
2566
+ curValue[0] === 'acFull'))
2567
+ ) {
2420
2568
  if (curQuery) {
2421
2569
  curQuery += typeIsOr ? ' OR ' : ' AND ';
2422
2570
  }
2423
- const cdate = `param${++count.i}`;
2424
- curQuery +=
2425
- (xor(typeIsNot, clauseNot) ? 'NOT ' : '') +
2426
- ieTable +
2427
- '."cdate"<@' +
2428
- cdate;
2429
- params[cdate] = isNaN(Number(curValue[1]))
2430
- ? null
2431
- : Number(curValue[1]);
2432
- break;
2433
- } else if (curValue[0] === 'mdate') {
2434
- if (curQuery) {
2435
- curQuery += typeIsOr ? ' OR ' : ' AND ';
2436
- }
2437
- const mdate = `param${++count.i}`;
2571
+ const value = `param${++count.i}`;
2438
2572
  curQuery +=
2439
2573
  (xor(typeIsNot, clauseNot) ? 'NOT ' : '') +
2440
2574
  ieTable +
2441
- '."mdate"<@' +
2442
- mdate;
2443
- params[mdate] = isNaN(Number(curValue[1]))
2575
+ '.' +
2576
+ PostgreSQLDriver.escape(curValue[0]) +
2577
+ '<@' +
2578
+ value;
2579
+ params[value] = isNaN(Number(curValue[1]))
2444
2580
  ? null
2445
2581
  : Number(curValue[1]);
2446
- break;
2447
2582
  } else {
2448
2583
  if (curQuery) {
2449
2584
  curQuery += typeIsOr ? ' OR ' : ' AND ';
@@ -2469,34 +2604,33 @@ export default class PostgreSQLDriver extends NymphDriver {
2469
2604
  break;
2470
2605
  case 'lte':
2471
2606
  case '!lte':
2472
- if (curValue[0] === 'cdate') {
2473
- if (curQuery) {
2474
- curQuery += typeIsOr ? ' OR ' : ' AND ';
2475
- }
2476
- const cdate = `param${++count.i}`;
2477
- curQuery +=
2478
- (xor(typeIsNot, clauseNot) ? 'NOT ' : '') +
2479
- ieTable +
2480
- '."cdate"<=@' +
2481
- cdate;
2482
- params[cdate] = isNaN(Number(curValue[1]))
2483
- ? null
2484
- : Number(curValue[1]);
2485
- break;
2486
- } else if (curValue[0] === 'mdate') {
2607
+ if (
2608
+ curValue[0] === 'cdate' ||
2609
+ curValue[0] === 'mdate' ||
2610
+ (this.nymph.tilmeld != null &&
2611
+ (curValue[0] === 'user' ||
2612
+ curValue[0] === 'group' ||
2613
+ curValue[0] === 'acUser' ||
2614
+ curValue[0] === 'acGroup' ||
2615
+ curValue[0] === 'acOther' ||
2616
+ curValue[0] === 'acRead' ||
2617
+ curValue[0] === 'acWrite' ||
2618
+ curValue[0] === 'acFull'))
2619
+ ) {
2487
2620
  if (curQuery) {
2488
2621
  curQuery += typeIsOr ? ' OR ' : ' AND ';
2489
2622
  }
2490
- const mdate = `param${++count.i}`;
2623
+ const value = `param${++count.i}`;
2491
2624
  curQuery +=
2492
2625
  (xor(typeIsNot, clauseNot) ? 'NOT ' : '') +
2493
2626
  ieTable +
2494
- '."mdate"<=@' +
2495
- mdate;
2496
- params[mdate] = isNaN(Number(curValue[1]))
2627
+ '.' +
2628
+ PostgreSQLDriver.escape(curValue[0]) +
2629
+ '<=@' +
2630
+ value;
2631
+ params[value] = isNaN(Number(curValue[1]))
2497
2632
  ? null
2498
2633
  : Number(curValue[1]);
2499
- break;
2500
2634
  } else {
2501
2635
  if (curQuery) {
2502
2636
  curQuery += typeIsOr ? ' OR ' : ' AND ';
@@ -2533,21 +2667,54 @@ export default class PostgreSQLDriver extends NymphDriver {
2533
2667
  if (curQuery) {
2534
2668
  curQuery += typeIsOr ? ' OR ' : ' AND ';
2535
2669
  }
2536
- const name = `param${++count.i}`;
2537
- const guid = `param${++count.i}`;
2538
- curQuery +=
2539
- (xor(typeIsNot, clauseNot) ? 'NOT ' : '') +
2540
- 'EXISTS (SELECT "guid" FROM ' +
2541
- PostgreSQLDriver.escape(this.prefix + 'references_' + etype) +
2542
- ' WHERE "guid"=' +
2543
- ieTable +
2544
- '."guid" AND "name"=@' +
2545
- name +
2546
- ' AND "reference"=decode(@' +
2547
- guid +
2548
- ", 'hex'))";
2549
- params[name] = curValue[0];
2550
- params[guid] = curQguid;
2670
+ if (
2671
+ this.nymph.tilmeld != null &&
2672
+ (curValue[0] === 'user' || curValue[0] === 'group')
2673
+ ) {
2674
+ const guid = `param${++count.i}`;
2675
+ curQuery +=
2676
+ (xor(typeIsNot, clauseNot) ? 'NOT ' : '') +
2677
+ ieTable +
2678
+ '.' +
2679
+ PostgreSQLDriver.escape(curValue[0]) +
2680
+ '=decode(@' +
2681
+ guid +
2682
+ ", 'hex')";
2683
+ params[guid] = curQguid;
2684
+ } else if (
2685
+ this.nymph.tilmeld != null &&
2686
+ (curValue[0] === 'acRead' ||
2687
+ curValue[0] === 'acWrite' ||
2688
+ curValue[0] === 'acFull')
2689
+ ) {
2690
+ const guid = `param${++count.i}`;
2691
+ curQuery +=
2692
+ (xor(typeIsNot, clauseNot) ? 'NOT ' : '') +
2693
+ 'decode(@' +
2694
+ guid +
2695
+ ", 'hex')=ANY(" +
2696
+ ieTable +
2697
+ '.' +
2698
+ PostgreSQLDriver.escape(curValue[0]) +
2699
+ ')';
2700
+ params[guid] = curQguid;
2701
+ } else {
2702
+ const name = `param${++count.i}`;
2703
+ const guid = `param${++count.i}`;
2704
+ curQuery +=
2705
+ (xor(typeIsNot, clauseNot) ? 'NOT ' : '') +
2706
+ 'EXISTS (SELECT "guid" FROM ' +
2707
+ PostgreSQLDriver.escape(this.prefix + 'references_' + etype) +
2708
+ ' WHERE "guid"=' +
2709
+ ieTable +
2710
+ '."guid" AND "name"=@' +
2711
+ name +
2712
+ ' AND "reference"=decode(@' +
2713
+ guid +
2714
+ ", 'hex'))";
2715
+ params[name] = curValue[0];
2716
+ params[guid] = curQguid;
2717
+ }
2551
2718
  break;
2552
2719
  case 'selector':
2553
2720
  case '!selector':
@@ -2579,44 +2746,118 @@ export default class PostgreSQLDriver extends NymphDriver {
2579
2746
  ];
2580
2747
  const QrefEntityClass = qrefOptions.class as EntityConstructor;
2581
2748
  etypes.push(QrefEntityClass.ETYPE);
2582
- const qrefQuery = this.makeEntityQuery(
2583
- {
2584
- ...qrefOptions,
2585
- sort: qrefOptions.sort ?? null,
2586
- return: 'guid',
2587
- class: QrefEntityClass,
2588
- },
2589
- qrefSelectors,
2590
- QrefEntityClass.ETYPE,
2591
- count,
2592
- params,
2593
- false,
2594
- makeTableSuffix(),
2595
- etypes,
2596
- 'r' + referenceTableSuffix + '."reference"',
2597
- );
2598
2749
  if (curQuery) {
2599
2750
  curQuery += typeIsOr ? ' OR ' : ' AND ';
2600
2751
  }
2601
- const qrefName = `param${++count.i}`;
2602
- curQuery +=
2603
- (xor(typeIsNot, clauseNot) ? 'NOT ' : '') +
2604
- 'EXISTS (SELECT "guid" FROM ' +
2605
- PostgreSQLDriver.escape(this.prefix + 'references_' + etype) +
2606
- ' r' +
2607
- referenceTableSuffix +
2608
- ' WHERE r' +
2609
- referenceTableSuffix +
2610
- '."guid"=' +
2611
- ieTable +
2612
- '."guid" AND r' +
2613
- referenceTableSuffix +
2614
- '."name"=@' +
2615
- qrefName +
2616
- ' AND EXISTS (' +
2617
- qrefQuery.query +
2618
- '))';
2619
- params[qrefName] = curValue[0];
2752
+ if (
2753
+ this.nymph.tilmeld != null &&
2754
+ (curValue[0] === 'user' || curValue[0] === 'group')
2755
+ ) {
2756
+ const qrefQuery = this.makeEntityQuery(
2757
+ {
2758
+ ...qrefOptions,
2759
+ sort: qrefOptions.sort ?? null,
2760
+ return: 'guid',
2761
+ class: QrefEntityClass,
2762
+ },
2763
+ qrefSelectors,
2764
+ QrefEntityClass.ETYPE,
2765
+ count,
2766
+ params,
2767
+ false,
2768
+ makeTableSuffix(),
2769
+ etypes,
2770
+ 'r' +
2771
+ referenceTableSuffix +
2772
+ '.' +
2773
+ PostgreSQLDriver.escape(curValue[0]),
2774
+ );
2775
+
2776
+ curQuery +=
2777
+ (xor(typeIsNot, clauseNot) ? 'NOT ' : '') +
2778
+ 'EXISTS (SELECT "guid" FROM ' +
2779
+ PostgreSQLDriver.escape(this.prefix + 'entities_' + etype) +
2780
+ ' r' +
2781
+ referenceTableSuffix +
2782
+ ' WHERE r' +
2783
+ referenceTableSuffix +
2784
+ '."guid"=' +
2785
+ ieTable +
2786
+ '."guid" AND EXISTS (' +
2787
+ qrefQuery.query +
2788
+ '))';
2789
+ } else if (
2790
+ this.nymph.tilmeld != null &&
2791
+ (curValue[0] === 'acRead' ||
2792
+ curValue[0] === 'acWrite' ||
2793
+ curValue[0] === 'acFull')
2794
+ ) {
2795
+ const qrefQuery = this.makeEntityQuery(
2796
+ {
2797
+ ...qrefOptions,
2798
+ sort: qrefOptions.sort ?? null,
2799
+ return: 'guid',
2800
+ class: QrefEntityClass,
2801
+ },
2802
+ qrefSelectors,
2803
+ QrefEntityClass.ETYPE,
2804
+ count,
2805
+ params,
2806
+ false,
2807
+ makeTableSuffix(),
2808
+ etypes,
2809
+ undefined,
2810
+ (guid) =>
2811
+ guid +
2812
+ '=ANY(' +
2813
+ ieTable +
2814
+ '.' +
2815
+ PostgreSQLDriver.escape(curValue[0]) +
2816
+ ')',
2817
+ );
2818
+
2819
+ curQuery +=
2820
+ (xor(typeIsNot, clauseNot) ? 'NOT ' : '') +
2821
+ 'EXISTS (' +
2822
+ qrefQuery.query +
2823
+ ')';
2824
+ } else {
2825
+ const qrefQuery = this.makeEntityQuery(
2826
+ {
2827
+ ...qrefOptions,
2828
+ sort: qrefOptions.sort ?? null,
2829
+ return: 'guid',
2830
+ class: QrefEntityClass,
2831
+ },
2832
+ qrefSelectors,
2833
+ QrefEntityClass.ETYPE,
2834
+ count,
2835
+ params,
2836
+ false,
2837
+ makeTableSuffix(),
2838
+ etypes,
2839
+ 'r' + referenceTableSuffix + '."reference"',
2840
+ );
2841
+ const qrefName = `param${++count.i}`;
2842
+ curQuery +=
2843
+ (xor(typeIsNot, clauseNot) ? 'NOT ' : '') +
2844
+ 'EXISTS (SELECT "guid" FROM ' +
2845
+ PostgreSQLDriver.escape(this.prefix + 'references_' + etype) +
2846
+ ' r' +
2847
+ referenceTableSuffix +
2848
+ ' WHERE r' +
2849
+ referenceTableSuffix +
2850
+ '."guid"=' +
2851
+ ieTable +
2852
+ '."guid" AND r' +
2853
+ referenceTableSuffix +
2854
+ '."name"=@' +
2855
+ qrefName +
2856
+ ' AND EXISTS (' +
2857
+ qrefQuery.query +
2858
+ '))';
2859
+ params[qrefName] = curValue[0];
2860
+ }
2620
2861
  break;
2621
2862
  }
2622
2863
  }
@@ -2681,9 +2922,11 @@ export default class PostgreSQLDriver extends NymphDriver {
2681
2922
  )}`;
2682
2923
  }
2683
2924
  const whereClause = queryParts.join(') AND (');
2684
- const guidClause = guidSelector
2685
- ? `${ieTable}."guid"=${guidSelector} AND `
2686
- : '';
2925
+ const guidClause = guidExplicitSelector
2926
+ ? `${guidExplicitSelector(`${ieTable}."guid"`)} AND `
2927
+ : guidSelector
2928
+ ? `${ieTable}."guid"=${guidSelector} AND `
2929
+ : '';
2687
2930
  if (options.return === 'count') {
2688
2931
  if (limit || offset) {
2689
2932
  query = `SELECT COUNT(${countTable}."guid") AS "count" FROM (
@@ -2718,6 +2961,14 @@ export default class PostgreSQLDriver extends NymphDriver {
2718
2961
  ${eTable}."tags",
2719
2962
  ${eTable}."cdate",
2720
2963
  ${eTable}."mdate",
2964
+ encode(${eTable}."user", 'hex') AS "user",
2965
+ encode(${eTable}."group", 'hex') AS "group",
2966
+ ${eTable}."acUser",
2967
+ ${eTable}."acGroup",
2968
+ ${eTable}."acOther",
2969
+ array(SELECT encode(n, 'hex') FROM unnest(${eTable}."acRead") AS n) as "acRead",
2970
+ array(SELECT encode(n, 'hex') FROM unnest(${eTable}."acWrite") AS n) as "acWrite",
2971
+ array(SELECT encode(n, 'hex') FROM unnest(${eTable}."acFull") AS n) as "acFull",
2721
2972
  ${dTable}."name",
2722
2973
  ${dTable}."value",
2723
2974
  ${dTable}."json",
@@ -2758,9 +3009,11 @@ export default class PostgreSQLDriver extends NymphDriver {
2758
3009
  isNaN(Number(options.offset)) ? 0 : Number(options.offset),
2759
3010
  )}`;
2760
3011
  }
2761
- const guidClause = guidSelector
2762
- ? ` WHERE ${ieTable}."guid"=${guidSelector}`
2763
- : '';
3012
+ const guidClause = guidExplicitSelector
3013
+ ? ` WHERE ${guidExplicitSelector(`${ieTable}."guid"`)}`
3014
+ : guidSelector
3015
+ ? ` WHERE ${ieTable}."guid"=${guidSelector}`
3016
+ : '';
2764
3017
  if (options.return === 'count') {
2765
3018
  if (limit || offset) {
2766
3019
  query = `SELECT COUNT(${countTable}."guid") AS "count" FROM (
@@ -2794,6 +3047,14 @@ export default class PostgreSQLDriver extends NymphDriver {
2794
3047
  ${eTable}."tags",
2795
3048
  ${eTable}."cdate",
2796
3049
  ${eTable}."mdate",
3050
+ encode(${eTable}."user", 'hex') AS "user",
3051
+ encode(${eTable}."group", 'hex') AS "group",
3052
+ ${eTable}."acUser",
3053
+ ${eTable}."acGroup",
3054
+ ${eTable}."acOther",
3055
+ array(SELECT encode(n, 'hex') FROM unnest(${eTable}."acRead") AS n) as "acRead",
3056
+ array(SELECT encode(n, 'hex') FROM unnest(${eTable}."acWrite") AS n) as "acWrite",
3057
+ array(SELECT encode(n, 'hex') FROM unnest(${eTable}."acFull") AS n) as "acFull",
2797
3058
  ${dTable}."name",
2798
3059
  ${dTable}."value",
2799
3060
  ${dTable}."json",
@@ -2822,6 +3083,14 @@ export default class PostgreSQLDriver extends NymphDriver {
2822
3083
  ${eTable}."tags",
2823
3084
  ${eTable}."cdate",
2824
3085
  ${eTable}."mdate",
3086
+ encode(${eTable}."user", 'hex') AS "user",
3087
+ encode(${eTable}."group", 'hex') AS "group",
3088
+ ${eTable}."acUser",
3089
+ ${eTable}."acGroup",
3090
+ ${eTable}."acOther",
3091
+ array(SELECT encode(n, 'hex') FROM unnest(${eTable}."acRead") AS n) as "acRead",
3092
+ array(SELECT encode(n, 'hex') FROM unnest(${eTable}."acWrite") AS n) as "acWrite",
3093
+ array(SELECT encode(n, 'hex') FROM unnest(${eTable}."acFull") AS n) as "acFull",
2825
3094
  ${dTable}."name",
2826
3095
  ${dTable}."value",
2827
3096
  ${dTable}."json",
@@ -2834,7 +3103,7 @@ export default class PostgreSQLDriver extends NymphDriver {
2834
3103
  `${this.prefix}data_${etype}`,
2835
3104
  )} ${dTable} ON ${eTable}."guid"=${dTable}."guid"
2836
3105
  ${sortJoin}
2837
- ${guidSelector ? `WHERE ${eTable}."guid"=${guidSelector}` : ''}
3106
+ ${guidExplicitSelector ? `WHERE ${guidExplicitSelector(`${eTable}."guid"`)}` : guidSelector ? `WHERE ${eTable}."guid"=${guidSelector}` : ''}
2838
3107
  ${sortBy ? sortBy + ', ' : 'ORDER BY '}${eTable}."guid"`;
2839
3108
  }
2840
3109
  }
@@ -2911,6 +3180,14 @@ export default class PostgreSQLDriver extends NymphDriver {
2911
3180
  tags: row.tags.filter((tag: string) => tag),
2912
3181
  cdate: isNaN(Number(row.cdate)) ? Date.now() : Number(row.cdate),
2913
3182
  mdate: isNaN(Number(row.mdate)) ? Date.now() : Number(row.mdate),
3183
+ user: row.user,
3184
+ group: row.group,
3185
+ acUser: row.acUser,
3186
+ acGroup: row.acGroup,
3187
+ acOther: row.acOther,
3188
+ acRead: row.acRead?.filter((guid: string) => guid) ?? [],
3189
+ acWrite: row.acWrite?.filter((guid: string) => guid) ?? [],
3190
+ acFull: row.acFull?.filter((guid: string) => guid) ?? [],
2914
3191
  }),
2915
3192
  (row) => ({
2916
3193
  name: row.name,
@@ -3885,6 +4162,72 @@ export default class PostgreSQLDriver extends NymphDriver {
3885
4162
  return nymph;
3886
4163
  }
3887
4164
 
4165
+ private async removeTilmeldOldRows(
4166
+ etype: string,
4167
+ connection: PostgreSQLDriverConnection,
4168
+ ) {
4169
+ await this.internalTransaction('nymph-remove-tilmeld-rows');
4170
+ try {
4171
+ for (let name of [
4172
+ 'user',
4173
+ 'group',
4174
+ 'acUser',
4175
+ 'acGroup',
4176
+ 'acOther',
4177
+ 'acRead',
4178
+ 'acWrite',
4179
+ 'acFull',
4180
+ ]) {
4181
+ await this.queryRun(
4182
+ `DELETE FROM ${PostgreSQLDriver.escape(
4183
+ `${this.prefix}data_${etype}`,
4184
+ )} WHERE "name"=@name;`,
4185
+ {
4186
+ etypes: [etype],
4187
+ params: {
4188
+ name,
4189
+ },
4190
+ connection,
4191
+ },
4192
+ );
4193
+ await this.queryRun(
4194
+ `DELETE FROM ${PostgreSQLDriver.escape(
4195
+ `${this.prefix}references_${etype}`,
4196
+ )} WHERE "name"=@name;`,
4197
+ {
4198
+ etypes: [etype],
4199
+ params: {
4200
+ name,
4201
+ },
4202
+ connection,
4203
+ },
4204
+ );
4205
+ await this.queryRun(
4206
+ `DELETE FROM ${PostgreSQLDriver.escape(
4207
+ `${this.prefix}tokens_${etype}`,
4208
+ )} WHERE "name"=@name;`,
4209
+ {
4210
+ etypes: [etype],
4211
+ params: {
4212
+ name,
4213
+ },
4214
+ connection,
4215
+ },
4216
+ );
4217
+ }
4218
+ } catch (e: any) {
4219
+ this.nymph.config.debugError(
4220
+ 'postgresql',
4221
+ `Remove tilmeld rows error: "${e}"`,
4222
+ );
4223
+ await this.rollback('nymph-remove-tilmeld-rows');
4224
+ throw e;
4225
+ }
4226
+
4227
+ await this.commit('nymph-remove-tilmeld-rows');
4228
+ return true;
4229
+ }
4230
+
3888
4231
  public async needsMigration(): Promise<
3889
4232
  'json' | 'tokens' | 'tilmeldColumns' | false
3890
4233
  > {
@@ -3949,7 +4292,9 @@ export default class PostgreSQLDriver extends NymphDriver {
3949
4292
  return false;
3950
4293
  }
3951
4294
 
3952
- public async liveMigration(migrationType: 'tokenTables' | 'tilmeldColumns') {
4295
+ public async liveMigration(
4296
+ migrationType: 'tokenTables' | 'tilmeldColumns' | 'tilmeldRemoveOldRows',
4297
+ ) {
3953
4298
  if (migrationType === 'tokenTables') {
3954
4299
  const etypes = await this.getEtypes();
3955
4300
 
@@ -3966,6 +4311,14 @@ export default class PostgreSQLDriver extends NymphDriver {
3966
4311
  await this.addTilmeldColumnsAndIndexes(etype, connection);
3967
4312
  }
3968
4313
  connection.done();
4314
+ } else if (migrationType === 'tilmeldRemoveOldRows') {
4315
+ const etypes = await this.getEtypes();
4316
+
4317
+ const connection = await this.getConnection(true);
4318
+ for (let etype of etypes) {
4319
+ await this.removeTilmeldOldRows(etype, connection);
4320
+ }
4321
+ connection.done();
3969
4322
  }
3970
4323
  }
3971
4324
  }