pogi 2.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/.vscode/launch.json +35 -0
  2. package/CHANGELOG.md +277 -0
  3. package/LICENSE +21 -0
  4. package/README.md +85 -0
  5. package/docs/API/PgDb.md +218 -0
  6. package/docs/API/PgSchema.md +91 -0
  7. package/docs/API/PgTable.md +365 -0
  8. package/docs/API/QueryOptions.md +77 -0
  9. package/docs/API/condition.md +133 -0
  10. package/docs/connection.md +91 -0
  11. package/docs/css/docs.css +164 -0
  12. package/docs/executingSqlFile.md +44 -0
  13. package/docs/faq.md +15 -0
  14. package/docs/functions.md +19 -0
  15. package/docs/generatingInterfaceForTables.md +35 -0
  16. package/docs/index.md +48 -0
  17. package/docs/logger.md +40 -0
  18. package/docs/mappingDatabaseTypes.md +89 -0
  19. package/docs/notification.md +19 -0
  20. package/docs/pitfalls.md +73 -0
  21. package/docs/streams.md +68 -0
  22. package/docs/transaction.md +65 -0
  23. package/lib/bin/generateInterface.d.ts +1 -0
  24. package/lib/bin/generateInterface.js +53 -0
  25. package/lib/bin/generateInterface.js.map +1 -0
  26. package/lib/connectionOptions.d.ts +25 -0
  27. package/lib/connectionOptions.js +3 -0
  28. package/lib/connectionOptions.js.map +1 -0
  29. package/lib/index.d.ts +6 -0
  30. package/lib/index.js +10 -0
  31. package/lib/index.js.map +1 -0
  32. package/lib/pgConverters.d.ts +10 -0
  33. package/lib/pgConverters.js +66 -0
  34. package/lib/pgConverters.js.map +1 -0
  35. package/lib/pgDb.d.ts +86 -0
  36. package/lib/pgDb.js +745 -0
  37. package/lib/pgDb.js.map +1 -0
  38. package/lib/pgDbLogger.d.ts +5 -0
  39. package/lib/pgDbLogger.js +3 -0
  40. package/lib/pgDbLogger.js.map +1 -0
  41. package/lib/pgDbOperators.d.ts +113 -0
  42. package/lib/pgDbOperators.js +44 -0
  43. package/lib/pgDbOperators.js.map +1 -0
  44. package/lib/pgSchema.d.ts +16 -0
  45. package/lib/pgSchema.js +16 -0
  46. package/lib/pgSchema.js.map +1 -0
  47. package/lib/pgTable.d.ts +131 -0
  48. package/lib/pgTable.js +322 -0
  49. package/lib/pgTable.js.map +1 -0
  50. package/lib/pgUtils.d.ts +31 -0
  51. package/lib/pgUtils.js +157 -0
  52. package/lib/pgUtils.js.map +1 -0
  53. package/lib/queryAble.d.ts +76 -0
  54. package/lib/queryAble.js +330 -0
  55. package/lib/queryAble.js.map +1 -0
  56. package/lib/queryWhere.d.ts +8 -0
  57. package/lib/queryWhere.js +249 -0
  58. package/lib/queryWhere.js.map +1 -0
  59. package/mkdocs.yml +25 -0
  60. package/package.json +65 -0
  61. package/spec/resources/init.sql +122 -0
  62. package/spec/resources/throw_exception.sql +5 -0
  63. package/spec/resources/tricky.sql +13 -0
  64. package/spec/run.js +5 -0
  65. package/spec/support/jasmine.json +9 -0
  66. package/src/bin/generateInterface.ts +54 -0
  67. package/src/connectionOptions.ts +42 -0
  68. package/src/index.ts +6 -0
  69. package/src/pgConverters.ts +55 -0
  70. package/src/pgDb.ts +820 -0
  71. package/src/pgDbLogger.ts +13 -0
  72. package/src/pgDbOperators.ts +62 -0
  73. package/src/pgSchema.ts +15 -0
  74. package/src/pgTable.ts +401 -0
  75. package/src/pgUtils.ts +176 -0
  76. package/src/queryAble.ts +393 -0
  77. package/src/queryWhere.ts +326 -0
  78. package/src/test/pgDbOperatorSpec.ts +492 -0
  79. package/src/test/pgDbSpec.ts +1339 -0
  80. package/src/test/pgServiceRestartTest.ts +1500 -0
  81. package/src/tsconfig.json +33 -0
  82. package/utils_sql/lower.sql +4 -0
@@ -0,0 +1,35 @@
1
+ {
2
+ // Use IntelliSense to learn about possible attributes.
3
+ // Hover to view descriptions of existing attributes.
4
+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
+ "version": "0.2.0",
6
+ "configurations": [
7
+ {
8
+ "name": "Debug via npm",
9
+ "type": "node",
10
+ "request": "launch",
11
+ "cwd": "${workspaceFolder}",
12
+ "runtimeExecutable": "npm",
13
+ "runtimeArgs": [
14
+ "run-script", "test_debug"
15
+ ],
16
+ "port": 9229
17
+ },
18
+ {
19
+ "name": "Run test",
20
+ "type": "node",
21
+ "request": "launch",
22
+ "cwd": "${workspaceFolder}",
23
+ "program": "${workspaceFolder}/spec/run.js",
24
+ "runtimeExecutable": "node",
25
+ "skipFiles": [
26
+ "fs.js",
27
+ "typescript.js",
28
+ "tslib.js",
29
+ "loader.js",
30
+ "loaders.js",
31
+ "helpers.js",
32
+ ]
33
+ }
34
+ ]
35
+ }
package/CHANGELOG.md ADDED
@@ -0,0 +1,277 @@
1
+ # [2.11.0](https://github.com/holdfenytolvaj/pogi/compare/v2.10.0...v2.11.0) (2021-09-16)
2
+
3
+ ### Features
4
+
5
+ - documentation on postgres-notifications
6
+ ([427119b](https://github.com/holdfenytolvaj/pogi/commit/427119baa3ffd8a19dc5ba5084e08ab7e2a4c395))
7
+ - automatic restart upon disconnected connection ([2bc777a](https://github.com/holdfenytolvaj/pogi/commit/2bc777ace4b88c2890b80e4090f3733137b89ef5))
8
+ - automatic recognition of changed enum ([5af7146](https://github.com/holdfenytolvaj/pogi/commit/5af7146d727f0344e3411a2f9df1f02afbf998b2),[bfaedd5](https://github.com/holdfenytolvaj/pogi/commit/bfaedd5a10810623d27be010e338abe324155494))
9
+
10
+ ### Bug Fixes
11
+
12
+ ## [2.10.2](https://github.com/holdfenytolvaj/pogi/compare/v2.10.0...v2.10.2) (2021-01-29)
13
+
14
+
15
+ ### Bug Fixes
16
+
17
+ * Null pointer exception ([289e6f4](https://github.com/holdfenytolvaj/pogi/commit/289e6f4))
18
+
19
+
20
+
21
+ ## [2.10.1](https://github.com/holdfenytolvaj/pogi/compare/v2.10.0...v2.10.1) (2021-01-29)
22
+
23
+
24
+ ### Bug Fixes
25
+
26
+ * Null pointer exception ([289e6f4](https://github.com/holdfenytolvaj/pogi/commit/289e6f4))
27
+
28
+
29
+
30
+ # [2.10.0](https://github.com/holdfenytolvaj/pogi/compare/v2.9.2...v2.10.0) (2021-01-29)
31
+
32
+
33
+ ### Features
34
+
35
+ * new query function queryAsRows which gives result as array instead of objects ([119aa73](https://github.com/holdfenytolvaj/pogi/commit/119aa73))
36
+
37
+
38
+
39
+ # [2.10.0](https://github.com/holdfenytolvaj/pogi/compare/v2.9.2...v2.10.0) (2021-01-29)
40
+
41
+
42
+ ### Features
43
+
44
+ * new query function queryAsRows which gives result as array instead of objects ([119aa73](https://github.com/holdfenytolvaj/pogi/commit/119aa73))
45
+
46
+
47
+
48
+ ## [2.9.2](https://github.com/holdfenytolvaj/pogi/compare/v2.9.1...v2.9.2) (2020-06-13)
49
+
50
+ ### Bug Fixes
51
+
52
+ * handle empty 'and' and 'or' condition ([e49c416](https://github.com/holdfenytolvaj/pogi/commit/e49c416))
53
+
54
+ ## [2.9.1](https://github.com/holdfenytolvaj/pogi/compare/v2.9.0...v2.9.1) (2020-06-13)
55
+
56
+ ### Chore
57
+ bump pg (8.2.1) and pg-query-stream (3.1.1) to support nodejs v14
58
+
59
+
60
+ # [2.9.0](https://github.com/holdfenytolvaj/pogi/compare/v2.8.0...v2.9.0) (2020-05-28)
61
+
62
+ ### Features
63
+
64
+ * more options to handle transaction, savepoint support from API ([d5a88cb](https://github.com/holdfenytolvaj/pogi/commit/d5a88cb))
65
+
66
+
67
+ # [2.8.0](https://github.com/holdfenytolvaj/pogi/compare/v2.5.11...v2.8.0) (2020-04-29)
68
+
69
+
70
+ ### Bug Fixes
71
+
72
+ * execute (file) function do not start new dedicated connection when run in one, add support for /* */ comment ([d5a03d5](https://github.com/holdfenytolvaj/pogi/commit/d5a03d5))
73
+
74
+
75
+ ### Features
76
+
77
+ * add notify and listen functions ([fb3318a](https://github.com/holdfenytolvaj/pogi/commit/fb3318a))
78
+
79
+
80
+
81
+ <a name="2.7.2"></a>
82
+ ## add initial support for postgresl PUB/SUB
83
+
84
+ <a name="2.7.1"></a>
85
+ ## add more test and update packages
86
+
87
+ [.. some missing update]
88
+
89
+ <a name="2.5.11"></a>
90
+ ## [2.5.11](https://github.com/holdfenytolvaj/pogi/compare/v2.5.10...v2.5.11) (2018-10-01)
91
+
92
+
93
+ ### Bug Fixes
94
+
95
+ * queryOneField and queryOneColumn maybe fall if no result found ([3395951](https://github.com/holdfenytolvaj/pogi/commit/3395951))
96
+
97
+
98
+
99
+ <a name="2.5.10"></a>
100
+ ## [2.5.10](https://github.com/holdfenytolvaj/pogi/compare/v2.5.9...v2.5.10) (2018-08-14)
101
+ * use different syntax for array query to avoid long sql (so instead of "field IN ($1, $2, $3)" where $1 $2 $3 are values use "field =ANY $1" where $1 is an array). There is no speed difference
102
+
103
+
104
+ <a name="2.5.8"></a>
105
+ ## [2.5.8](https://github.com/holdfenytolvaj/pogi/compare/v2.5.6...v2.5.8) (2018-04-23)
106
+ * Nothing changed, just scripts runs and runs
107
+
108
+
109
+ <a name="2.5.7"></a>
110
+ ## [2.5.7](https://github.com/holdfenytolvaj/pogi/compare/v2.5.6...v2.5.7) (2018-04-23)
111
+
112
+ ### Bug Fixes
113
+
114
+ * null item value handling on column type number[]
115
+
116
+
117
+ <a name="2.5.6"></a>
118
+ ## [2.5.6](https://github.com/holdfenytolvaj/pogi/compare/v2.5.5...v2.5.6) (2018-03-05)
119
+
120
+
121
+ ### Bug Fixes
122
+
123
+ * reload function should use transaction if it started to reload schema. ([d14c495](https://github.com/holdfenytolvaj/pogi/commit/d14c495))
124
+
125
+
126
+
127
+ <a name="2.5.5"></a>
128
+ ## [2.5.5](https://github.com/holdfenytolvaj/pogi/compare/v2.5.3...v2.5.5) (2017-12-12)
129
+ * Nothing changed, just scripts runs and runs
130
+
131
+ ## [2.5.4](https://github.com/holdfenytolvaj/pogi/compare/v2.5.3...v2.5.5) (2017-12-12)
132
+ ### Bug Fixes
133
+ * fix import statement
134
+
135
+ <a name="2.5.3"></a>
136
+ ## [2.5.3](https://github.com/holdfenytolvaj/pogi/compare/v2.5.2...v2.5.3) (2017-12-04)
137
+
138
+
139
+ ### Bug Fixes
140
+
141
+ * array column parsing , JSON.parse do not handle correctly special characters ex: \ f (formfeed) ([c2a48dc](https://github.com/holdfenytolvaj/pogi/commit/c2a48dc))
142
+
143
+
144
+
145
+ <a name="2.5.2"></a>
146
+ ## [2.5.2](https://github.com/holdfenytolvaj/pogi/compare/v2.5.1...v2.5.2) (2017-11-30)
147
+
148
+
149
+ ### Bug Fixes
150
+
151
+ * update query build did not handle properly null value on query ([0d84e61](https://github.com/holdfenytolvaj/pogi/commit/0d84e61))
152
+
153
+
154
+
155
+ <a name="2.5.1"></a>
156
+ ## [2.5.1](https://github.com/holdfenytolvaj/pogi/compare/v2.5.0...v2.5.1) (2017-11-08)
157
+ * Nothing changed, just scripts runs and runs
158
+
159
+
160
+ <a name="2.5.0"></a>
161
+ # [2.5.0](https://github.com/holdfenytolvaj/pogi/compare/v2.4.0...v2.5.0) (2017-11-08)
162
+
163
+
164
+ ### Bug Fixes
165
+
166
+ * add tslib to dependencies ([eb16ea4](https://github.com/holdfenytolvaj/pogi/commit/eb16ea4))
167
+ * jsonb[] column parsing ([eafb0fd](https://github.com/holdfenytolvaj/pogi/commit/eafb0fd))
168
+
169
+
170
+
171
+ <a name="2.4.0"></a>
172
+ # [2.4.0](https://github.com/holdfenytolvaj/pogi/compare/v2.3.5...v2.4.0) (2017-10-24)
173
+
174
+
175
+ ### Features
176
+
177
+ * add queryFirst, queryOne queries which return only one result ([dce7bad](https://github.com/holdfenytolvaj/pogi/commit/dce7bad))
178
+ * add distinct, forUpdate as boolean query options ([dce7bad](https://github.com/holdfenytolvaj/pogi/commit/dce7bad))
179
+
180
+
181
+
182
+ <a name="2.3.5"></a>
183
+ ## [2.3.5](https://github.com/holdfenytolvaj/pogi/compare/v2.3.4...v2.3.5) (2017-10-20)
184
+
185
+
186
+ ### Bug Fixes
187
+
188
+ * option is passed to pg connect by a copied object not prototype ([7c5e186](https://github.com/holdfenytolvaj/pogi/commit/7c5e186))
189
+
190
+
191
+
192
+ <a name="2.3.4"></a>
193
+ ## [2.3.4](https://github.com/holdfenytolvaj/pogi/compare/v2.3.3...v2.3.4) (2017-10-19)
194
+
195
+
196
+ ### Bug Fixes
197
+
198
+ * streams not released connections ([a7fdb42](https://github.com/holdfenytolvaj/pogi/commit/a7fdb42))
199
+ * textArray parsing do not handle right " character ([c3993db](https://github.com/holdfenytolvaj/pogi/commit/c3993db))
200
+
201
+
202
+
203
+ <a name="2.3.3"></a>
204
+ ## [2.3.3](https://github.com/holdfenytolvaj/pogi/compare/v2.3.2...v2.3.3) (2017-10-13)
205
+
206
+
207
+ ### Bug Fixes
208
+
209
+ * pg stream not working with newer version of pg-query-stream ([00d1687](https://github.com/holdfenytolvaj/pogi/commit/00d1687))
210
+
211
+
212
+
213
+ <a name="2.3.2"></a>
214
+ ## [2.3.2](https://github.com/holdfenytolvaj/pogi/compare/v2.2.4...v2.3.2) (2017-09-29)
215
+
216
+
217
+ ### Bug Fixes
218
+
219
+ * textArray parsing do not handle right \ escape character ([7b9c332](https://github.com/holdfenytolvaj/pogi/commit/7b9c332))
220
+
221
+
222
+
223
+ <a name="2.2.4"></a>
224
+ ## [2.2.4](https://github.com/holdfenytolvaj/pogi/compare/v2.2.3...v2.2.4) (2017-06-11)
225
+
226
+
227
+
228
+ <a name="2.2.3"></a>
229
+ ## [2.2.3](https://github.com/holdfenytolvaj/pogi/compare/v2.2.2...v2.2.3) (2017-06-06)
230
+
231
+
232
+
233
+ <a name="2.2.2"></a>
234
+ ## [2.2.2](https://github.com/holdfenytolvaj/pogi/compare/v2.2.1...v2.2.2) (2017-06-02)
235
+
236
+
237
+
238
+ <a name="2.2.1"></a>
239
+ ## [2.2.1](https://github.com/holdfenytolvaj/pogi/compare/v2.2.0...v2.2.1) (2017-03-20)
240
+
241
+
242
+
243
+ <a name="2.2.0"></a>
244
+ # [2.2.0](https://github.com/holdfenytolvaj/pogi/compare/v2.1.1...v2.2.0) (2017-03-18)
245
+
246
+
247
+
248
+ <a name="2.1.1"></a>
249
+ ## [2.1.1](https://github.com/holdfenytolvaj/pogi/compare/v2.1.0...v2.1.1) (2017-03-13)
250
+
251
+
252
+
253
+ <a name="2.1.0"></a>
254
+ # [2.1.0](https://github.com/holdfenytolvaj/pogi/compare/v2.0.0...v2.1.0) (2017-01-23)
255
+
256
+
257
+
258
+ <a name="2.0.0"></a>
259
+ # [2.0.0](https://github.com/holdfenytolvaj/pogi/compare/v1.0.4...v2.0.0) (2016-12-12)
260
+
261
+
262
+
263
+ <a name="1.0.2"></a>
264
+ ## [1.0.2](https://github.com/holdfenytolvaj/pogi/compare/v1.0.1...v1.0.2) (2016-11-30)
265
+
266
+
267
+
268
+ <a name="1.0.1"></a>
269
+ ## [1.0.1](https://github.com/holdfenytolvaj/pogi/compare/v1.0.0...v1.0.1) (2016-10-13)
270
+
271
+
272
+
273
+ <a name="1.0.0"></a>
274
+ # 1.0.0 (2016-10-12)
275
+
276
+
277
+
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright 2016 Radics, Laszlo & Radics, Geza
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,85 @@
1
+ # pogi
2
+ > What is your dream?
3
+
4
+ **pogi** is a wrapper over [pg.js](https://github.com/brianc/node-postgres) to use PostgreSQL easier.
5
+ - it is not an over engineered ORM with new syntax to learn and with less functionality,
6
+ - it is not a simple prepared statements executor with a lot of boilerplate for queries
7
+
8
+ it is somewhere in between, around the _golden_ middle ground.
9
+
10
+ ## Some of the features:
11
+ - typescript support (async-await!) (also can generate the structure for the db)
12
+ - transaction support
13
+ - connection pooling
14
+ - sql file execution
15
+ - BYOL - bring your own logger :) (db/schema/table/query level)
16
+ - encourage mixing jsonb and relational columns (arrays, complex types, enums etc) to get the full power!
17
+ - named parameters for queries
18
+ - stream support
19
+
20
+ so all the basics that you would expect in 2018.
21
+
22
+ ## Install
23
+ ```js
24
+ npm install pogi --save
25
+ ```
26
+
27
+ ## Documentation (includes why+1?)
28
+ [here](http://pogi.readthedocs.io/en/latest/)
29
+
30
+ [Our experience on migrating from mongo](https://hackernoon.com/javascript-experience-of-migrating-from-mongodb-to-postgresql-21f8bf140c05#.k4d7hqsv2)
31
+
32
+
33
+ ## Some examples to get the taste
34
+ ```js
35
+ import {PgDb} from "pogi";
36
+
37
+ let pgdb = await PgDb.connect({connectionString: "postgres://"});
38
+
39
+ let table = pgdb['test']['users']; //or pgdb.test.users if you generate the interface
40
+
41
+ let c1 = await pgdb.query(`SELECT COUNT(*) as c FROM ${table} WHERE active=:active`, {active:true});
42
+ let c2 = await table.count({active:true});
43
+ c1[0].c == c2; //true
44
+
45
+ //mix json and relational columns (e.g. enumerations)
46
+ await table.insert({name:'simply', permissions:['r','w','e'], props:{email:'undefined@dev.null'}});
47
+
48
+ let rows;
49
+
50
+ //use the same operators as in postgre
51
+ rows = await table.find({'name ~':'Jo.*', //regexp
52
+ 'jsoncolumn @>':{'dream':{'change':'the world'}}, //contains
53
+ 'arraycolumn @>':['up', 'down']}); //contains
54
+
55
+ //will be transformed to "select * from test.users where id in (1,2,3)"
56
+ rows = await table.find({id:[1,2,3]});
57
+
58
+ //easy fallback
59
+ rows = await table.findWhere('"happyWife"="happyLife" and name=:name', {name:'me'});
60
+
61
+ //convenient functions
62
+ let power = await pgdb.queryOneField('SELECT MAX(power) FROM magical.dbhandlers');
63
+ power; //>9000
64
+
65
+ //much more!
66
+
67
+ ```
68
+
69
+ ## It's not without pitfalls
70
+ What is? It's just usually not written (definitely not in the front page), but see more in the [docs](https://pogi.readthedocs.io/pitfalls/).
71
+ I wish more project would be honest about it to save a lot of hours for others. If you find more,
72
+ don't hesitate to tell us!
73
+
74
+ ## Contributing
75
+ Ideas are welcome! To compile & test
76
+ ```js
77
+ npm run build
78
+ npm run test
79
+ ```
80
+
81
+ ## Changelog
82
+ [Changelog.md](CHANGELOG.md)
83
+
84
+ ## Handcrafted at
85
+ [www.labcup.net](http://www.labcup.net/)
@@ -0,0 +1,218 @@
1
+ For all the examples below
2
+ ```js
3
+ import {PgDb} from "pogi";
4
+
5
+ let pgdb = PgDb.connect(..);
6
+ ```
7
+ Note: search path will be readed on connection and `tables` and `fn` properties will be populated by that. However these are not merged into PgDb object, while schemas will be.
8
+
9
+ #Properties
10
+ ## db
11
+ <span class="def">db:</span><span class="type">PgDb</span>
12
+ Back reference to this instance.
13
+ ## schemas
14
+ <span class="def">schemas:</span><span class="type">{[name:string]:PgSchema}</span>
15
+ Schemas, also merged to db object.
16
+ ## tables
17
+ <span class="def">tables:</span><span class="type">{[name:string]:PgTable}</span>
18
+ Tables in the search_path.
19
+ ## fn
20
+ <span class="def">fn:</span><span class="type">{[name:string]:Function}</span>
21
+ Stored procedures and functions in the search_path.
22
+ #Functions
23
+ ##setLogger
24
+ <span class="def"><span class="func">setLogger</span>(logger:<span class="type">PgDbLogger</span>) </span>
25
+
26
+ Note: inherited.
27
+
28
+ Sets the fallback logger for all queries (if no schema, table or query level logger is set, this will be used).
29
+ ```js
30
+ pgdb.setLogger(console);
31
+ ```
32
+
33
+ ---
34
+ ## isTransactionActive
35
+ <span class="def"><span class="func">isTransactionActive</span>():Promise&lt;<span class="type">PgDb</span>&gt;</span>
36
+
37
+ Returns true if the active connection has transaction ongoing. (Does not detect timeouts.)
38
+
39
+ # Functions - async
40
+
41
+ ## connect
42
+ <span style="color:darkorange;">static</span> <span class="def"><span class="func">connect</span>(config:<span class="type">ConnectionOptions</span>):Promise&lt;<span class="type">PgDb</span>&gt;</span>
43
+
44
+ see [connection](/connection) section
45
+
46
+ ---
47
+ ## close
48
+ <span style="color:darkorange;">static</span> <span class="def"><span class="func">close</span>():Promise&lt;<span class="type">void</span>&gt;</span>
49
+
50
+ Close connection, useful for exiting/teardown code.
51
+
52
+ ---
53
+ ## dedicatedConnectionBegin
54
+ <span class="def"><span class="func">dedicatedConnectionBegin</span>():Promise&lt;<span class="type">PgDb</span>&gt;</span>
55
+
56
+ You can use dedicated connection instead of pool. It is very useful if you plan to use such a command: `SET search_path TO "dev";`
57
+ Similar to [transactionBegin](#transactionBegin) but without transaction. This function will create a new PgDb instance with the dedicated connection mode.
58
+ Use of that Pgdb instance all query will go throuth that single connection. The original pgdb instance won't touched.
59
+ For example see the [transaction](/transaction) section.
60
+
61
+ ---
62
+ ## dedicatedConnectionEnd
63
+ <span class="def"><span class="func">dedicatedConnectionEnd</span>():Promise&lt;<span class="type">PgDb</span>&gt;</span>
64
+
65
+ Close dedicated connection. If there is no dedicated connection, do nothing. After that pgdb instance will work in pooled connection mode.
66
+ Return value will be the same pgdb instance.
67
+ For example see the [transaction](/transaction) section.
68
+
69
+ ---
70
+ ## execute
71
+ <span class="def"><span class="func">execute</span>(fileName, transformer?:<span class="type">(string)=&gt;string)</span>):Promise&lt;<span class="type">void</span>&gt;</span>
72
+
73
+ Executes an sql file, with a transformer function. For more details see [Executing sql files](/executingSqlFile) section.
74
+
75
+ ```js
76
+ for (let schemaName of ['test1', 'test2']) {
77
+ await pgdb.execute(__dirname + '/db_upgrade/all.sql', (cmd)=&gt;cmd.replace(/__SCHEMA__/g, '"' + schemaName + '"'));
78
+ }
79
+ ```
80
+
81
+ where the sql file is (`__SCHEMA__` will be replaced to the `schemaName` see above)
82
+ ```sql
83
+ UPDATE __SCHEMA__.webapp set lang='TS' where lang='JS';
84
+ ```
85
+
86
+ ---
87
+ ##query
88
+ <span class="def"><span class="func">query</span>(sql:<span class="type">string</span>, params?:<span class="type">any[]|{}</span>, options?:<span class="type">SqlQueryOptions</span>):Promise&lt;<span class="type">any[]</span>&gt;</span>
89
+ <a name="query"></a>
90
+
91
+ Executes an arbitrary sql string with parameters / named parameters.
92
+ ```ts
93
+ let res1 = await schema.query('SELECT MAX(point) from game1.scores WHERE name=$1 ', ['player1']);
94
+ let res2 = await schema.query('SELECT MAX(point) from !:schema.scores WHERE name=:name ', {schema:'game1', name:'player1'});
95
+ ```
96
+ ---
97
+ ##queryFirst
98
+ <span class="def"><span class="func">queryFirst</span>(sql:<span class="type">string</span>, params?:<span class="type">any[]|{}</span>, options?:<span class="type">SqlQueryOptions</span>):Promise&lt;<span class="type">any</span>&gt;</span>
99
+ <a name="query"></a>
100
+
101
+ Executes an arbitrary sql string with parameters / named parameters. Return the first record.
102
+
103
+ ---
104
+ ##queryOne
105
+ <span class="def"><span class="func">query</span>(sql:<span class="type">string</span>, params?:<span class="type">any[]|{}</span>, options?:<span class="type">SqlQueryOptions</span>):Promise&lt;<span class="type">any</span>&gt;</span>
106
+ <a name="query"></a>
107
+
108
+ Executes an arbitrary sql string with parameters / named parameters. Return the first record, throw Error if there are more.
109
+
110
+ ---
111
+ ## queryOneField
112
+ <span class="def"><span class="func">queryOneField</span>(sql:<span class="type">string</span>, params?:<span class="type">any[]|{}</span>, options?:<span class="type">SqlQueryOptions</span>):Promise&lt;<span class="type">any</span>&gt;</span>
113
+
114
+ Note: inherited, uses schema level log if present (if not then the db level log).
115
+
116
+ If there is only one record and one field that we are interested in. For the params usage see [query](#query).
117
+ ```js
118
+ let winner = await schema.getOneField(`SELECT 'The winner is ' || name FROM test1.users LIMIT 1`);
119
+ console.log(winner); //The winner is Admin
120
+ ```
121
+
122
+ ---
123
+ ## queryOneColumn
124
+ <span class="def"><span class="func">queryOneColumn</span>(sql:<span class="type">string</span>, params?:<span class="type">any[]|{}</span>, options?:<span class="type">SqlQueryOptions</span>):Promise&lt;<span class="type">any[]</span>&gt;</span>
125
+
126
+ Note: inherited, uses schema level log if present (if not then the db level log).
127
+
128
+ If there is only one column that we are interested in. For the params usage see [query](#query).
129
+ ```js
130
+ let userList = await schema.getOneColumn('SELECT name FROM test1.users');
131
+ console.dir(userList); //['Admin', 'User1', 'User2']
132
+ ```
133
+
134
+ ---
135
+ ## queryAsStream
136
+ <span class="def"><span class="func">queryAsStream</span>(sql:<span class="type">string</span>, params?:<span class="type">any[]|{}</span>, options?:<span class="type">SqlQueryOptions</span>):Promise&lt;<span class="type">any[]</span>&gt;</span>
137
+
138
+ ---
139
+ ## reload
140
+ <span class="def"><span class="func">reload</span>()</span>
141
+ Rerun the queries to load the schemas, tables and special types.
142
+ Need to be called after truncate(!), alter table, create schema etc.
143
+
144
+ ---
145
+ ##run
146
+ <span class="def"><span class="func">run</span>(sql:<span class="type">string</span>):Promise&lt;<span class="type">any[]</span>&gt;</span>
147
+ Executes an arbitrary sql string.
148
+ ```js
149
+ await schema.run('CREATE schema myschema');
150
+ ```
151
+
152
+ ---
153
+ ## setTypeParser
154
+ <span class="def"><span class="func">setTypeParser</span>(typeName:<span class="type">string</span>, parser:<span class="type">(string)=&gt;any</span>, schemaName?:<span class="type">string</span>): Promise&lt;<span class="type">void</span>&gt;</span>
155
+
156
+ See the [mapping database types to js types](/mappingDatabaseTypes) section
157
+
158
+ ---
159
+ ## setPgTypeParser
160
+ <span class="def"><span class="func">setPgTypeParser</span>(typeName:<span class="type">string</span>, parser:<span class="type">(string)=&gt;any</span>, schemaName?:<span class="type">string</span>): Promise&lt;<span class="type">void</span>&gt;</span>
161
+
162
+ See the [mapping database types to js types](/mappingDatabaseTypes) section
163
+
164
+ ---
165
+ ## setPostProcessResult
166
+ <span class="def"><span class="func">setPostProcessResult</span>(f:(res: <span class="type">any[]</span>, fields: <span class="type">ResultFieldType[]</span>, logger:<span class="type">PgDbLogger</span>)=&gt;<span class="type">void</span>): <span class="type">void</span></span>
167
+ You can add a postprocessor function that will be executed for every result (even empty ones), if you want to do something extra.
168
+ If you call it twice the second function will overwrite the first. So you can easily unset also if you call it will null;
169
+
170
+ ---
171
+ ## transactionBegin
172
+ <span class="def"><span class="func">transactionBegin</span>():Promise&lt;<span class="type">PgDb</span>&gt;</span>
173
+
174
+ Return with a new PgDb instance with dedicated connection mode and start a transaction.
175
+ (Only this connection has the transaction, can be committed or rolled back. Similar to [dedicatedConnectionBegin](#dedicatedConnectionBegin))
176
+
177
+ For example see the [transaction](/transaction) section.
178
+
179
+ ---
180
+ ## transactionCommit
181
+ <span class="def"><span class="func">transactionCommit</span>():Promise&lt;<span class="type">PgDb</span>&gt;</span>
182
+
183
+ If the PgDb instance has dedicated connection mode and has transaction it will commits that, otherwise do nothing.
184
+ Returns with PgDb instance (with pool connections mode) where no transaction is taking place.
185
+ For example see the [transaction](/transaction) section.
186
+
187
+ ---
188
+ ## transactionRollback
189
+ <span class="def"><span class="func">transactionRollback</span>():Promise&lt;<span class="type">PgDb</span>&gt;</span>
190
+
191
+ If the PgDb instance has dedicated connection mode and has transaction it will rolls back, otherwise do nothing.
192
+ Returns with PgDb instance (with pool connections mode) where no transaction is taking place.
193
+ For example see the [transaction](/transaction) section.
194
+
195
+ ---
196
+ ## listen
197
+ <span class="def"><span class="func">listen</span>(channel:<span class="type">string</span>, callback:<span class="type">(Notification)=&gt;void)</span>;</>
198
+
199
+ Creates a new dedicated connection for listeners (if it doesn't exists), and sets a callback for the channel.
200
+ It is possible to set multiple callbacks for one channel.
201
+ If there will be a notification from the database, the callback will be executed.
202
+ For example see the [notification](/notification) section.
203
+
204
+ ---
205
+ ## unlisten
206
+ <span class="def"><span class="func">unlisten</span>(channel:<span class="type">string</span>, callback?:<span class="type">(Notification)=&gt;void)</span>;</>
207
+
208
+ Removes a listener. If callback parameter is set, only the given callback will be removed.
209
+ If callback parameter is not set, all callbacks will be removed from the channel.
210
+ If it was the last channel, the dedicated connection for listeners will be released.
211
+ For example see the [notification](/notification) section.
212
+
213
+ ---
214
+ ## notify
215
+ <span class="def"><span class="func">notify</span>(channel:<span class="type">string</span>, payload?:<span class="type">string</span>;</>
216
+
217
+ Send a notification via postgresql.
218
+ For example see the [notification](/notification) section.