pogi 2.10.2 → 3.0.0-beta2

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.
Files changed (83) hide show
  1. package/.vscode/launch.json +47 -15
  2. package/CHANGELOG.md +11 -0
  3. package/docs/API/PgDb.md +25 -0
  4. package/docs/notification.md +19 -0
  5. package/jest.config.js +23 -0
  6. package/lib/bin/generateInterface.js +3 -3
  7. package/lib/bin/generateInterface.js.map +1 -1
  8. package/lib/connectionOptions.d.ts +10 -0
  9. package/lib/index.d.ts +1 -1
  10. package/lib/pgConverters.d.ts +9 -8
  11. package/lib/pgConverters.js +46 -32
  12. package/lib/pgConverters.js.map +1 -1
  13. package/lib/pgConverters.test.d.ts +1 -0
  14. package/lib/pgConverters.test.js +13 -0
  15. package/lib/pgConverters.test.js.map +1 -0
  16. package/lib/pgDb.d.ts +27 -27
  17. package/lib/pgDb.js +293 -100
  18. package/lib/pgDb.js.map +1 -1
  19. package/lib/pgDb.test.d.ts +1 -0
  20. package/lib/pgDb.test.js +1126 -0
  21. package/lib/pgDb.test.js.map +1 -0
  22. package/lib/pgDbInterface.d.ts +53 -0
  23. package/lib/pgDbInterface.js +11 -0
  24. package/lib/pgDbInterface.js.map +1 -0
  25. package/lib/pgDbOperators.d.ts +3 -3
  26. package/lib/pgDbOperators.js +4 -7
  27. package/lib/pgDbOperators.js.map +1 -1
  28. package/lib/pgDbOperators.test.d.ts +1 -0
  29. package/lib/pgDbOperators.test.js +313 -0
  30. package/lib/pgDbOperators.test.js.map +1 -0
  31. package/lib/pgSchema.d.ts +10 -9
  32. package/lib/pgSchema.js.map +1 -1
  33. package/lib/pgSchemaInterface.d.ts +12 -0
  34. package/lib/pgSchemaInterface.js +3 -0
  35. package/lib/pgSchemaInterface.js.map +1 -0
  36. package/lib/pgTable.d.ts +15 -40
  37. package/lib/pgTable.js +54 -54
  38. package/lib/pgTable.js.map +1 -1
  39. package/lib/pgTableInterface.d.ts +102 -0
  40. package/lib/pgTableInterface.js +4 -0
  41. package/lib/pgTableInterface.js.map +1 -0
  42. package/lib/pgUtils.d.ts +16 -6
  43. package/lib/pgUtils.js +162 -31
  44. package/lib/pgUtils.js.map +1 -1
  45. package/lib/queryAble.d.ts +20 -53
  46. package/lib/queryAble.js +149 -80
  47. package/lib/queryAble.js.map +1 -1
  48. package/lib/queryAbleInterface.d.ts +55 -0
  49. package/lib/queryAbleInterface.js +7 -0
  50. package/lib/queryAbleInterface.js.map +1 -0
  51. package/lib/queryWhere.d.ts +2 -2
  52. package/lib/queryWhere.js +19 -23
  53. package/lib/queryWhere.js.map +1 -1
  54. package/mkdocs.yml +1 -0
  55. package/package.json +21 -11
  56. package/src/bin/generateInterface.ts +2 -2
  57. package/src/connectionOptions.ts +48 -13
  58. package/src/index.d.ts +7 -0
  59. package/src/index.ts +1 -1
  60. package/src/pgConverters.test.ts +10 -0
  61. package/src/pgConverters.ts +34 -22
  62. package/src/pgDb.test.ts +1324 -0
  63. package/src/pgDb.ts +318 -122
  64. package/src/pgDbInterface.ts +57 -0
  65. package/src/pgDbOperators.test.ts +478 -0
  66. package/src/pgDbOperators.ts +45 -22
  67. package/src/pgSchema.ts +10 -9
  68. package/src/pgSchemaInterface.ts +12 -0
  69. package/src/pgTable.ts +66 -98
  70. package/src/pgTableInterface.ts +131 -0
  71. package/src/pgUtils.ts +166 -42
  72. package/src/queryAble.ts +167 -125
  73. package/src/queryAbleInterface.ts +104 -0
  74. package/src/queryWhere.ts +42 -43
  75. package/{spec/resources → src/test}/init.sql +23 -0
  76. package/src/test/pgServiceRestartTest.ts +1500 -0
  77. package/{spec/resources → src/test}/throw_exception.sql +0 -0
  78. package/{spec/resources → src/test}/tricky.sql +0 -0
  79. package/{src/tsconfig.json → tsconfig.json} +12 -11
  80. package/spec/run.js +0 -5
  81. package/spec/support/jasmine.json +0 -9
  82. package/src/test/pgDbOperatorSpec.ts +0 -492
  83. package/src/test/pgDbSpec.ts +0 -994
File without changes
File without changes
@@ -9,24 +9,25 @@
9
9
  "forceConsistentCasingInFileNames": true,
10
10
  "suppressImplicitAnyIndexErrors": true,
11
11
  "importHelpers": true,
12
- "rootDir": "./",
13
- "outDir": "../lib",
12
+ "strict": true,
13
+ "rootDir": "./src",
14
+ "outDir": "./lib",
14
15
  "types": [
15
- "node"
16
+ "node",
17
+ "jest"
16
18
  ],
17
19
  "lib": [
18
20
  "es2015",
19
21
  "es2016",
20
22
  "es2017"
21
23
  ],
22
- "typeRoots": [
23
- "../node_modules/@types"
24
- ]
25
24
  },
26
25
  "files": [
27
- "index.ts",
28
- "test/pgDbOperatorSpec.ts",
29
- "test/pgDbSpec.ts",
30
- "bin/generateInterface.ts"
26
+ "src/index.ts",
27
+ "src/bin/generateInterface.ts"
28
+ ],
29
+ "include": [
30
+ "src/*.test.ts",
31
+ "src/index.d.ts"
31
32
  ]
32
- }
33
+ }
package/spec/run.js DELETED
@@ -1,5 +0,0 @@
1
- var Jasmine = require('jasmine');
2
-
3
- var jasmine = new Jasmine();
4
- jasmine.loadConfigFile('spec/support/jasmine.json');
5
- jasmine.execute();
@@ -1,9 +0,0 @@
1
- {
2
- "spec_dir": "lib/test",
3
- "spec_files": [
4
- "**/pgDbOperatorSpec.js",
5
- "**/pgDbSpec.js"
6
- ],
7
- "stopSpecOnExpectationFailure": false,
8
- "random": false
9
- }
@@ -1,492 +0,0 @@
1
- /// <reference types="jasmine"/>
2
- import {PgDb} from "../pgDb";
3
- import {PgTable} from "../pgTable";
4
-
5
- const util = require('util');
6
-
7
- function w(func) {
8
- return function (done) {
9
- return (async () => {
10
- try {
11
- await func();
12
- } catch (e) {
13
- console.log('------------------------------');
14
- console.error(e.message, e.stack);
15
- console.log('------------------------------');
16
- expect('Exception: ' + e.message).toBeFalsy();
17
- }
18
- return done();
19
- })();
20
- }
21
- }
22
-
23
- describe("pgdb", () => {
24
- let pgdb: PgDb;
25
- let schema = 'pgdb_test';
26
- let tableUsers: PgTable<any>;
27
- let viewUsers: PgTable<any>;
28
-
29
- beforeAll(w(async () => {
30
- jasmine.DEFAULT_TIMEOUT_INTERVAL = 800000;
31
-
32
- /**
33
- * Using environment variables, e.g.
34
- * PGUSER (defaults USER env var, so optional)
35
- * PGDATABASE (defaults USER env var, so optional)
36
- * PGPASSWORD
37
- * PGPORT
38
- * etc...
39
- */
40
- try {
41
- pgdb = await PgDb.connect({connectionString: "postgres://"});
42
- } catch (e) {
43
- console.error("connection failed! Are you specified PGUSER/PGDATABASE/PGPASSWORD correctly?");
44
- console.error(e);
45
- process.exit(1);
46
- }
47
- //await pgdb.run('DROP SCHEMA IF EXISTS "' + schema + '" CASCADE ');
48
- await pgdb.run('CREATE SCHEMA IF NOT EXISTS "' + schema + '"');
49
- await pgdb.execute('spec/resources/init.sql', (cmd) => cmd.replace(/__SCHEMA__/g, '"' + schema + '"'));
50
- await pgdb.reload();
51
-
52
- pgdb.setLogger(console);
53
- tableUsers = pgdb.schemas[schema]['users'];
54
- viewUsers = pgdb.schemas[schema]['users_view'];
55
-
56
- return Promise.resolve();
57
- }));
58
-
59
- beforeEach(w(async () => {
60
- await tableUsers.run('DELETE FROM ' + tableUsers);
61
- }));
62
-
63
- it("Testing Array operators", w(async () => {
64
- await tableUsers.insert({name: 'S', favourites: ['sport']});
65
- await tableUsers.insert({name: 'SF', favourites: ['sport', 'food']});
66
- await tableUsers.insert({name: 'TF', favourites: ['tech', 'food']});
67
-
68
- let res;
69
-
70
- res = await tableUsers.find({'favourites': 'sport'}, {fields: ['name']}); //=> 'sport' = ANY("favourites")
71
- expect(res.map(r => r.name)).toEqual(['S', 'SF']);
72
-
73
- res = await tableUsers.find({'favourites': ['sport', 'food']}, {fields: ['name']}); //=> favourites = '{sport,food}'
74
- expect(res.map(r => r.name)).toEqual(['SF']);
75
-
76
- res = await tableUsers.find({'favourites @>': ['sport']}); //contains
77
- expect(res.map(r => r.name)).toEqual(['S', 'SF']);
78
-
79
- res = await tableUsers.find({'favourites <@': ['sport', 'food', 'tech']});//contained by
80
- expect(res.map(r => r.name)).toEqual(['S', 'SF', 'TF']);
81
-
82
- res = await tableUsers.find({'favourites &&': ['sport', 'music']});//overlap
83
- expect(res.map(r => r.name)).toEqual(['S', 'SF']);
84
-
85
- res = await tableUsers.find({'favourites !=': ['sport']});//
86
- expect(res.map(r => r.name)).toEqual(['SF', 'TF']);
87
- }));
88
-
89
- it("Testing Array operators on view", w(async () => {
90
- await viewUsers.insert({name: 'S', favourites: ['sport']});
91
- await viewUsers.insert({name: 'SF', favourites: ['sport', 'food']});
92
- await viewUsers.insert({name: 'TF', favourites: ['tech', 'food']});
93
-
94
- let res;
95
-
96
- res = await viewUsers.find({'favourites': 'sport'}, {fields: ['name']}); //=> 'sport' = ANY("favourites")
97
- expect(res.map(r => r.name)).toEqual(['S', 'SF']);
98
-
99
- res = await viewUsers.find({'favourites': ['sport', 'food']}, {fields: ['name']}); //=> favourites = '{sport,food}'
100
- expect(res.map(r => r.name)).toEqual(['SF']);
101
-
102
- res = await viewUsers.find({'favourites @>': ['sport']}); //contains
103
- expect(res.map(r => r.name)).toEqual(['S', 'SF']);
104
-
105
- res = await viewUsers.find({'favourites <@': ['sport', 'food', 'tech']});//contained by
106
- expect(res.map(r => r.name)).toEqual(['S', 'SF', 'TF']);
107
-
108
- res = await viewUsers.find({'favourites &&': ['sport', 'music']});//overlap
109
- expect(res.map(r => r.name)).toEqual(['S', 'SF']);
110
-
111
- res = await viewUsers.find({'favourites !=': ['sport']});//
112
- expect(res.map(r => r.name)).toEqual(['SF', 'TF']);
113
- }));
114
-
115
- it("Searching in elements in jsonList", w(async () => {
116
- await tableUsers.insert({name: 'Medium and high risk', jsonList: [{risk: 'H'}, {risk: 'M'}]});
117
-
118
- let query1 = {
119
- or: [{'"jsonList" @>': [{"risk": "H"}]}, {'"jsonList" @>': [{"risk": "L"}]}]
120
- };
121
- let query2 = {
122
- or: [{'jsonList @>': [{"risk": "H"}]}, {'jsonList @>': [{"risk": "L"}]}]
123
- };
124
- let query3 = {
125
- or: [{'jsonList @>': '[{"risk": "H"}]'}, {'jsonList @>': '[{"risk": "L"}]'}]
126
- };
127
-
128
- let res;
129
- res = await tableUsers.find(query1, {fields: ['name']});
130
- expect(res.map(r => r.name)).toEqual(['Medium and high risk']);
131
-
132
- res = await tableUsers.find(query2, {fields: ['name']});
133
- expect(res.map(r => r.name)).toEqual(['Medium and high risk']);
134
-
135
- res = await tableUsers.find(query3, {fields: ['name']});
136
- expect(res.map(r => r.name)).toEqual(['Medium and high risk']);
137
- }));
138
-
139
- it("Free text search", w(async () => {
140
- await tableUsers.insert({name: 'Medium and high risk', jsonList: [{name: "The return of the Jedi"}]});
141
-
142
- let res;
143
- for (let searchCol of ['"name"||"jsonList" @@', 'tsv @@']) {
144
- res = await tableUsers.find({[searchCol]: 'risk & return'}, {fields: ['name']});
145
- expect(res.map(r => r.name)).toEqual(['Medium and high risk']);
146
-
147
- res = await tableUsers.find({[searchCol]: 'risk & future'}, {fields: ['name']});
148
- expect(res.length).toEqual(0);
149
-
150
- res = await tableUsers.find({
151
- [searchCol]: {
152
- lang: 'english',
153
- query: 'risk & return'
154
- }
155
- }, {fields: ['name']});
156
- expect(res.map(r => r.name)).toEqual(['Medium and high risk']);
157
- }
158
- }));
159
-
160
- it("Testing Jsonb list selector operators", w(async () => {
161
- //@formatter:off
162
- await tableUsers.insert({ name: 'Somebody', jsonList: ['sport', 'season'] });
163
- await tableUsers.insert({ name: 'Anybody', jsonList: ['art', 'age'] });
164
- await tableUsers.insert({ name: 'Nobody', jsonList: ['neverending', 'nearby'] });
165
- await tableUsers.insert({ name: 'Noone', jsonList: null, });
166
- await tableUsers.insert({ name: 'Anonymous', jsonList: [] });
167
- await tableUsers.insert({ name: 'Obi1', jsonObject: {a:{b:3}}});
168
- await tableUsers.insert({ name: 'Obi2', jsonObject: {a:{b:[3,4,5,6]}, d:'c', g:'e' }});
169
- //@formatter:on
170
-
171
- let res;
172
-
173
- res = await tableUsers.find({'"jsonObject" ?|': ['d', 'f']}, {fields: ['name']});
174
- expect(res.map(r => r.name)).toEqual(['Obi2']);
175
-
176
- res = await tableUsers.find({'jsonList @>': ['sport']}, {fields: ['name']}); //=>
177
- expect(res.map(r => r.name)).toEqual(['Somebody']);
178
-
179
- res = await tableUsers.find({'jsonList <@': ['sport', 'tech', 'season']}, {fields: ['name']}); //=>
180
- expect(res.map(r => r.name)).toEqual(['Somebody', 'Anonymous']);
181
-
182
- res = await tableUsers.find({'jsonList ?': 0}, {fields: ['name']}); //=> doesnt work
183
- expect(res.map(r => r.name)).toEqual([]);
184
-
185
- res = await tableUsers.find({'jsonList ?': '0'}, {fields: ['name']}); //=> doesnt work
186
- expect(res.map(r => r.name)).toEqual([]);
187
-
188
- res = await tableUsers.find({'jsonObject -> a': {b: 3}}, {fields: ['name']});
189
- expect(res.map(r => r.name)).toEqual(['Obi1']);
190
-
191
- res = await tableUsers.find({"jsonObject -> 'a'": {b: 3}}, {fields: ['name']});
192
- expect(res.map(r => r.name)).toEqual(['Obi1']);
193
-
194
- res = await tableUsers.find({'jsonList ->> 0': 'art'}, {fields: ['name']});
195
- expect(res.map(r => r.name)).toEqual(['Anybody']);
196
-
197
- res = await tableUsers.find({'jsonObject ->> a': '{"b": 3}'}, {fields: ['name']}); //->> return as a text
198
- expect(res.map(r => r.name)).toEqual(['Obi1']);
199
-
200
- res = await tableUsers.find({"jsonObject ->> 'a'": '{"b": 3}'}, {fields: ['name']}); //->> return as a text
201
- expect(res.map(r => r.name)).toEqual(['Obi1']);
202
-
203
- res = await tableUsers.find({"jsonList ->> '0'": 'art'}, {fields: ['name']}); //=> doesnt work
204
- expect(res.map(r => r.name)).toEqual([]);
205
-
206
- res = await tableUsers.find({"jsonObject #> {a}": {b: 3}}, {fields: ['name']});
207
- expect(res.map(r => r.name)).toEqual(['Obi1']);
208
-
209
- res = await tableUsers.find({"jsonObject #>> {a}": '{"b": 3}'}, {fields: ['name']});
210
- expect(res.map(r => r.name)).toEqual(['Obi1']);
211
-
212
- res = await tableUsers.find({"jsonObject #>> {a,b}": 3}, {fields: ['name']});
213
- expect(res.map(r => r.name)).toEqual(['Obi1']);
214
-
215
- res = await tableUsers.find({"jsonObject #>> {a,b,1}": 4}, {fields: ['name']});
216
- expect(res.map(r => r.name)).toEqual(['Obi2']);
217
-
218
- res = await tableUsers.find({"jsonObject #>> {a,b,1}": '4'}, {fields: ['name']});
219
- expect(res.map(r => r.name)).toEqual(['Obi2']);
220
- }));
221
-
222
- it("Testing Jsonb list update", w(async () => {
223
- await tableUsers.insert({name: 'Somebody', jsonList: ['sport', 'season']});
224
- await tableUsers.update({name: 'Somebody'}, {jsonList: [{name: 'sport'}, {name: 'season'}]});
225
-
226
- let res = await tableUsers.findAll();
227
- expect(res.map(r => r.jsonList.map(e => e.name))[0]).toEqual(['sport', 'season']);
228
- }));
229
-
230
- it("Testing Jsonb list operators", w(async () => {
231
- //@formatter:off
232
- await tableUsers.insert({ name: 'Somebody', jsonObject: {realName: 'somebody', webpage: 's.com'} });
233
- await tableUsers.insert({ name: 'Anybody', jsonObject: {realName: 'anybody', webpage: 'a.com'} });
234
- await tableUsers.insert({ name: 'Nobody', jsonObject: {realName: 'nobody', email: 'nobody@nowhere.com'}});
235
- await tableUsers.insert({ name: 'Noone', jsonObject: null});
236
- await tableUsers.insert({ name: 'Anonymous', jsonObject: {}});
237
- //@formatter:on
238
- let res;
239
-
240
- res = await tableUsers.find({'jsonObject ?': 'email'}, {fields: ['name']}); //=> has the key ..
241
- expect(res.map(r => r.name)).toEqual(['Nobody']);
242
-
243
- res = await tableUsers.find({'jsonObject ?&': ['email', 'realName']}, {fields: ['name']}); //=> has all key ..
244
- expect(res.map(r => r.name)).toEqual(['Nobody']);
245
-
246
- res = await tableUsers.find({'jsonObject ?|': ['email', 'webpage']}, {fields: ['name']}); //=> has any of the key..
247
- expect(res.map(r => r.name)).toEqual(['Somebody', 'Anybody', 'Nobody']);
248
-
249
- res = await tableUsers.find({'jsonObject @>': {realName: 'somebody'}}, {fields: ['name']}); //=> contains substructure
250
- expect(res.map(r => r.name)).toEqual(['Somebody']);
251
-
252
- res = await tableUsers.find({'jsonObject ->> realName': 'somebody'}, {fields: ['name']}); //=> has the key + equals to
253
- expect(res.map(r => r.name)).toEqual(['Somebody']);
254
-
255
- res = await tableUsers.find({'jsonObject ->> \'realName\'': 'somebody'}, {fields: ['name']}); //=> has the key + equals to
256
- expect(res.map(r => r.name)).toEqual(['Somebody']);
257
-
258
- res = await tableUsers.find({'"jsonObject" ->> \'realName\'': 'somebody'}, {fields: ['name']}); //=> has the key + equals to
259
- expect(res.map(r => r.name)).toEqual(['Somebody']);
260
-
261
- res = await tableUsers.find({'jsonObject ->> realName': ['somebody', 'anybody']}, {fields: ['name']}); //=> has the key + in array
262
- expect(res.map(r => r.name)).toEqual(['Somebody', 'Anybody']);
263
-
264
- res = await tableUsers.find({'jsonObject ->> realName like': '%body'}, {fields: ['name']}); //=> has the key + like
265
- expect(res.map(r => r.name)).toEqual(['Somebody', 'Anybody', 'Nobody']);
266
-
267
- res = await tableUsers.find({'jsonObject ->> realName ~~': '%body'}, {fields: ['name']}); //=> has the key + like
268
- expect(res.map(r => r.name)).toEqual(['Somebody', 'Anybody', 'Nobody']);
269
-
270
- }));
271
-
272
- it("Test deep jsonb @>", w(async () => {
273
- //@formatter:off
274
- await tableUsers.insert({ name: 'Somebody', jsonObject: {service: {indexing: {by: [1, 2, 3]}, database: true}, paid: true}});
275
- await tableUsers.insert({ name: 'Anybody', jsonList: [{realName: 'anyone'}, {realName: 'anybody'}]});
276
- //@formatter:on
277
-
278
- let res;
279
- res = await tableUsers.find({'jsonObject @>': {service: {indexing: {by: [1]}}, paid: true}});
280
- expect(res.map(r => r.name)).toEqual(['Somebody']);
281
-
282
- res = await tableUsers.find({'jsonList @>': [{realName: 'anybody'}]});
283
- expect(res.map(r => r.name)).toEqual(['Anybody']);
284
- }))
285
-
286
-
287
- it("Testing is (not) null", w(async () => {
288
- await tableUsers.insert({name: 'Noone', jsonObject: null});
289
- await tableUsers.insert({name: 'Anonymous', jsonObject: {}});
290
-
291
- let count;
292
-
293
- count = await tableUsers.count({'jsonObject !': null});
294
- expect(count).toEqual(1);
295
-
296
- count = await tableUsers.count({'jsonObject': null});
297
- expect(count).toEqual(1);
298
-
299
- count = await tableUsers.count({});
300
- expect(count).toEqual(2);
301
- }));
302
-
303
- it("Test regexp ~,~*,!~,!~*", w(async () => {
304
- await tableUsers.insert({name: "All' o Phoibe"});
305
- await tableUsers.insert({name: "I've got that tune"});
306
-
307
- let res = await tableUsers.find({'name ~': "\\so\\s"});
308
- expect(res.map(r => r.name)).toEqual(["All' o Phoibe"]);
309
-
310
- res = await tableUsers.find({'name ~*': "\\sO\\s"});
311
- expect(res.map(r => r.name)).toEqual(["All' o Phoibe"]);
312
-
313
- res = await tableUsers.find({'name !~': "\\so\\s"});
314
- expect(res.map(r => r.name)).toEqual(["I've got that tune"]);
315
-
316
- res = await tableUsers.find({'name !~*': "\\sO\\s"});
317
- expect(res.map(r => r.name)).toEqual(["I've got that tune"]);
318
-
319
- }));
320
-
321
- it("Test regexp " +
322
- "~/~* ANY" +
323
- "!~/!~* ALL", w(async () => {
324
- await tableUsers.insert({name: "All' o Phoibe"});
325
- await tableUsers.insert({name: "I've got that tune"});
326
-
327
- let res = await tableUsers.find({'name ~': ["\\so\\s", '\\d+']});
328
- expect(res.map(r => r.name)).toEqual(["All' o Phoibe"]);
329
-
330
- res = await tableUsers.find({'name ~*': ["\\sO\\s", '\\d+']});
331
- expect(res.map(r => r.name)).toEqual(["All' o Phoibe"]);
332
-
333
- res = await tableUsers.find({'name !~': ["\\so\\s", '\\d+']});
334
- expect(res.map(r => r.name)).toEqual(["I've got that tune"]);
335
-
336
- res = await tableUsers.find({'name !~*': ["\\sO\\s", '\\d+']});
337
- expect(res.map(r => r.name)).toEqual(["I've got that tune"]);
338
-
339
- }));
340
-
341
-
342
- it("Test like ~~, like, ~~*, ilike, !~~, not like, !~~*, not ilike", w(async () => {
343
- await tableUsers.insert({name: 'Iced lemonade'});
344
- await tableUsers.insert({name: 'Cucumber pear juice'});
345
- let res;
346
-
347
- res = await tableUsers.find({'name ~~': '%lemon%'});
348
- expect(res.map(r => r.name)).toEqual(['Iced lemonade']);
349
-
350
- res = await tableUsers.find({'name like': '%lemon%'});
351
- expect(res.map(r => r.name)).toEqual(['Iced lemonade']);
352
-
353
- res = await tableUsers.find({'name ~~*': '%LEMON%'});
354
- expect(res.map(r => r.name)).toEqual(['Iced lemonade']);
355
-
356
- res = await tableUsers.find({'name ilike': '%LEMON%'});
357
- expect(res.map(r => r.name)).toEqual(['Iced lemonade']);
358
-
359
- res = await tableUsers.find({'name !~~': '%lemon%'});
360
- expect(res.map(r => r.name)).toEqual(['Cucumber pear juice']);
361
-
362
- res = await tableUsers.find({'name not like': '%lemon%'});
363
- expect(res.map(r => r.name)).toEqual(['Cucumber pear juice']);
364
-
365
- res = await tableUsers.find({'name !~~*': '%LEMON%'});
366
- expect(res.map(r => r.name)).toEqual(['Cucumber pear juice']);
367
-
368
- res = await tableUsers.find({'name not ilike': '%LEMON%'});
369
- expect(res.map(r => r.name)).toEqual(['Cucumber pear juice']);
370
-
371
- }));
372
-
373
- it("Test " +
374
- "like/~~/ilike/~~* ANY(), " +
375
- "not like/!~~/not ilike/!~~* ALL()", w(async () => {
376
-
377
- await tableUsers.insert({name: 'Iced lemonade'});
378
- await tableUsers.insert({name: 'Cucumber pear juice'});
379
- let res;
380
-
381
- res = await tableUsers.find({'name ~~': ['BB', '%lemon%']});
382
- expect(res.map(r => r.name)).toEqual(['Iced lemonade']);
383
-
384
- res = await tableUsers.find({'name like': ['BB', '%lemon%']});
385
- expect(res.map(r => r.name)).toEqual(['Iced lemonade']);
386
-
387
- res = await tableUsers.find({'name ~~*': ['bb', '%LEMON%']});
388
- expect(res.map(r => r.name)).toEqual(['Iced lemonade']);
389
-
390
- res = await tableUsers.find({'name ilike': ['bb', '%LEMON%']});
391
- expect(res.map(r => r.name)).toEqual(['Iced lemonade']);
392
-
393
- res = await tableUsers.find({'name !~~': ['BB', '%lemon%']});
394
- expect(res.map(r => r.name)).toEqual(['Cucumber pear juice']);
395
-
396
- res = await tableUsers.find({'name not like': ['BB', '%lemon%']});
397
- expect(res.map(r => r.name)).toEqual(['Cucumber pear juice']);
398
-
399
- res = await tableUsers.find({'name !~~*': ['bb', '%LEMON%']});
400
- expect(res.map(r => r.name)).toEqual(['Cucumber pear juice']);
401
-
402
- res = await tableUsers.find({'name not ilike': ['bb', '%LEMON%']});
403
- expect(res.map(r => r.name)).toEqual(['Cucumber pear juice']);
404
- }));
405
-
406
- it("Special added operators =*, icontains", w(async () => {
407
- await tableUsers.insert({name: 'Iced lemonade'});
408
- await tableUsers.insert({name: 'Cucumber pear juice', textList: ['good', 'better', 'best']});
409
- let res;
410
-
411
- res = await tableUsers.find({'name =*': 'ICED LEMONADE'});
412
- expect(res.map(r => r.name)).toEqual(['Iced lemonade']);
413
-
414
- res = await tableUsers.find({'textList icontains': 'GOOD'});
415
- expect(res.map(r => r.name)).toEqual(['Cucumber pear juice']);
416
-
417
- res = await tableUsers.find({'textList =*': 'GOOD'});
418
- expect(res.map(r => r.name)).toEqual(['Cucumber pear juice']);
419
-
420
- res = await tableUsers.find({'textList &&*': ['GOOD', 'Bad']});
421
- expect(res.map(r => r.name)).toEqual(['Cucumber pear juice']);
422
- }));
423
-
424
-
425
- });
426
-
427
- /*
428
-
429
- console.log('--- TEST 17 jsonb [{}] update ---------');
430
- res = await pdb.schemas['dev']['fsZones'].updateAndGetOne({id:14}, {zoneAdmins:[], buildings:[]});
431
- if (!Array.isArray(res.buildings) || !Array.isArray(res.zoneAdmins)) {
432
- throw Error('both should be an array!');
433
- }
434
- console.log(util.inspect(res, false, null));
435
-
436
- console.log('--- TEST 18 array<int> ---------');
437
- dbTable = pdb.schemas['dev']['fsZones'];
438
- res = await dbTable.findAll();
439
- console.log(util.inspect(res, false, null));
440
-
441
-
442
- console.log('--- TEST 20 parsing array fields ----------');
443
- res = await pdb.schemas['dev']['chemicals'].updateAndGetOne({id:167}, {extMedia:["test",'a b', 'c,d', '"e,f"','', null, null]});
444
- console.log(res);
445
-
446
-
447
- await pdb.close();
448
- console.log('end');
449
-
450
- })().catch(e => console.error(e.message, e.stack));
451
- */
452
-
453
- /**
454
- * {,ads,"asdf""fd,",",3," "}
455
- *
456
- s = ',ads,"asdf""fd,",",3," "';
457
- e =
458
- e.exec(s)
459
- */
460
- function parseComplexTypeArray(str) {
461
- let list = JSON.parse('[' + str.substring(1, str.length - 1) + ']');
462
-
463
- let result = [];
464
- for (let elementStr of list) {
465
- result.push(parseComplexType(elementStr));
466
- }
467
- return result;
468
- }
469
-
470
- function parseComplexType(str) {
471
- //cut of '(', ')'
472
- str = str.substring(1, str.length - 1);
473
- let e = /"((?:[^"]|"")*)"(?:,|$)|([^,]*)(?:,|$)/g;
474
- let valList = [];
475
- let parsingResult;
476
- let valStr;
477
- let hasNextValue;
478
- /**
479
- * parsingResult.index<str.length check for finish is not reliable
480
- * as if the last value is null it goes undetected, e.g. (,,)
481
- */
482
- do {
483
- parsingResult = e.exec(str);
484
- valStr = (parsingResult[0] == '' || parsingResult[0] == ',' || parsingResult[2] == 'null') ? null : parsingResult[1] || parsingResult[2];
485
- if (parsingResult[0] == '"",' || parsingResult[0] == '""') {
486
- valStr = '';
487
- }
488
- valList.push(valStr ? valStr.replace(/""/g, '"') : valStr);
489
- hasNextValue = parsingResult[0].substring(parsingResult[0].length - 1, parsingResult[0].length) == ',';
490
- } while (hasNextValue);
491
- return valList;
492
- }