postgrejs 2.22.9 → 2.23.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 (216) hide show
  1. package/CHANGELOG.md +8 -1
  2. package/{esm/connection → connection}/bind-param.js +2 -0
  3. package/{esm/connection → connection}/connection.js +4 -2
  4. package/{esm/connection → connection}/cursor.js +8 -3
  5. package/{esm/connection → connection}/intl-connection.js +6 -3
  6. package/{esm/connection → connection}/pool.js +4 -1
  7. package/{esm/connection → connection}/portal.js +3 -1
  8. package/{esm/connection → connection}/prepared-statement.js +6 -3
  9. package/{esm/constants.js → constants.js} +1 -1
  10. package/{esm/data-type-map.js → data-type-map.js} +2 -2
  11. package/package.json +12 -31
  12. package/{esm/protocol → protocol}/backend.js +1 -0
  13. package/{esm/protocol → protocol}/buffer-reader.js +2 -1
  14. package/{esm/protocol → protocol}/database-error.js +16 -0
  15. package/{esm/protocol → protocol}/frontend.js +1 -0
  16. package/{esm/protocol → protocol}/pg-socket.js +9 -3
  17. package/{esm/protocol → protocol}/smart-buffer.js +9 -5
  18. package/{esm/util → util}/bigint-methods.js +1 -0
  19. package/cjs/connection/bind-param.js +0 -10
  20. package/cjs/connection/connection.js +0 -295
  21. package/cjs/connection/cursor.js +0 -91
  22. package/cjs/connection/intl-connection.js +0 -258
  23. package/cjs/connection/pool.js +0 -236
  24. package/cjs/connection/portal.js +0 -157
  25. package/cjs/connection/prepared-statement.js +0 -226
  26. package/cjs/constants.js +0 -249
  27. package/cjs/data-type-map.js +0 -131
  28. package/cjs/data-types/bool-type.js +0 -33
  29. package/cjs/data-types/box-type.js +0 -52
  30. package/cjs/data-types/bytea-type.js +0 -28
  31. package/cjs/data-types/char-type.js +0 -27
  32. package/cjs/data-types/circle-type.js +0 -51
  33. package/cjs/data-types/date-type.js +0 -75
  34. package/cjs/data-types/float4-type.js +0 -25
  35. package/cjs/data-types/float8-type.js +0 -25
  36. package/cjs/data-types/int2-type.js +0 -26
  37. package/cjs/data-types/int2-vector-type.js +0 -42
  38. package/cjs/data-types/int4-type.js +0 -28
  39. package/cjs/data-types/int8-type.js +0 -36
  40. package/cjs/data-types/json-type.js +0 -40
  41. package/cjs/data-types/jsonb-type.js +0 -44
  42. package/cjs/data-types/lseg-type.js +0 -55
  43. package/cjs/data-types/numeric-type.js +0 -125
  44. package/cjs/data-types/oid-type.js +0 -32
  45. package/cjs/data-types/point-type.js +0 -42
  46. package/cjs/data-types/time-type.js +0 -66
  47. package/cjs/data-types/timestamp-type.js +0 -89
  48. package/cjs/data-types/timestamptz-type.js +0 -76
  49. package/cjs/data-types/uuid-type.js +0 -39
  50. package/cjs/data-types/varchar-type.js +0 -27
  51. package/cjs/index.js +0 -28
  52. package/cjs/interfaces/command-result.js +0 -2
  53. package/cjs/interfaces/data-mapping-options.js +0 -2
  54. package/cjs/interfaces/data-type.js +0 -2
  55. package/cjs/interfaces/database-connection-params.js +0 -2
  56. package/cjs/interfaces/field-info.js +0 -2
  57. package/cjs/interfaces/query-options.js +0 -2
  58. package/cjs/interfaces/query-result.js +0 -2
  59. package/cjs/interfaces/script-execute-options.js +0 -2
  60. package/cjs/interfaces/script-result.js +0 -2
  61. package/cjs/interfaces/statement-prepare-options.js +0 -2
  62. package/cjs/package.json +0 -3
  63. package/cjs/protocol/backend.js +0 -262
  64. package/cjs/protocol/buffer-reader.js +0 -78
  65. package/cjs/protocol/database-error.js +0 -17
  66. package/cjs/protocol/frontend.js +0 -255
  67. package/cjs/protocol/pg-socket.js +0 -367
  68. package/cjs/protocol/protocol.js +0 -71
  69. package/cjs/protocol/sasl.js +0 -108
  70. package/cjs/protocol/smart-buffer.js +0 -178
  71. package/cjs/safe-event-emitter.js +0 -17
  72. package/cjs/tsconfig-build-cjs.tsbuildinfo +0 -1
  73. package/cjs/types.js +0 -2
  74. package/cjs/util/array-calculatedim.js +0 -18
  75. package/cjs/util/bigint-methods.js +0 -44
  76. package/cjs/util/config-from-env.js +0 -29
  77. package/cjs/util/connection-config.js +0 -61
  78. package/cjs/util/convert-row-to-object.js +0 -12
  79. package/cjs/util/decode-binaryarray.js +0 -38
  80. package/cjs/util/encode-binaryarray.js +0 -44
  81. package/cjs/util/escape-literal.js +0 -26
  82. package/cjs/util/fast-parseint.js +0 -31
  83. package/cjs/util/get-parsers.js +0 -41
  84. package/cjs/util/parse-array.js +0 -60
  85. package/cjs/util/parse-datetime.js +0 -37
  86. package/cjs/util/parse-row.js +0 -11
  87. package/cjs/util/parse-time.js +0 -30
  88. package/cjs/util/stringify-arrayliteral.js +0 -37
  89. package/cjs/util/stringify-for-sql.js +0 -29
  90. package/cjs/util/wrap-row-description.js +0 -34
  91. package/esm/package.json +0 -3
  92. package/types/index.d.cts +0 -25
  93. /package/{types/connection → connection}/bind-param.d.ts +0 -0
  94. /package/{types/connection → connection}/connection.d.ts +0 -0
  95. /package/{types/connection → connection}/cursor.d.ts +0 -0
  96. /package/{types/connection → connection}/intl-connection.d.ts +0 -0
  97. /package/{types/connection → connection}/pool.d.ts +0 -0
  98. /package/{types/connection → connection}/portal.d.ts +0 -0
  99. /package/{types/connection → connection}/prepared-statement.d.ts +0 -0
  100. /package/{types/constants.d.ts → constants.d.ts} +0 -0
  101. /package/{types/data-type-map.d.ts → data-type-map.d.ts} +0 -0
  102. /package/{types/data-types → data-types}/bool-type.d.ts +0 -0
  103. /package/{esm/data-types → data-types}/bool-type.js +0 -0
  104. /package/{types/data-types → data-types}/box-type.d.ts +0 -0
  105. /package/{esm/data-types → data-types}/box-type.js +0 -0
  106. /package/{types/data-types → data-types}/bytea-type.d.ts +0 -0
  107. /package/{esm/data-types → data-types}/bytea-type.js +0 -0
  108. /package/{types/data-types → data-types}/char-type.d.ts +0 -0
  109. /package/{esm/data-types → data-types}/char-type.js +0 -0
  110. /package/{types/data-types → data-types}/circle-type.d.ts +0 -0
  111. /package/{esm/data-types → data-types}/circle-type.js +0 -0
  112. /package/{types/data-types → data-types}/date-type.d.ts +0 -0
  113. /package/{esm/data-types → data-types}/date-type.js +0 -0
  114. /package/{types/data-types → data-types}/float4-type.d.ts +0 -0
  115. /package/{esm/data-types → data-types}/float4-type.js +0 -0
  116. /package/{types/data-types → data-types}/float8-type.d.ts +0 -0
  117. /package/{esm/data-types → data-types}/float8-type.js +0 -0
  118. /package/{types/data-types → data-types}/int2-type.d.ts +0 -0
  119. /package/{esm/data-types → data-types}/int2-type.js +0 -0
  120. /package/{types/data-types → data-types}/int2-vector-type.d.ts +0 -0
  121. /package/{esm/data-types → data-types}/int2-vector-type.js +0 -0
  122. /package/{types/data-types → data-types}/int4-type.d.ts +0 -0
  123. /package/{esm/data-types → data-types}/int4-type.js +0 -0
  124. /package/{types/data-types → data-types}/int8-type.d.ts +0 -0
  125. /package/{esm/data-types → data-types}/int8-type.js +0 -0
  126. /package/{types/data-types → data-types}/json-type.d.ts +0 -0
  127. /package/{esm/data-types → data-types}/json-type.js +0 -0
  128. /package/{types/data-types → data-types}/jsonb-type.d.ts +0 -0
  129. /package/{esm/data-types → data-types}/jsonb-type.js +0 -0
  130. /package/{types/data-types → data-types}/lseg-type.d.ts +0 -0
  131. /package/{esm/data-types → data-types}/lseg-type.js +0 -0
  132. /package/{types/data-types → data-types}/numeric-type.d.ts +0 -0
  133. /package/{esm/data-types → data-types}/numeric-type.js +0 -0
  134. /package/{types/data-types → data-types}/oid-type.d.ts +0 -0
  135. /package/{esm/data-types → data-types}/oid-type.js +0 -0
  136. /package/{types/data-types → data-types}/point-type.d.ts +0 -0
  137. /package/{esm/data-types → data-types}/point-type.js +0 -0
  138. /package/{types/data-types → data-types}/time-type.d.ts +0 -0
  139. /package/{esm/data-types → data-types}/time-type.js +0 -0
  140. /package/{types/data-types → data-types}/timestamp-type.d.ts +0 -0
  141. /package/{esm/data-types → data-types}/timestamp-type.js +0 -0
  142. /package/{types/data-types → data-types}/timestamptz-type.d.ts +0 -0
  143. /package/{esm/data-types → data-types}/timestamptz-type.js +0 -0
  144. /package/{types/data-types → data-types}/uuid-type.d.ts +0 -0
  145. /package/{esm/data-types → data-types}/uuid-type.js +0 -0
  146. /package/{types/data-types → data-types}/varchar-type.d.ts +0 -0
  147. /package/{esm/data-types → data-types}/varchar-type.js +0 -0
  148. /package/{types/index.d.ts → index.d.ts} +0 -0
  149. /package/{esm/index.js → index.js} +0 -0
  150. /package/{types/interfaces → interfaces}/command-result.d.ts +0 -0
  151. /package/{esm/interfaces → interfaces}/command-result.js +0 -0
  152. /package/{types/interfaces → interfaces}/data-mapping-options.d.ts +0 -0
  153. /package/{esm/interfaces → interfaces}/data-mapping-options.js +0 -0
  154. /package/{types/interfaces → interfaces}/data-type.d.ts +0 -0
  155. /package/{esm/interfaces → interfaces}/data-type.js +0 -0
  156. /package/{types/interfaces → interfaces}/database-connection-params.d.ts +0 -0
  157. /package/{esm/interfaces → interfaces}/database-connection-params.js +0 -0
  158. /package/{types/interfaces → interfaces}/field-info.d.ts +0 -0
  159. /package/{esm/interfaces → interfaces}/field-info.js +0 -0
  160. /package/{types/interfaces → interfaces}/query-options.d.ts +0 -0
  161. /package/{esm/interfaces → interfaces}/query-options.js +0 -0
  162. /package/{types/interfaces → interfaces}/query-result.d.ts +0 -0
  163. /package/{esm/interfaces → interfaces}/query-result.js +0 -0
  164. /package/{types/interfaces → interfaces}/script-execute-options.d.ts +0 -0
  165. /package/{esm/interfaces → interfaces}/script-execute-options.js +0 -0
  166. /package/{types/interfaces → interfaces}/script-result.d.ts +0 -0
  167. /package/{esm/interfaces → interfaces}/script-result.js +0 -0
  168. /package/{types/interfaces → interfaces}/statement-prepare-options.d.ts +0 -0
  169. /package/{esm/interfaces → interfaces}/statement-prepare-options.js +0 -0
  170. /package/{types/protocol → protocol}/backend.d.ts +0 -0
  171. /package/{types/protocol → protocol}/buffer-reader.d.ts +0 -0
  172. /package/{types/protocol → protocol}/database-error.d.ts +0 -0
  173. /package/{types/protocol → protocol}/frontend.d.ts +0 -0
  174. /package/{types/protocol → protocol}/pg-socket.d.ts +0 -0
  175. /package/{types/protocol → protocol}/protocol.d.ts +0 -0
  176. /package/{esm/protocol → protocol}/protocol.js +0 -0
  177. /package/{types/protocol → protocol}/sasl.d.ts +0 -0
  178. /package/{esm/protocol → protocol}/sasl.js +0 -0
  179. /package/{types/protocol → protocol}/smart-buffer.d.ts +0 -0
  180. /package/{types/safe-event-emitter.d.ts → safe-event-emitter.d.ts} +0 -0
  181. /package/{esm/safe-event-emitter.js → safe-event-emitter.js} +0 -0
  182. /package/{types/types.d.ts → types.d.ts} +0 -0
  183. /package/{esm/types.js → types.js} +0 -0
  184. /package/{types/util → util}/array-calculatedim.d.ts +0 -0
  185. /package/{esm/util → util}/array-calculatedim.js +0 -0
  186. /package/{types/util → util}/bigint-methods.d.ts +0 -0
  187. /package/{types/util → util}/config-from-env.d.ts +0 -0
  188. /package/{esm/util → util}/config-from-env.js +0 -0
  189. /package/{types/util → util}/connection-config.d.ts +0 -0
  190. /package/{esm/util → util}/connection-config.js +0 -0
  191. /package/{types/util → util}/convert-row-to-object.d.ts +0 -0
  192. /package/{esm/util → util}/convert-row-to-object.js +0 -0
  193. /package/{types/util → util}/decode-binaryarray.d.ts +0 -0
  194. /package/{esm/util → util}/decode-binaryarray.js +0 -0
  195. /package/{types/util → util}/encode-binaryarray.d.ts +0 -0
  196. /package/{esm/util → util}/encode-binaryarray.js +0 -0
  197. /package/{types/util → util}/escape-literal.d.ts +0 -0
  198. /package/{esm/util → util}/escape-literal.js +0 -0
  199. /package/{types/util → util}/fast-parseint.d.ts +0 -0
  200. /package/{esm/util → util}/fast-parseint.js +0 -0
  201. /package/{types/util → util}/get-parsers.d.ts +0 -0
  202. /package/{esm/util → util}/get-parsers.js +0 -0
  203. /package/{types/util → util}/parse-array.d.ts +0 -0
  204. /package/{esm/util → util}/parse-array.js +0 -0
  205. /package/{types/util → util}/parse-datetime.d.ts +0 -0
  206. /package/{esm/util → util}/parse-datetime.js +0 -0
  207. /package/{types/util → util}/parse-row.d.ts +0 -0
  208. /package/{esm/util → util}/parse-row.js +0 -0
  209. /package/{types/util → util}/parse-time.d.ts +0 -0
  210. /package/{esm/util → util}/parse-time.js +0 -0
  211. /package/{types/util → util}/stringify-arrayliteral.d.ts +0 -0
  212. /package/{esm/util → util}/stringify-arrayliteral.js +0 -0
  213. /package/{types/util → util}/stringify-for-sql.d.ts +0 -0
  214. /package/{esm/util → util}/stringify-for-sql.js +0 -0
  215. /package/{types/util → util}/wrap-row-description.d.ts +0 -0
  216. /package/{esm/util → util}/wrap-row-description.js +0 -0
@@ -1,157 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Portal = void 0;
4
- const constants_js_1 = require("../constants.js");
5
- const data_type_map_js_1 = require("../data-type-map.js");
6
- const protocol_js_1 = require("../protocol/protocol.js");
7
- const intl_connection_js_1 = require("./intl-connection.js");
8
- class Portal {
9
- constructor(statement, name) {
10
- this._columnFormat = constants_js_1.DEFAULT_COLUMN_FORMAT;
11
- this._statement = statement;
12
- this._name = name;
13
- }
14
- get connection() {
15
- return this._statement.connection;
16
- }
17
- get name() {
18
- return this._name;
19
- }
20
- async bind(params, queryOptions) {
21
- const intoCon = (0, intl_connection_js_1.getIntlConnection)(this.connection);
22
- intoCon.ref();
23
- try {
24
- const socket = intoCon.socket;
25
- this._columnFormat =
26
- queryOptions.columnFormat != null
27
- ? queryOptions.columnFormat
28
- : protocol_js_1.Protocol.DataFormat.binary;
29
- socket.sendBindMessage({
30
- typeMap: queryOptions.typeMap || data_type_map_js_1.GlobalTypeMap,
31
- statement: this._statement.name,
32
- portal: this.name,
33
- paramTypes: this._statement.paramTypes,
34
- params,
35
- queryOptions,
36
- });
37
- socket.sendFlushMessage();
38
- return await socket.capture(async (code, msg, done) => {
39
- switch (code) {
40
- case protocol_js_1.Protocol.BackendMessageCode.BindComplete:
41
- done();
42
- break;
43
- case protocol_js_1.Protocol.BackendMessageCode.NoticeResponse:
44
- break;
45
- default:
46
- done(new Error(`Server returned unexpected response message (${String.fromCharCode(code)})`));
47
- }
48
- });
49
- }
50
- finally {
51
- intoCon.unref();
52
- }
53
- }
54
- async retrieveFields() {
55
- const intoCon = (0, intl_connection_js_1.getIntlConnection)(this.connection);
56
- intoCon.ref();
57
- try {
58
- const socket = intoCon.socket;
59
- socket.sendDescribeMessage({ type: 'P', name: this.name });
60
- socket.sendFlushMessage();
61
- return await socket.capture(async (code, msg, done) => {
62
- switch (code) {
63
- case protocol_js_1.Protocol.BackendMessageCode.NoticeResponse:
64
- break;
65
- case protocol_js_1.Protocol.BackendMessageCode.NoData:
66
- done();
67
- break;
68
- case protocol_js_1.Protocol.BackendMessageCode.RowDescription:
69
- done(undefined, msg.fields);
70
- break;
71
- default:
72
- done(new Error(`Server returned unexpected response message (${String.fromCharCode(code)})`));
73
- }
74
- });
75
- }
76
- finally {
77
- intoCon.unref();
78
- }
79
- }
80
- async execute(fetchCount) {
81
- const intoCon = (0, intl_connection_js_1.getIntlConnection)(this.connection);
82
- intoCon.ref();
83
- try {
84
- const socket = intoCon.socket;
85
- socket.sendExecuteMessage({
86
- portal: this.name,
87
- fetchCount: fetchCount || 100,
88
- });
89
- socket.sendFlushMessage();
90
- const rows = [];
91
- return await socket.capture(async (code, msg, done) => {
92
- switch (code) {
93
- case protocol_js_1.Protocol.BackendMessageCode.NoticeResponse:
94
- break;
95
- case protocol_js_1.Protocol.BackendMessageCode.NoData:
96
- done(undefined, { code });
97
- break;
98
- case protocol_js_1.Protocol.BackendMessageCode.DataRow:
99
- if (Array.isArray(this._columnFormat)) {
100
- rows.push(msg.columns.map((buf, i) => this._columnFormat[i] ===
101
- protocol_js_1.Protocol.DataFormat.text
102
- ? buf.toString('utf8')
103
- : buf));
104
- }
105
- else if (this._columnFormat === protocol_js_1.Protocol.DataFormat.binary)
106
- rows.push(msg.columns);
107
- else
108
- rows.push(msg.columns.map((buf) => buf.toString('utf8')));
109
- break;
110
- case protocol_js_1.Protocol.BackendMessageCode.PortalSuspended:
111
- done(undefined, { code, rows });
112
- break;
113
- case protocol_js_1.Protocol.BackendMessageCode.CommandComplete:
114
- done(undefined, {
115
- code,
116
- rows,
117
- command: msg.command,
118
- rowCount: msg.rowCount,
119
- });
120
- break;
121
- default:
122
- done(new Error(`Server returned unexpected response message (${String.fromCharCode(code)})`));
123
- }
124
- });
125
- }
126
- finally {
127
- intoCon.unref();
128
- }
129
- }
130
- async close() {
131
- const intoCon = (0, intl_connection_js_1.getIntlConnection)(this.connection);
132
- intoCon.ref();
133
- try {
134
- const socket = intoCon.socket;
135
- socket.sendCloseMessage({ type: 'P', name: this.name });
136
- socket.sendSyncMessage();
137
- return await socket.capture(async (code, msg, done) => {
138
- switch (code) {
139
- case protocol_js_1.Protocol.BackendMessageCode.NoticeResponse:
140
- break;
141
- case protocol_js_1.Protocol.BackendMessageCode.CloseComplete:
142
- break;
143
- case protocol_js_1.Protocol.BackendMessageCode.ReadyForQuery:
144
- intoCon.transactionStatus = msg.status;
145
- done();
146
- break;
147
- default:
148
- done(new Error(`Server returned unexpected response message (${String.fromCharCode(code)})`));
149
- }
150
- });
151
- }
152
- finally {
153
- intoCon.unref();
154
- }
155
- }
156
- }
157
- exports.Portal = Portal;
@@ -1,226 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PreparedStatement = void 0;
4
- const putil_varhelpers_1 = require("putil-varhelpers");
5
- const constants_js_1 = require("../constants.js");
6
- const data_type_map_js_1 = require("../data-type-map.js");
7
- const protocol_js_1 = require("../protocol/protocol.js");
8
- const safe_event_emitter_js_1 = require("../safe-event-emitter.js");
9
- const convert_row_to_object_js_1 = require("../util/convert-row-to-object.js");
10
- const get_parsers_js_1 = require("../util/get-parsers.js");
11
- const parse_row_js_1 = require("../util/parse-row.js");
12
- const wrap_row_description_js_1 = require("../util/wrap-row-description.js");
13
- const cursor_js_1 = require("./cursor.js");
14
- const intl_connection_js_1 = require("./intl-connection.js");
15
- const portal_js_1 = require("./portal.js");
16
- let statementCounter = 0;
17
- let portalCounter = 0;
18
- class PreparedStatement extends safe_event_emitter_js_1.SafeEventEmitter {
19
- constructor(connection, sql, paramTypes) {
20
- super();
21
- this._sql = '';
22
- this._name = '';
23
- this._refCount = 0;
24
- this._connection = connection;
25
- this._name = 'S_' + ++statementCounter;
26
- this._sql = sql;
27
- this._paramTypes = paramTypes;
28
- this._onErrorSavePoint = 'SP_' + Math.round(Math.random() * 100000000);
29
- }
30
- static async prepare(connection, sql, options) {
31
- const intoCon = (0, intl_connection_js_1.getIntlConnection)(connection);
32
- intoCon.assertConnected();
33
- const socket = intoCon.socket;
34
- const statement = new PreparedStatement(connection, sql, options?.paramTypes);
35
- await intoCon.statementQueue
36
- .enqueue(async () => {
37
- intoCon.ref();
38
- try {
39
- socket.sendParseMessage({
40
- statement: statement.name,
41
- sql: statement.sql,
42
- paramTypes: statement.paramTypes,
43
- });
44
- socket.sendFlushMessage();
45
- try {
46
- await socket.capture(async (code, msg, done) => {
47
- if (code === protocol_js_1.Protocol.BackendMessageCode.ParseComplete)
48
- done();
49
- // May be Protocol.BackendMessageCode.NoticeResponse
50
- });
51
- }
52
- finally {
53
- socket.sendSyncMessage();
54
- await socket.capture(async (code, msg, done) => {
55
- if (code === protocol_js_1.Protocol.BackendMessageCode.ReadyForQuery)
56
- done();
57
- // May be Protocol.BackendMessageCode.NoticeResponse
58
- });
59
- }
60
- }
61
- finally {
62
- intoCon.unref();
63
- }
64
- })
65
- .toPromise();
66
- statement._refCount = 1;
67
- return statement;
68
- }
69
- get connection() {
70
- return this._connection;
71
- }
72
- get name() {
73
- return this._name;
74
- }
75
- get sql() {
76
- return this._sql;
77
- }
78
- get paramTypes() {
79
- return this._paramTypes;
80
- }
81
- async execute(options = {}) {
82
- const intlCon = (0, intl_connection_js_1.getIntlConnection)(this.connection);
83
- const transactionCommand = this.sql.match(/^(\bBEGIN\b|\bCOMMIT\b|\bSTART\b|\bROLLBACK|SAVEPOINT|RELEASE\b)/i);
84
- let beginFirst = false;
85
- let commitLast = false;
86
- if (!transactionCommand) {
87
- if (!intlCon.inTransaction &&
88
- (options?.autoCommit != null
89
- ? options?.autoCommit
90
- : intlCon.config.autoCommit) === false) {
91
- beginFirst = true;
92
- }
93
- if (intlCon.inTransaction && options?.autoCommit)
94
- commitLast = true;
95
- }
96
- if (beginFirst)
97
- await intlCon.execute('BEGIN');
98
- const rollbackOnError = !transactionCommand &&
99
- (options?.rollbackOnError != null
100
- ? options.rollbackOnError
101
- : (0, putil_varhelpers_1.coerceToBoolean)(intlCon.config.rollbackOnError, true));
102
- if (intlCon.inTransaction && rollbackOnError)
103
- await intlCon.execute('SAVEPOINT ' + this._onErrorSavePoint);
104
- try {
105
- const result = await intlCon.statementQueue
106
- .enqueue(() => this._execute(options))
107
- .toPromise();
108
- if (commitLast)
109
- await intlCon.execute('COMMIT');
110
- else if (intlCon.inTransaction && rollbackOnError) {
111
- await intlCon.execute('RELEASE ' + this._onErrorSavePoint + ';');
112
- }
113
- return result;
114
- }
115
- catch (e) {
116
- if (intlCon.inTransaction && rollbackOnError) {
117
- await intlCon.execute('ROLLBACK TO ' + this._onErrorSavePoint + ';');
118
- }
119
- throw e;
120
- }
121
- }
122
- async close() {
123
- --this._refCount;
124
- if (this._refCount > 0)
125
- return;
126
- const intoCon = (0, intl_connection_js_1.getIntlConnection)(this.connection);
127
- await intoCon.statementQueue.enqueue(() => this._close()).toPromise();
128
- }
129
- async cancel() {
130
- throw new Error('Not implemented yet');
131
- }
132
- async _execute(options = {}) {
133
- let portal;
134
- const intlCon = (0, intl_connection_js_1.getIntlConnection)(this.connection);
135
- intlCon.ref();
136
- try {
137
- const result = { command: undefined };
138
- const startTime = Date.now();
139
- const t = Date.now();
140
- // Create portal
141
- const portalName = 'P_' + ++portalCounter;
142
- portal = new portal_js_1.Portal(this, portalName);
143
- await portal.bind(options.params, options);
144
- const fields = await portal.retrieveFields();
145
- const typeMap = options.typeMap || data_type_map_js_1.GlobalTypeMap;
146
- let parsers;
147
- let resultFields;
148
- if (fields) {
149
- parsers = (0, get_parsers_js_1.getParsers)(typeMap, fields);
150
- resultFields = (0, wrap_row_description_js_1.wrapRowDescription)(typeMap, fields, options.columnFormat || constants_js_1.DEFAULT_COLUMN_FORMAT);
151
- result.fields = resultFields;
152
- result.rowType = options.objectRows ? 'object' : 'array';
153
- if (options.cursor) {
154
- result.cursor = new cursor_js_1.Cursor(this, portal, resultFields, parsers, options);
155
- this._refCount++;
156
- portal = undefined;
157
- return result;
158
- }
159
- }
160
- const executeResult = await portal.execute(options.fetchCount);
161
- result.executeTime = Date.now() - t;
162
- if (executeResult.command)
163
- result.command = executeResult.command;
164
- if (resultFields && parsers && executeResult.rows) {
165
- if (!result.command)
166
- result.command = 'SELECT';
167
- const rows = (result.rows = executeResult.rows);
168
- const l = rows.length;
169
- let row;
170
- for (let i = 0; i < l; i++) {
171
- row = rows[i];
172
- (0, parse_row_js_1.parseRow)(parsers, row, options);
173
- if (options.objectRows) {
174
- rows[i] = (0, convert_row_to_object_js_1.convertRowToObject)(resultFields, row);
175
- }
176
- }
177
- }
178
- if (result.command === 'DELETE' ||
179
- result.command === 'INSERT' ||
180
- result.command === 'UPDATE') {
181
- result.rowsAffected = executeResult.rowCount;
182
- }
183
- result.executeTime = Date.now() - startTime;
184
- return result;
185
- }
186
- finally {
187
- intlCon.unref();
188
- if (portal)
189
- await portal.close();
190
- }
191
- }
192
- async _close() {
193
- if (--this._refCount > 0)
194
- return;
195
- const intoCon = (0, intl_connection_js_1.getIntlConnection)(this.connection);
196
- intoCon.ref();
197
- try {
198
- const socket = intoCon.socket;
199
- socket.sendCloseMessage({ type: 'S', name: this.name });
200
- socket.sendSyncMessage();
201
- await socket.capture(async (code, msg, done) => {
202
- switch (code) {
203
- case protocol_js_1.Protocol.BackendMessageCode.NoticeResponse:
204
- this.emit('notice', msg);
205
- break;
206
- case protocol_js_1.Protocol.BackendMessageCode.CloseComplete:
207
- break;
208
- case protocol_js_1.Protocol.BackendMessageCode.ReadyForQuery:
209
- intoCon.transactionStatus = msg.status;
210
- done();
211
- break;
212
- default:
213
- done(new Error(`Server returned unexpected response message (0x${code.toString(16)})`));
214
- }
215
- });
216
- }
217
- finally {
218
- intoCon.unref();
219
- }
220
- this.emit('close');
221
- }
222
- [Symbol.asyncDispose]() {
223
- return this.close();
224
- }
225
- }
226
- exports.PreparedStatement = PreparedStatement;
package/cjs/constants.js DELETED
@@ -1,249 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DataTypeNames = exports.DataTypeOIDs = exports.ConnectionState = exports.DEFAULT_COLUMN_FORMAT = exports.DataFormat = void 0;
4
- const protocol_js_1 = require("./protocol/protocol.js");
5
- var DataFormat = protocol_js_1.Protocol.DataFormat;
6
- exports.DataFormat = DataFormat;
7
- // @ts-ignore
8
- Symbol.asyncDispose ?? (Symbol.asyncDispose = Symbol('Symbol.asyncDispose'));
9
- exports.DEFAULT_COLUMN_FORMAT = DataFormat.binary;
10
- var ConnectionState;
11
- (function (ConnectionState) {
12
- ConnectionState[ConnectionState["CLOSED"] = 0] = "CLOSED";
13
- ConnectionState[ConnectionState["CONNECTING"] = 1] = "CONNECTING";
14
- ConnectionState[ConnectionState["AUTHORIZING"] = 3] = "AUTHORIZING";
15
- ConnectionState[ConnectionState["READY"] = 2] = "READY";
16
- ConnectionState[ConnectionState["CLOSING"] = 10] = "CLOSING";
17
- })(ConnectionState || (exports.ConnectionState = ConnectionState = {}));
18
- exports.DataTypeOIDs = {
19
- bool: 16,
20
- bytea: 17,
21
- char: 18,
22
- name: 19,
23
- int8: 20,
24
- int2: 21,
25
- int2vector: 22,
26
- int4: 23,
27
- regproc: 24,
28
- text: 25,
29
- oid: 26,
30
- tid: 27,
31
- xid: 28,
32
- cid: 29,
33
- oidvector: 30,
34
- json: 114,
35
- xml: 142,
36
- point: 600,
37
- lseg: 601,
38
- path: 602,
39
- box: 603,
40
- polygon: 604,
41
- line: 628,
42
- cidr: 650,
43
- float4: 700,
44
- float8: 701,
45
- unknown: 705,
46
- circle: 718,
47
- macaddr8: 774,
48
- money: 790,
49
- macaddr: 829,
50
- inet: 869,
51
- bpchar: 1042,
52
- varchar: 1043,
53
- date: 1082,
54
- time: 1083,
55
- timestamp: 1114,
56
- timestamptz: 1184,
57
- interval: 1186,
58
- timetz: 1266,
59
- bit: 1560,
60
- varbit: 1562,
61
- numeric: 1700,
62
- refcursor: 1790,
63
- regprocedure: 2202,
64
- regoper: 2203,
65
- regoperator: 2204,
66
- regclass: 2205,
67
- regtype: 2206,
68
- record: 2249,
69
- cstring: 2275,
70
- any: 2276,
71
- anyarray: 2277,
72
- void: 2278,
73
- trigger: 2279,
74
- language_handler: 2280,
75
- internal: 2281,
76
- anyelement: 2283,
77
- anynonarray: 2776,
78
- uuid: 2950,
79
- jsonb: 3802,
80
- anyrange: 3831,
81
- int4range: 3904,
82
- numrange: 3906,
83
- tsrange: 3908,
84
- rstzrange: 3910,
85
- daterange: 3912,
86
- int8range: 3926,
87
- _xml: 143,
88
- _json: 199,
89
- _xid8: 271,
90
- _line: 629,
91
- _cidr: 651,
92
- _circle: 719,
93
- _macaddr8: 775,
94
- _money: 791,
95
- _bool: 1000,
96
- _bytea: 1001,
97
- _char: 1002,
98
- _name: 1003,
99
- _int2: 1005,
100
- _int2vector: 1006,
101
- _int4: 1007,
102
- _regproc: 1008,
103
- _text: 1009,
104
- _tid: 1010,
105
- _xid: 1011,
106
- _cid: 1012,
107
- _oidvector: 1013,
108
- _bpchar: 1014,
109
- _varchar: 1015,
110
- _int8: 1016,
111
- _point: 1017,
112
- _lseg: 1018,
113
- _path: 1019,
114
- _box: 1020,
115
- _float4: 1021,
116
- _float8: 1022,
117
- _polygon: 1027,
118
- _oid: 1028,
119
- _macaddr: 1040,
120
- _inet: 1041,
121
- _timestamp: 1115,
122
- _date: 1182,
123
- _time: 1183,
124
- _timestamptz: 1185,
125
- _interval: 1187,
126
- _numeric: 1231,
127
- _cstring: 1263,
128
- _timetz: 1270,
129
- _bit: 1561,
130
- _varbit: 1563,
131
- _uuid: 2951,
132
- _jsonb: 3807,
133
- };
134
- exports.DataTypeNames = {
135
- [exports.DataTypeOIDs.bool]: 'bool',
136
- [exports.DataTypeOIDs.bytea]: 'bytea',
137
- [exports.DataTypeOIDs.char]: 'char',
138
- [exports.DataTypeOIDs.name]: 'name',
139
- [exports.DataTypeOIDs.int8]: 'int8',
140
- [exports.DataTypeOIDs.int2]: 'int2',
141
- [exports.DataTypeOIDs.int2vector]: 'int2vector',
142
- [exports.DataTypeOIDs.int4]: 'int4',
143
- [exports.DataTypeOIDs.regproc]: 'regproc',
144
- [exports.DataTypeOIDs.text]: 'text',
145
- [exports.DataTypeOIDs.oid]: 'oid',
146
- [exports.DataTypeOIDs.tid]: 'tid',
147
- [exports.DataTypeOIDs.xid]: 'xid',
148
- [exports.DataTypeOIDs.cid]: 'cid',
149
- [exports.DataTypeOIDs.oidvector]: 'oidvector',
150
- [exports.DataTypeOIDs.json]: 'json',
151
- [exports.DataTypeOIDs.xml]: 'xml',
152
- [exports.DataTypeOIDs.point]: 'point',
153
- [exports.DataTypeOIDs.lseg]: 'lseg',
154
- [exports.DataTypeOIDs.path]: 'path',
155
- [exports.DataTypeOIDs.box]: 'box',
156
- [exports.DataTypeOIDs.polygon]: 'polygon',
157
- [exports.DataTypeOIDs.line]: 'line',
158
- [exports.DataTypeOIDs.cidr]: 'cidr',
159
- [exports.DataTypeOIDs.float4]: 'float4',
160
- [exports.DataTypeOIDs.float8]: 'float8',
161
- [exports.DataTypeOIDs.unknown]: 'unknown',
162
- [exports.DataTypeOIDs.circle]: 'circle',
163
- [exports.DataTypeOIDs.macaddr8]: 'macaddr8',
164
- [exports.DataTypeOIDs.money]: 'money',
165
- [exports.DataTypeOIDs.macaddr]: 'macaddr',
166
- [exports.DataTypeOIDs.inet]: 'inet',
167
- [exports.DataTypeOIDs.bpchar]: 'bpchar',
168
- [exports.DataTypeOIDs.varchar]: 'varchar',
169
- [exports.DataTypeOIDs.date]: 'date',
170
- [exports.DataTypeOIDs.time]: 'time',
171
- [exports.DataTypeOIDs.timestamp]: 'timestamp',
172
- [exports.DataTypeOIDs.timestamptz]: 'timestamptz',
173
- [exports.DataTypeOIDs.interval]: 'interval',
174
- [exports.DataTypeOIDs.timetz]: 'timetz',
175
- [exports.DataTypeOIDs.bit]: 'bit',
176
- [exports.DataTypeOIDs.varbit]: 'varbit',
177
- [exports.DataTypeOIDs.numeric]: 'numeric',
178
- [exports.DataTypeOIDs.refcursor]: 'refcursor',
179
- [exports.DataTypeOIDs.regprocedure]: 'regprocedure',
180
- [exports.DataTypeOIDs.regoper]: 'regoper',
181
- [exports.DataTypeOIDs.regoperator]: 'regoperator',
182
- [exports.DataTypeOIDs.regclass]: 'regclass',
183
- [exports.DataTypeOIDs.regtype]: 'regtype',
184
- [exports.DataTypeOIDs.record]: 'record',
185
- [exports.DataTypeOIDs.cstring]: 'cstring',
186
- [exports.DataTypeOIDs.any]: 'any',
187
- [exports.DataTypeOIDs.anyarray]: 'anyarray',
188
- [exports.DataTypeOIDs.void]: 'void',
189
- [exports.DataTypeOIDs.trigger]: 'trigger',
190
- [exports.DataTypeOIDs.language_handler]: 'language_handler',
191
- [exports.DataTypeOIDs.internal]: 'internal',
192
- [exports.DataTypeOIDs.anyelement]: 'anyelement',
193
- [exports.DataTypeOIDs.anynonarray]: 'anynonarray',
194
- [exports.DataTypeOIDs.uuid]: 'uuid',
195
- [exports.DataTypeOIDs.jsonb]: 'jsonb',
196
- [exports.DataTypeOIDs.anyrange]: 'anyrange',
197
- [exports.DataTypeOIDs.int4range]: 'int4range',
198
- [exports.DataTypeOIDs.numrange]: 'numrange',
199
- [exports.DataTypeOIDs.tsrange]: 'tsrange',
200
- [exports.DataTypeOIDs.rstzrange]: 'rstzrange',
201
- [exports.DataTypeOIDs.daterange]: 'daterange',
202
- [exports.DataTypeOIDs.int8range]: 'int8range',
203
- [exports.DataTypeOIDs._xml]: '_xml',
204
- [exports.DataTypeOIDs._json]: '_json',
205
- [exports.DataTypeOIDs._xid8]: '_xid8',
206
- [exports.DataTypeOIDs._line]: '_line',
207
- [exports.DataTypeOIDs._cidr]: '_cidr',
208
- [exports.DataTypeOIDs._circle]: '_circle',
209
- [exports.DataTypeOIDs._macaddr8]: '_macaddr8',
210
- [exports.DataTypeOIDs._money]: '_money',
211
- [exports.DataTypeOIDs._bool]: '_bool',
212
- [exports.DataTypeOIDs._bytea]: '_bytea',
213
- [exports.DataTypeOIDs._char]: '_char',
214
- [exports.DataTypeOIDs._name]: '_name',
215
- [exports.DataTypeOIDs._int2]: '_int2',
216
- [exports.DataTypeOIDs._int2vector]: '_int2vector',
217
- [exports.DataTypeOIDs._int4]: '_int4',
218
- [exports.DataTypeOIDs._regproc]: '_regproc',
219
- [exports.DataTypeOIDs._text]: '_text',
220
- [exports.DataTypeOIDs._tid]: '_tid',
221
- [exports.DataTypeOIDs._xid]: '_xid',
222
- [exports.DataTypeOIDs._cid]: '_cid',
223
- [exports.DataTypeOIDs._oidvector]: '_oidvector',
224
- [exports.DataTypeOIDs._bpchar]: '_bpchar',
225
- [exports.DataTypeOIDs._varchar]: '_varchar',
226
- [exports.DataTypeOIDs._int8]: '_int8',
227
- [exports.DataTypeOIDs._point]: '_point',
228
- [exports.DataTypeOIDs._lseg]: '_lseg',
229
- [exports.DataTypeOIDs._path]: '_path',
230
- [exports.DataTypeOIDs._box]: '_box',
231
- [exports.DataTypeOIDs._float4]: '_float4',
232
- [exports.DataTypeOIDs._float8]: '_float8',
233
- [exports.DataTypeOIDs._polygon]: '_polygon',
234
- [exports.DataTypeOIDs._oid]: '_oid',
235
- [exports.DataTypeOIDs._macaddr]: '_macaddr',
236
- [exports.DataTypeOIDs._inet]: '_inet',
237
- [exports.DataTypeOIDs._timestamp]: '_timestamp',
238
- [exports.DataTypeOIDs._date]: '_date',
239
- [exports.DataTypeOIDs._time]: '_time',
240
- [exports.DataTypeOIDs._timestamptz]: '_timestamptz',
241
- [exports.DataTypeOIDs._interval]: '_interval',
242
- [exports.DataTypeOIDs._numeric]: '_numeric',
243
- [exports.DataTypeOIDs._cstring]: '_cstring',
244
- [exports.DataTypeOIDs._timetz]: '_timetz',
245
- [exports.DataTypeOIDs._bit]: '_bit',
246
- [exports.DataTypeOIDs._varbit]: '_varbit',
247
- [exports.DataTypeOIDs._uuid]: '_uuid',
248
- [exports.DataTypeOIDs._jsonb]: '_jsonb',
249
- };