node-firebird-driver 2.4.0 → 3.0.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.
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.runCommonTests = void 0;
13
4
  const lib_1 = require("../lib");
@@ -51,9 +42,8 @@ function runCommonTests(client) {
51
42
  testConfig.host == '127.0.0.1';
52
43
  }
53
44
  function getTempFile(name) {
54
- var _a;
55
45
  const database = `${testConfig.tmpDir}/${name}`;
56
- return ((_a = testConfig.host) !== null && _a !== void 0 ? _a : '') +
46
+ return (testConfig.host ?? '') +
57
47
  (testConfig.host && testConfig.port ? `/${testConfig.port}` : '') +
58
48
  (testConfig.host ? ':' : '') +
59
49
  database;
@@ -70,63 +60,68 @@ function runCommonTests(client) {
70
60
  password: testConfig.password,
71
61
  username: testConfig.username
72
62
  };
73
- client.defaultCreateDatabaseOptions = Object.assign({ forcedWrite: false }, defaultOptions);
74
- client.defaultConnectOptions = Object.assign({}, defaultOptions);
63
+ client.defaultCreateDatabaseOptions = {
64
+ forcedWrite: false,
65
+ ...defaultOptions
66
+ };
67
+ client.defaultConnectOptions = {
68
+ ...defaultOptions
69
+ };
75
70
  });
76
- afterAll(() => __awaiter(this, void 0, void 0, function* () {
77
- yield client.dispose();
71
+ afterAll(async () => {
72
+ await client.dispose();
78
73
  expect(client.isValid).toBeFalsy();
79
74
  if (isLocal())
80
75
  fs.rmdirSync(testConfig.tmpDir);
81
- }));
76
+ });
82
77
  describe('Client', () => {
83
- test('#createDatabase()', () => __awaiter(this, void 0, void 0, function* () {
84
- const attachment = yield client.createDatabase(getTempFile('Client-createDatabase.fdb'));
85
- yield attachment.dropDatabase();
86
- }));
87
- test('#connect()', () => __awaiter(this, void 0, void 0, function* () {
78
+ test('#createDatabase()', async () => {
79
+ const attachment = await client.createDatabase(getTempFile('Client-createDatabase.fdb'));
80
+ await attachment.dropDatabase();
81
+ });
82
+ test('#connect()', async () => {
88
83
  const filename = getTempFile('Client-connect.fdb');
89
- const attachment1 = yield client.createDatabase(filename);
90
- const attachment2 = yield client.connect(filename);
84
+ const attachment1 = await client.createDatabase(filename);
85
+ const attachment2 = await client.connect(filename);
91
86
  expect(attachment1.isValid).toBeTruthy();
92
87
  expect(attachment2.isValid).toBeTruthy();
93
- yield attachment2.disconnect();
94
- yield attachment1.dropDatabase();
88
+ await attachment2.disconnect();
89
+ await attachment1.dropDatabase();
95
90
  expect(attachment1.isValid).toBeFalsy();
96
91
  expect(attachment2.isValid).toBeFalsy();
97
- }));
92
+ });
98
93
  });
99
94
  describe('Attachment', () => {
100
- test('#startTransaction()', () => __awaiter(this, void 0, void 0, function* () {
101
- const attachment = yield client.createDatabase(getTempFile('Attachment-startTransaction.fdb'));
95
+ test('#startTransaction()', async () => {
96
+ const attachment = await client.createDatabase(getTempFile('Attachment-startTransaction.fdb'));
102
97
  const isolationQuery = 'select rdb$get_context(\'SYSTEM\', \'ISOLATION_LEVEL\') from rdb$database';
103
- const transaction1 = yield attachment.startTransaction();
98
+ const transaction1 = await attachment.startTransaction();
104
99
  expect(transaction1.isValid).toBeTruthy();
105
- expect((yield attachment.executeSingleton(transaction1, isolationQuery))[0]).toBe('SNAPSHOT');
106
- yield transaction1.commit();
100
+ expect((await attachment.executeSingleton(transaction1, isolationQuery))[0]).toBe('SNAPSHOT');
101
+ await transaction1.commit();
107
102
  expect(transaction1.isValid).toBeFalsy();
108
- const transaction2 = yield attachment.startTransaction({ isolation: lib_1.TransactionIsolation.READ_COMMITTED });
103
+ const transaction2 = await attachment.startTransaction({ isolation: lib_1.TransactionIsolation.READ_COMMITTED });
109
104
  expect(transaction2.isValid).toBeTruthy();
110
- expect((yield attachment.executeSingleton(transaction2, isolationQuery))[0]).toBe('READ COMMITTED');
111
- yield transaction2.commit();
105
+ expect((await attachment.executeSingleton(transaction2, isolationQuery))[0]).toBe('READ COMMITTED');
106
+ await transaction2.commit();
112
107
  expect(transaction2.isValid).toBeFalsy();
113
- const transaction3 = yield attachment.startTransaction({ isolation: lib_1.TransactionIsolation.CONSISTENCY });
108
+ const transaction3 = await attachment.startTransaction({ isolation: lib_1.TransactionIsolation.CONSISTENCY });
114
109
  expect(transaction3.isValid).toBeTruthy();
115
- expect((yield attachment.executeSingleton(transaction3, isolationQuery))[0]).toBe('CONSISTENCY');
116
- yield transaction3.commit();
110
+ expect((await attachment.executeSingleton(transaction3, isolationQuery))[0]).toBe('CONSISTENCY');
111
+ await transaction3.commit();
117
112
  expect(transaction3.isValid).toBeFalsy();
118
- yield attachment.dropDatabase();
119
- }));
120
- test('#prepare()', () => __awaiter(this, void 0, void 0, function* () {
121
- const attachment = yield client.createDatabase(getTempFile('Attachment-prepare.fdb'));
122
- const transaction = yield attachment.startTransaction();
123
- const statement = yield attachment.prepare(transaction, 'create table t1 (n1 integer)');
113
+ await attachment.dropDatabase();
114
+ });
115
+ test('#prepare()', async () => {
116
+ const attachment = await client.createDatabase(getTempFile('Attachment-prepare.fdb'));
117
+ const transaction = await attachment.startTransaction();
118
+ const statement = await attachment.prepare(transaction, 'create table t1 (n1 integer)');
124
119
  expect(statement.isValid).toBeTruthy();
125
- yield statement.dispose();
120
+ await statement.dispose();
126
121
  expect(statement.isValid).toBeFalsy();
127
122
  let error;
128
123
  try {
129
- yield attachment.prepare(transaction, 'create select t1 (n1 integer)');
124
+ await attachment.prepare(transaction, 'create select t1 (n1 integer)');
130
125
  }
131
126
  catch (e) {
132
127
  error = e;
@@ -136,75 +131,75 @@ function runCommonTests(client) {
136
131
  '-select');
137
132
  }
138
133
  expect(error).toBeTruthy();
139
- yield transaction.commit();
140
- yield attachment.dropDatabase();
141
- }));
134
+ await transaction.commit();
135
+ await attachment.dropDatabase();
136
+ });
142
137
  //// TODO: #executeTransaction
143
- test('#execute()', () => __awaiter(this, void 0, void 0, function* () {
144
- const attachment = yield client.createDatabase(getTempFile('Attachment-execute.fdb'));
145
- const transaction = yield attachment.startTransaction();
146
- yield attachment.execute(transaction, 'create table t1 (n1 integer)');
147
- yield transaction.commitRetaining();
148
- yield attachment.execute(transaction, 'insert into t1 (n1) values (1)');
149
- yield transaction.commit();
150
- yield attachment.dropDatabase();
151
- }));
152
- test('#executeQuery()', () => __awaiter(this, void 0, void 0, function* () {
153
- const attachment = yield client.createDatabase(getTempFile('Attachment-executeQuery.fdb'));
154
- const transaction = yield attachment.startTransaction();
155
- yield attachment.execute(transaction, 'create table t1 (n1 integer)');
156
- yield transaction.commitRetaining();
157
- const resultSet = yield attachment.executeQuery(transaction, 'select n1 from t1');
138
+ test('#execute()', async () => {
139
+ const attachment = await client.createDatabase(getTempFile('Attachment-execute.fdb'));
140
+ const transaction = await attachment.startTransaction();
141
+ await attachment.execute(transaction, 'create table t1 (n1 integer)');
142
+ await transaction.commitRetaining();
143
+ await attachment.execute(transaction, 'insert into t1 (n1) values (1)');
144
+ await transaction.commit();
145
+ await attachment.dropDatabase();
146
+ });
147
+ test('#executeQuery()', async () => {
148
+ const attachment = await client.createDatabase(getTempFile('Attachment-executeQuery.fdb'));
149
+ const transaction = await attachment.startTransaction();
150
+ await attachment.execute(transaction, 'create table t1 (n1 integer)');
151
+ await transaction.commitRetaining();
152
+ const resultSet = await attachment.executeQuery(transaction, 'select n1 from t1');
158
153
  expect(resultSet.isValid).toBeTruthy();
159
- yield resultSet.close();
154
+ await resultSet.close();
160
155
  expect(resultSet.isValid).toBeFalsy();
161
- yield transaction.commit();
162
- yield attachment.dropDatabase();
163
- }));
164
- test('#executeSingleton()', () => __awaiter(this, void 0, void 0, function* () {
165
- const attachment = yield client.createDatabase(getTempFile('Attachment-executeSingleton.fdb'));
166
- const transaction = yield attachment.startTransaction();
167
- yield attachment.execute(transaction, 'create table t1 (n1 integer)');
168
- yield transaction.commitRetaining();
169
- const result = yield attachment.executeSingleton(transaction, 'insert into t1 values (11) returning n1');
156
+ await transaction.commit();
157
+ await attachment.dropDatabase();
158
+ });
159
+ test('#executeSingleton()', async () => {
160
+ const attachment = await client.createDatabase(getTempFile('Attachment-executeSingleton.fdb'));
161
+ const transaction = await attachment.startTransaction();
162
+ await attachment.execute(transaction, 'create table t1 (n1 integer)');
163
+ await transaction.commitRetaining();
164
+ const result = await attachment.executeSingleton(transaction, 'insert into t1 values (11) returning n1');
170
165
  expect(result.length).toBe(1);
171
166
  expect(result[0]).toBe(11);
172
- yield transaction.commit();
173
- yield attachment.dropDatabase();
174
- }));
175
- test('#executeSingletonAsObject()', () => __awaiter(this, void 0, void 0, function* () {
176
- const attachment = yield client.createDatabase(getTempFile('Attachment-executeSingletonAsObject.fdb'));
177
- const transaction = yield attachment.startTransaction();
178
- yield attachment.execute(transaction, 'create table t1 (n1 integer)');
179
- yield transaction.commitRetaining();
180
- const output = yield attachment.executeSingletonAsObject(transaction, 'insert into t1 values (11) returning n1');
167
+ await transaction.commit();
168
+ await attachment.dropDatabase();
169
+ });
170
+ test('#executeSingletonAsObject()', async () => {
171
+ const attachment = await client.createDatabase(getTempFile('Attachment-executeSingletonAsObject.fdb'));
172
+ const transaction = await attachment.startTransaction();
173
+ await attachment.execute(transaction, 'create table t1 (n1 integer)');
174
+ await transaction.commitRetaining();
175
+ const output = await attachment.executeSingletonAsObject(transaction, 'insert into t1 values (11) returning n1');
181
176
  expect(output.N1).toBe(11);
182
- yield transaction.commit();
183
- yield attachment.dropDatabase();
184
- }));
185
- test('#executeReturning()', () => __awaiter(this, void 0, void 0, function* () {
186
- const attachment = yield client.createDatabase(getTempFile('Attachment-executeReturning.fdb'));
187
- const transaction = yield attachment.startTransaction();
188
- yield attachment.execute(transaction, 'create table t1 (n1 integer)');
189
- yield transaction.commitRetaining();
190
- const result = yield attachment.executeReturning(transaction, 'insert into t1 values (11) returning n1');
177
+ await transaction.commit();
178
+ await attachment.dropDatabase();
179
+ });
180
+ test('#executeReturning()', async () => {
181
+ const attachment = await client.createDatabase(getTempFile('Attachment-executeReturning.fdb'));
182
+ const transaction = await attachment.startTransaction();
183
+ await attachment.execute(transaction, 'create table t1 (n1 integer)');
184
+ await transaction.commitRetaining();
185
+ const result = await attachment.executeReturning(transaction, 'insert into t1 values (11) returning n1');
191
186
  expect(result.length).toBe(1);
192
187
  expect(result[0]).toBe(11);
193
- yield transaction.commit();
194
- yield attachment.dropDatabase();
195
- }));
196
- test('#executeReturningAsObject()', () => __awaiter(this, void 0, void 0, function* () {
197
- const attachment = yield client.createDatabase(getTempFile('Attachment-executeReturningAsObject.fdb'));
198
- const transaction = yield attachment.startTransaction();
199
- yield attachment.execute(transaction, 'create table t1 (n1 integer)');
200
- yield transaction.commitRetaining();
201
- const output = yield attachment.executeReturningAsObject(transaction, 'insert into t1 values (11) returning n1');
188
+ await transaction.commit();
189
+ await attachment.dropDatabase();
190
+ });
191
+ test('#executeReturningAsObject()', async () => {
192
+ const attachment = await client.createDatabase(getTempFile('Attachment-executeReturningAsObject.fdb'));
193
+ const transaction = await attachment.startTransaction();
194
+ await attachment.execute(transaction, 'create table t1 (n1 integer)');
195
+ await transaction.commitRetaining();
196
+ const output = await attachment.executeReturningAsObject(transaction, 'insert into t1 values (11) returning n1');
202
197
  expect(output.N1).toBe(11);
203
- yield transaction.commit();
204
- yield attachment.dropDatabase();
205
- }));
206
- test('#queueEvents()', () => __awaiter(this, void 0, void 0, function* () {
207
- const attachment = yield client.createDatabase(getTempFile('Attachment-queueEvents.fdb'));
198
+ await transaction.commit();
199
+ await attachment.dropDatabase();
200
+ });
201
+ test('#queueEvents()', async () => {
202
+ const attachment = await client.createDatabase(getTempFile('Attachment-queueEvents.fdb'));
208
203
  const eventNames = [
209
204
  ['EVENT1', 16],
210
205
  ['EVENT2', 8]
@@ -217,10 +212,10 @@ function runCommonTests(client) {
217
212
  count: 0,
218
213
  promise: new Promise(resolve => resolver = resolve)
219
214
  };
220
- return Object.assign(Object.assign({}, obj), { resolver });
215
+ return { ...obj, resolver };
221
216
  });
222
217
  const eventsMap = new Map(eventsObj.map(ev => [ev.name, ev]));
223
- const eventHandler = (counters) => __awaiter(this, void 0, void 0, function* () {
218
+ const eventHandler = async (counters) => {
224
219
  counters.forEach(([name, count]) => {
225
220
  const obj = eventsMap.get(name);
226
221
  const newCount = obj.count + count;
@@ -230,19 +225,19 @@ function runCommonTests(client) {
230
225
  });
231
226
  if (Array.from(eventsMap.values()).every(obj => obj.count >= obj.expected)) {
232
227
  if (events) {
233
- yield events.cancel();
228
+ await events.cancel();
234
229
  expect(events.isValid).toBeFalsy();
235
230
  events = null;
236
231
  }
237
232
  }
238
- });
239
- let events = yield attachment.queueEvents(Array.from(eventsMap.keys()), eventHandler);
240
- const transaction = yield attachment.startTransaction();
233
+ };
234
+ let events = await attachment.queueEvents(Array.from(eventsMap.keys()), eventHandler);
235
+ const transaction = await attachment.startTransaction();
241
236
  try {
242
237
  // Iterate more times than the neccessary so that
243
238
  // eventHandler may have a chance to cancel the events.
244
239
  for (let i = 0; i < 20; ++i) {
245
- yield attachment.execute(transaction, `
240
+ await attachment.execute(transaction, `
246
241
  execute block as
247
242
  begin
248
243
  post_event 'EVENT1';
@@ -253,167 +248,167 @@ function runCommonTests(client) {
253
248
  `);
254
249
  // Commit retaining to test internal event rescheduling
255
250
  // after each handler dispatch.
256
- yield transaction.commitRetaining();
251
+ await transaction.commitRetaining();
257
252
  expect(transaction.isValid).toBeTruthy();
258
253
  }
259
254
  }
260
255
  finally {
261
- yield transaction.commit();
256
+ await transaction.commit();
262
257
  expect(transaction.isValid).toBeFalsy();
263
258
  }
264
- yield Promise.all(eventsObj.map(ev => ev.promise));
259
+ await Promise.all(eventsObj.map(ev => ev.promise));
265
260
  if (events)
266
- yield events.cancel();
261
+ await events.cancel();
267
262
  eventsObj.forEach(ev => expect(ev.count).toBeGreaterThanOrEqual(ev.expected));
268
- yield attachment.dropDatabase();
269
- }));
263
+ await attachment.dropDatabase();
264
+ });
270
265
  });
271
266
  describe('Transaction', () => {
272
- test('#commit()', () => __awaiter(this, void 0, void 0, function* () {
273
- const attachment = yield client.createDatabase(getTempFile('Transaction-commit.fdb'));
274
- const transaction = yield attachment.startTransaction();
275
- yield transaction.commit();
276
- yield attachment.dropDatabase();
277
- }));
278
- test('#commitRetaining()', () => __awaiter(this, void 0, void 0, function* () {
279
- const attachment = yield client.createDatabase(getTempFile('Transaction-commitRetaining.fdb'));
280
- const transaction = yield attachment.startTransaction();
281
- yield transaction.commitRetaining();
282
- yield transaction.commit();
283
- yield attachment.dropDatabase();
284
- }));
285
- test('#rollback()', () => __awaiter(this, void 0, void 0, function* () {
286
- const attachment = yield client.createDatabase(getTempFile('Transaction-rollback.fdb'));
287
- const transaction = yield attachment.startTransaction();
288
- yield transaction.rollback();
289
- yield attachment.dropDatabase();
290
- }));
291
- test('#rollbackRetaining()', () => __awaiter(this, void 0, void 0, function* () {
292
- const attachment = yield client.createDatabase(getTempFile('Transaction-rollbackRetaining.fdb'));
293
- const transaction = yield attachment.startTransaction();
294
- yield transaction.rollbackRetaining();
295
- yield transaction.rollback();
296
- yield attachment.dropDatabase();
297
- }));
298
- test('transaction left opened', () => __awaiter(this, void 0, void 0, function* () {
299
- const attachment = yield client.createDatabase(getTempFile('Transaction-left-opened.fdb'));
300
- yield attachment.startTransaction();
301
- yield attachment.dropDatabase();
302
- }));
267
+ test('#commit()', async () => {
268
+ const attachment = await client.createDatabase(getTempFile('Transaction-commit.fdb'));
269
+ const transaction = await attachment.startTransaction();
270
+ await transaction.commit();
271
+ await attachment.dropDatabase();
272
+ });
273
+ test('#commitRetaining()', async () => {
274
+ const attachment = await client.createDatabase(getTempFile('Transaction-commitRetaining.fdb'));
275
+ const transaction = await attachment.startTransaction();
276
+ await transaction.commitRetaining();
277
+ await transaction.commit();
278
+ await attachment.dropDatabase();
279
+ });
280
+ test('#rollback()', async () => {
281
+ const attachment = await client.createDatabase(getTempFile('Transaction-rollback.fdb'));
282
+ const transaction = await attachment.startTransaction();
283
+ await transaction.rollback();
284
+ await attachment.dropDatabase();
285
+ });
286
+ test('#rollbackRetaining()', async () => {
287
+ const attachment = await client.createDatabase(getTempFile('Transaction-rollbackRetaining.fdb'));
288
+ const transaction = await attachment.startTransaction();
289
+ await transaction.rollbackRetaining();
290
+ await transaction.rollback();
291
+ await attachment.dropDatabase();
292
+ });
293
+ test('transaction left opened', async () => {
294
+ const attachment = await client.createDatabase(getTempFile('Transaction-left-opened.fdb'));
295
+ await attachment.startTransaction();
296
+ await attachment.dropDatabase();
297
+ });
303
298
  });
304
299
  describe('Statement', () => {
305
- test('#execute()', () => __awaiter(this, void 0, void 0, function* () {
306
- const attachment = yield client.createDatabase(getTempFile('Statement-execute.fdb'));
307
- const transaction = yield attachment.startTransaction();
308
- const statement1 = yield attachment.prepare(transaction, 'create table t1 (n1 integer)');
309
- yield statement1.execute(transaction);
310
- yield statement1.dispose();
311
- yield transaction.commitRetaining();
312
- const statement2 = yield attachment.prepare(transaction, 'insert into t1 (n1) values (?)');
313
- yield statement2.execute(transaction, [1]);
314
- yield statement2.execute(transaction, [null]);
315
- yield statement2.execute(transaction, [10]);
316
- yield statement2.execute(transaction, [100]);
300
+ test('#execute()', async () => {
301
+ const attachment = await client.createDatabase(getTempFile('Statement-execute.fdb'));
302
+ const transaction = await attachment.startTransaction();
303
+ const statement1 = await attachment.prepare(transaction, 'create table t1 (n1 integer)');
304
+ await statement1.execute(transaction);
305
+ await statement1.dispose();
306
+ await transaction.commitRetaining();
307
+ const statement2 = await attachment.prepare(transaction, 'insert into t1 (n1) values (?)');
308
+ await statement2.execute(transaction, [1]);
309
+ await statement2.execute(transaction, [null]);
310
+ await statement2.execute(transaction, [10]);
311
+ await statement2.execute(transaction, [100]);
317
312
  expect(statement2.isValid).toBeTruthy();
318
- yield statement2.dispose();
313
+ await statement2.dispose();
319
314
  expect(statement2.isValid).toBeFalsy();
320
- const rs = yield attachment.executeQuery(transaction, `select sum(n1) || ', ' || count(n1) || ', ' || count(*) ret from t1`);
321
- const ret = yield rs.fetchAsObject();
322
- yield rs.close();
315
+ const rs = await attachment.executeQuery(transaction, `select sum(n1) || ', ' || count(n1) || ', ' || count(*) ret from t1`);
316
+ const ret = await rs.fetchAsObject();
317
+ await rs.close();
323
318
  expect(ret[0].RET).toStrictEqual('111, 3, 4');
324
- yield transaction.commit();
325
- yield attachment.dropDatabase();
326
- }));
327
- test('#executeQuery()', () => __awaiter(this, void 0, void 0, function* () {
328
- const attachment = yield client.createDatabase(getTempFile('Statement-executeQuery.fdb'));
329
- const transaction = yield attachment.startTransaction();
330
- const statement1 = yield attachment.prepare(transaction, 'create table t1 (n1 integer)');
331
- yield statement1.execute(transaction);
332
- yield statement1.dispose();
333
- yield transaction.commitRetaining();
334
- const statement2 = yield attachment.prepare(transaction, 'select n1 from t1');
335
- const resultSet2 = yield statement2.executeQuery(transaction);
336
- yield resultSet2.close();
337
- yield statement2.dispose();
338
- yield transaction.commit();
339
- yield attachment.dropDatabase();
340
- }));
341
- test('#executeSingleton()', () => __awaiter(this, void 0, void 0, function* () {
342
- const attachment = yield client.createDatabase(getTempFile('Attachment-executeSingleton.fdb'));
343
- const transaction = yield attachment.startTransaction();
344
- yield attachment.execute(transaction, 'create table t1 (n1 integer)');
345
- yield transaction.commitRetaining();
346
- const statement = yield attachment.prepare(transaction, 'insert into t1 values (11) returning n1, n1 * 2');
347
- const result = yield statement.executeSingleton(transaction);
319
+ await transaction.commit();
320
+ await attachment.dropDatabase();
321
+ });
322
+ test('#executeQuery()', async () => {
323
+ const attachment = await client.createDatabase(getTempFile('Statement-executeQuery.fdb'));
324
+ const transaction = await attachment.startTransaction();
325
+ const statement1 = await attachment.prepare(transaction, 'create table t1 (n1 integer)');
326
+ await statement1.execute(transaction);
327
+ await statement1.dispose();
328
+ await transaction.commitRetaining();
329
+ const statement2 = await attachment.prepare(transaction, 'select n1 from t1');
330
+ const resultSet2 = await statement2.executeQuery(transaction);
331
+ await resultSet2.close();
332
+ await statement2.dispose();
333
+ await transaction.commit();
334
+ await attachment.dropDatabase();
335
+ });
336
+ test('#executeSingleton()', async () => {
337
+ const attachment = await client.createDatabase(getTempFile('Attachment-executeSingleton.fdb'));
338
+ const transaction = await attachment.startTransaction();
339
+ await attachment.execute(transaction, 'create table t1 (n1 integer)');
340
+ await transaction.commitRetaining();
341
+ const statement = await attachment.prepare(transaction, 'insert into t1 values (11) returning n1, n1 * 2');
342
+ const result = await statement.executeSingleton(transaction);
348
343
  expect(result.length).toBe(2);
349
344
  expect(result[0]).toBe(11);
350
345
  expect(result[1]).toBe(11 * 2);
351
- yield statement.dispose();
352
- yield transaction.commit();
353
- yield attachment.dropDatabase();
354
- }));
355
- test('#executeReturning()', () => __awaiter(this, void 0, void 0, function* () {
356
- const attachment = yield client.createDatabase(getTempFile('Attachment-executeReturning.fdb'));
357
- const transaction = yield attachment.startTransaction();
358
- yield attachment.execute(transaction, 'create table t1 (n1 integer)');
359
- yield transaction.commitRetaining();
360
- const statement = yield attachment.prepare(transaction, 'insert into t1 values (11) returning n1, n1 * 2');
361
- const result = yield statement.executeReturning(transaction);
346
+ await statement.dispose();
347
+ await transaction.commit();
348
+ await attachment.dropDatabase();
349
+ });
350
+ test('#executeReturning()', async () => {
351
+ const attachment = await client.createDatabase(getTempFile('Attachment-executeReturning.fdb'));
352
+ const transaction = await attachment.startTransaction();
353
+ await attachment.execute(transaction, 'create table t1 (n1 integer)');
354
+ await transaction.commitRetaining();
355
+ const statement = await attachment.prepare(transaction, 'insert into t1 values (11) returning n1, n1 * 2');
356
+ const result = await statement.executeReturning(transaction);
362
357
  expect(result.length).toBe(2);
363
358
  expect(result[0]).toBe(11);
364
359
  expect(result[1]).toBe(11 * 2);
365
- yield statement.dispose();
366
- yield transaction.commit();
367
- yield attachment.dropDatabase();
368
- }));
369
- test('#columnLabels()', () => __awaiter(this, void 0, void 0, function* () {
370
- const attachment = yield client.createDatabase(getTempFile('Statement-columnLabels.fdb'));
371
- const transaction = yield attachment.startTransaction();
372
- const statement1 = yield attachment.prepare(transaction, 'create table t1 (n1 integer)');
373
- expect(yield statement1.columnLabels).toStrictEqual([]);
374
- yield statement1.execute(transaction);
375
- yield statement1.dispose();
376
- yield transaction.commitRetaining();
377
- const statement2 = yield attachment.prepare(transaction, 'select n1, n1 x from t1');
378
- expect(yield statement2.columnLabels).toStrictEqual(['N1', 'X']);
379
- yield statement2.dispose();
380
- yield transaction.commit();
381
- yield attachment.dropDatabase();
382
- }));
383
- test('#hasResultSet()', () => __awaiter(this, void 0, void 0, function* () {
384
- const attachment = yield client.createDatabase(getTempFile('Statement-hasResultSet.fdb'));
385
- const transaction = yield attachment.startTransaction();
386
- const statement1 = yield attachment.prepare(transaction, 'create table t1 (n1 integer)');
360
+ await statement.dispose();
361
+ await transaction.commit();
362
+ await attachment.dropDatabase();
363
+ });
364
+ test('#columnLabels()', async () => {
365
+ const attachment = await client.createDatabase(getTempFile('Statement-columnLabels.fdb'));
366
+ const transaction = await attachment.startTransaction();
367
+ const statement1 = await attachment.prepare(transaction, 'create table t1 (n1 integer)');
368
+ expect(await statement1.columnLabels).toStrictEqual([]);
369
+ await statement1.execute(transaction);
370
+ await statement1.dispose();
371
+ await transaction.commitRetaining();
372
+ const statement2 = await attachment.prepare(transaction, 'select n1, n1 x from t1');
373
+ expect(await statement2.columnLabels).toStrictEqual(['N1', 'X']);
374
+ await statement2.dispose();
375
+ await transaction.commit();
376
+ await attachment.dropDatabase();
377
+ });
378
+ test('#hasResultSet()', async () => {
379
+ const attachment = await client.createDatabase(getTempFile('Statement-hasResultSet.fdb'));
380
+ const transaction = await attachment.startTransaction();
381
+ const statement1 = await attachment.prepare(transaction, 'create table t1 (n1 integer)');
387
382
  expect(statement1.hasResultSet).toBe(false);
388
- yield statement1.execute(transaction);
389
- yield statement1.dispose();
390
- yield transaction.commitRetaining();
391
- const statement2 = yield attachment.prepare(transaction, 'insert into t1 values (1)');
383
+ await statement1.execute(transaction);
384
+ await statement1.dispose();
385
+ await transaction.commitRetaining();
386
+ const statement2 = await attachment.prepare(transaction, 'insert into t1 values (1)');
392
387
  expect(statement2.hasResultSet).toBe(false);
393
- yield statement2.dispose();
394
- const statement3 = yield attachment.prepare(transaction, 'insert into t1 values (1) returning *');
388
+ await statement2.dispose();
389
+ const statement3 = await attachment.prepare(transaction, 'insert into t1 values (1) returning *');
395
390
  expect(statement3.hasResultSet).toBe(false);
396
- yield statement3.dispose();
397
- const statement4 = yield attachment.prepare(transaction, 'execute block as begin end');
391
+ await statement3.dispose();
392
+ const statement4 = await attachment.prepare(transaction, 'execute block as begin end');
398
393
  expect(statement4.hasResultSet).toBe(false);
399
- yield statement4.dispose();
400
- const statement5 = yield attachment.prepare(transaction, 'select * from t1');
394
+ await statement4.dispose();
395
+ const statement5 = await attachment.prepare(transaction, 'select * from t1');
401
396
  expect(statement5.hasResultSet).toBe(true);
402
- yield statement5.dispose();
403
- const statement6 = yield attachment.prepare(transaction, 'execute block returns (n integer) as begin suspend; end');
397
+ await statement5.dispose();
398
+ const statement6 = await attachment.prepare(transaction, 'execute block returns (n integer) as begin suspend; end');
404
399
  expect(statement6.hasResultSet).toBe(true);
405
- yield statement6.dispose();
406
- const statement7 = yield attachment.prepare(transaction, 'execute block returns (n integer) as begin end');
400
+ await statement6.dispose();
401
+ const statement7 = await attachment.prepare(transaction, 'execute block returns (n integer) as begin end');
407
402
  expect(statement7.hasResultSet).toBe(true);
408
- yield statement7.dispose();
409
- yield transaction.commit();
410
- yield attachment.dropDatabase();
411
- }));
403
+ await statement7.dispose();
404
+ await transaction.commit();
405
+ await attachment.dropDatabase();
406
+ });
412
407
  });
413
408
  describe('ResultSet', () => {
414
- test('#fetch()', () => __awaiter(this, void 0, void 0, function* () {
415
- const attachment = yield client.createDatabase(getTempFile('ResultSet-fetch.fdb'));
416
- let transaction = yield attachment.startTransaction();
409
+ test('#fetch()', async () => {
410
+ const attachment = await client.createDatabase(getTempFile('ResultSet-fetch.fdb'));
411
+ let transaction = await attachment.startTransaction();
417
412
  const blobBuffer = Buffer.alloc(11, '12345678á9');
418
413
  const fields = [
419
414
  { name: 'x_short', type: 'numeric(2)', valToStr: (v) => v },
@@ -459,22 +454,22 @@ function runCommonTests(client) {
459
454
  { name: 'x_blob1', type: 'blob', valToStr: (v) => `'${v.toString()}'` },
460
455
  { name: 'x_blob2', type: 'blob', valToStr: () => `'${blobBuffer.toString()}'` }
461
456
  ];
462
- const statement1 = yield attachment.prepare(transaction, `create table t1 (${fields.map(f => `${f.name} ${f.type}`).join(', ')})`);
463
- yield statement1.execute(transaction);
464
- yield statement1.dispose();
465
- yield transaction.commitRetaining();
457
+ const statement1 = await attachment.prepare(transaction, `create table t1 (${fields.map(f => `${f.name} ${f.type}`).join(', ')})`);
458
+ await statement1.execute(transaction);
459
+ await statement1.dispose();
460
+ await transaction.commitRetaining();
466
461
  const recordCount = 5;
467
462
  let parameters;
468
463
  { // scope
469
- const statement2a = yield attachment.prepare(transaction, `insert into t1 (${fields.map(f => f.name).join(', ')}) values (${fields.map(() => '?').join(', ')})`);
464
+ const statement2a = await attachment.prepare(transaction, `insert into t1 (${fields.map(f => f.name).join(', ')}) values (${fields.map(() => '?').join(', ')})`);
470
465
  // Test execution in a new transaction, after the one used in prepare was committed.
471
- yield transaction.commit();
472
- transaction = yield attachment.startTransaction();
473
- const blob = yield attachment.createBlob(transaction);
466
+ await transaction.commit();
467
+ transaction = await attachment.startTransaction();
468
+ const blob = await attachment.createBlob(transaction);
474
469
  expect(blob.isValid).toBeTruthy();
475
- yield blob.write(blobBuffer);
470
+ await blob.write(blobBuffer);
476
471
  expect(blob.isValid).toBeTruthy();
477
- yield blob.close();
472
+ await blob.close();
478
473
  expect(blob.isValid).toBeFalsy();
479
474
  parameters = [
480
475
  -1,
@@ -511,18 +506,18 @@ function runCommonTests(client) {
511
506
  blob
512
507
  ];
513
508
  for (let i = 0; i < recordCount; ++i)
514
- yield statement2a.execute(transaction, parameters);
515
- yield statement2a.dispose();
509
+ await statement2a.execute(transaction, parameters);
510
+ await statement2a.dispose();
516
511
  }
517
512
  { // scope
518
- const statement2b = yield attachment.prepare(transaction, `insert into t1 (${fields.map(f => f.name).join(', ')}) ` +
513
+ const statement2b = await attachment.prepare(transaction, `insert into t1 (${fields.map(f => f.name).join(', ')}) ` +
519
514
  `values (${parameters.map((val, index) => fields[index].valToStr(val)).join(', ')})`);
520
515
  for (let i = 0; i < recordCount; ++i)
521
- yield statement2b.execute(transaction);
522
- yield statement2b.dispose();
516
+ await statement2b.execute(transaction);
517
+ await statement2b.dispose();
523
518
  }
524
- yield transaction.commitRetaining();
525
- const statement3 = yield attachment.prepare(transaction, `select x_short,
519
+ await transaction.commitRetaining();
520
+ const statement3 = await attachment.prepare(transaction, `select x_short,
526
521
  x_int,
527
522
  x_int_scale,
528
523
  x_bigint,
@@ -555,8 +550,8 @@ function runCommonTests(client) {
555
550
  x_blob1,
556
551
  x_blob2
557
552
  from t1`);
558
- const resultSet3 = yield statement3.executeQuery(transaction);
559
- const data = yield resultSet3.fetch();
553
+ const resultSet3 = await statement3.executeQuery(transaction);
554
+ const data = await resultSet3.fetch();
560
555
  expect(data.length).toBe(recordCount * 2);
561
556
  for (const columns of data) {
562
557
  let n = 0;
@@ -593,39 +588,39 @@ function runCommonTests(client) {
593
588
  for (const i = n + 2; n < i; ++n) {
594
589
  const blob = columns[n];
595
590
  expect(blob.isValid).toBeTruthy();
596
- const blobStream = yield attachment.openBlob(transaction, blob);
597
- const buffer = Buffer.alloc(yield blobStream.length);
598
- expect(yield blobStream.read(buffer)).toBe(buffer.length);
599
- expect(yield blobStream.read(buffer)).toBe(-1);
600
- yield blobStream.close();
591
+ const blobStream = await attachment.openBlob(transaction, blob);
592
+ const buffer = Buffer.alloc(await blobStream.length);
593
+ expect(await blobStream.read(buffer)).toBe(buffer.length);
594
+ expect(await blobStream.read(buffer)).toBe(-1);
595
+ await blobStream.close();
601
596
  expect(buffer.toString()).toBe('12345678á9');
602
597
  }
603
598
  expect(columns.length).toBe(n);
604
599
  }
605
- expect((yield resultSet3.fetch()).length).toBe(0);
606
- expect((yield resultSet3.fetch()).length).toBe(0);
607
- yield resultSet3.close();
608
- yield statement3.dispose();
609
- yield transaction.commit();
610
- yield attachment.dropDatabase();
611
- }));
612
- test('#fetchAsObject()', () => __awaiter(this, void 0, void 0, function* () {
613
- const attachment = yield client.createDatabase(getTempFile('ResultSet-fetchAsObject.fdb'));
614
- const transaction = yield attachment.startTransaction();
615
- const resultSet = yield attachment.executeQuery(transaction, 'select 1 as a, 2 as b from rdb$database');
616
- const output = yield resultSet.fetchAsObject();
600
+ expect((await resultSet3.fetch()).length).toBe(0);
601
+ expect((await resultSet3.fetch()).length).toBe(0);
602
+ await resultSet3.close();
603
+ await statement3.dispose();
604
+ await transaction.commit();
605
+ await attachment.dropDatabase();
606
+ });
607
+ test('#fetchAsObject()', async () => {
608
+ const attachment = await client.createDatabase(getTempFile('ResultSet-fetchAsObject.fdb'));
609
+ const transaction = await attachment.startTransaction();
610
+ const resultSet = await attachment.executeQuery(transaction, 'select 1 as a, 2 as b from rdb$database');
611
+ const output = await resultSet.fetchAsObject();
617
612
  expect(output[0].A).toBe(1);
618
613
  expect(output[0].B).toBe(2);
619
- yield resultSet.close();
620
- yield transaction.commit();
621
- yield attachment.dropDatabase();
622
- }));
623
- test('#fetch() with fetchSize', () => __awaiter(this, void 0, void 0, function* () {
624
- const attachment = yield client.createDatabase(getTempFile('ResultSet-fetch-with-fetchSize.fdb'));
625
- const transaction = yield attachment.startTransaction();
626
- yield attachment.execute(transaction, 'create table t1 (n1 integer)');
627
- yield transaction.commitRetaining();
628
- yield attachment.execute(transaction, `
614
+ await resultSet.close();
615
+ await transaction.commit();
616
+ await attachment.dropDatabase();
617
+ });
618
+ test('#fetch() with fetchSize', async () => {
619
+ const attachment = await client.createDatabase(getTempFile('ResultSet-fetch-with-fetchSize.fdb'));
620
+ const transaction = await attachment.startTransaction();
621
+ await attachment.execute(transaction, 'create table t1 (n1 integer)');
622
+ await transaction.commitRetaining();
623
+ await attachment.execute(transaction, `
629
624
  execute block
630
625
  as
631
626
  declare n integer = 0;
@@ -637,24 +632,24 @@ function runCommonTests(client) {
637
632
  end
638
633
  end
639
634
  `);
640
- const rs = yield attachment.executeQuery(transaction, 'select n1 from t1 order by n1');
635
+ const rs = await attachment.executeQuery(transaction, 'select n1 from t1 order by n1');
641
636
  rs.defaultFetchOptions = { fetchSize: 5 };
642
- expect((yield rs.fetch()).length).toBe(5);
643
- expect((yield rs.fetch({ fetchSize: 2 })).length).toBe(2);
644
- expect((yield rs.fetch()).length).toBe(5);
645
- expect((yield rs.fetch({ fetchSize: 36 })).length).toBe(36);
646
- expect((yield rs.fetch()).length).toBe(2);
647
- expect((yield rs.fetch()).length).toBe(0);
648
- yield rs.close();
649
- yield transaction.commit();
650
- yield attachment.dropDatabase();
651
- }));
652
- test('#fetch() with fetchSize and exception', () => __awaiter(this, void 0, void 0, function* () {
653
- const attachment = yield client.createDatabase(getTempFile('ResultSet-fetch-with-fetchSize.fdb'));
654
- const transaction = yield attachment.startTransaction();
655
- yield attachment.execute(transaction, 'create exception e1 \'e1\'');
656
- yield transaction.commitRetaining();
657
- const rs = yield attachment.executeQuery(transaction, `
637
+ expect((await rs.fetch()).length).toBe(5);
638
+ expect((await rs.fetch({ fetchSize: 2 })).length).toBe(2);
639
+ expect((await rs.fetch()).length).toBe(5);
640
+ expect((await rs.fetch({ fetchSize: 36 })).length).toBe(36);
641
+ expect((await rs.fetch()).length).toBe(2);
642
+ expect((await rs.fetch()).length).toBe(0);
643
+ await rs.close();
644
+ await transaction.commit();
645
+ await attachment.dropDatabase();
646
+ });
647
+ test('#fetch() with fetchSize and exception', async () => {
648
+ const attachment = await client.createDatabase(getTempFile('ResultSet-fetch-with-fetchSize.fdb'));
649
+ const transaction = await attachment.startTransaction();
650
+ await attachment.execute(transaction, 'create exception e1 \'e1\'');
651
+ await transaction.commitRetaining();
652
+ const rs = await attachment.executeQuery(transaction, `
658
653
  execute block returns (n integer)
659
654
  as
660
655
  begin
@@ -668,38 +663,67 @@ function runCommonTests(client) {
668
663
  end
669
664
  `);
670
665
  rs.defaultFetchOptions = { fetchSize: 5 };
671
- expect((yield rs.fetch()).length).toBe(2);
666
+ expect((await rs.fetch()).length).toBe(2);
672
667
  expect(rs.fetch()).rejects.toBeTruthy();
673
- yield rs.close();
674
- yield transaction.commit();
675
- yield attachment.dropDatabase();
676
- }));
677
- test('#fetch() with large blob', () => __awaiter(this, void 0, void 0, function* () {
678
- const attachment = yield client.createDatabase(getTempFile('ResultSet-fetch-with-large-blob.fdb'));
679
- let transaction = yield attachment.startTransaction();
680
- yield attachment.execute(transaction, `create table t1 (x_blob blob)`);
681
- yield transaction.commit();
682
- transaction = yield attachment.startTransaction();
668
+ await rs.close();
669
+ await transaction.commit();
670
+ await attachment.dropDatabase();
671
+ });
672
+ test('#fetch() with large blob', async () => {
673
+ const attachment = await client.createDatabase(getTempFile('ResultSet-fetch-with-large-blob.fdb'));
674
+ let transaction = await attachment.startTransaction();
675
+ await attachment.execute(transaction, `create table t1 (x_blob blob)`);
676
+ await transaction.commit();
677
+ transaction = await attachment.startTransaction();
683
678
  const buffer = Buffer.from('123'.repeat(60000));
684
- yield attachment.execute(transaction, `insert into t1 (x_blob) values (?)`, [buffer]);
685
- yield transaction.commit();
686
- transaction = yield attachment.startTransaction();
687
- const resultSet = yield attachment.executeQuery(transaction, `select x_blob from t1`);
688
- const result = yield resultSet.fetch();
689
- const readStream = yield attachment.openBlob(transaction, result[0][0]);
690
- const blobLength = yield readStream.length;
679
+ await attachment.execute(transaction, `insert into t1 (x_blob) values (?)`, [buffer]);
680
+ await transaction.commit();
681
+ transaction = await attachment.startTransaction();
682
+ const resultSet = await attachment.executeQuery(transaction, `select x_blob from t1`);
683
+ const result = await resultSet.fetch();
684
+ const readStream = await attachment.openBlob(transaction, result[0][0]);
685
+ const blobLength = await readStream.length;
691
686
  const resultBuffer = Buffer.alloc(blobLength);
692
687
  let size = 0;
693
688
  let n;
694
- while (size < blobLength && (n = yield readStream.read(resultBuffer.slice(size))) > 0)
689
+ while (size < blobLength && (n = await readStream.read(resultBuffer.slice(size))) > 0)
695
690
  size += n;
696
- yield readStream.close();
691
+ await readStream.close();
697
692
  expect(resultBuffer.toString().length).toEqual(buffer.toString().length);
698
693
  expect(resultBuffer.toString()).toEqual(buffer.toString());
699
- yield resultSet.close();
700
- yield transaction.commit();
701
- yield attachment.dropDatabase();
702
- }));
694
+ await resultSet.close();
695
+ await transaction.commit();
696
+ await attachment.dropDatabase();
697
+ });
698
+ });
699
+ describe('BlobStream', () => {
700
+ test('#seek()', async () => {
701
+ const attachment = await client.createDatabase(getTempFile('BlobStream-seek.fdb'));
702
+ const transaction = await attachment.startTransaction();
703
+ await attachment.execute(transaction, 'create table t1 (b blob)');
704
+ await transaction.commitRetaining();
705
+ const blobStream = await attachment.createBlob(transaction, { type: 'STREAM' });
706
+ await blobStream.write(Buffer.alloc(10, '1234567890'));
707
+ await blobStream.close();
708
+ await attachment.execute(transaction, 'insert into t1 (b) values (?)', [blobStream.blob]);
709
+ const blob = (await attachment.executeSingleton(transaction, 'select b from t1'))[0];
710
+ const readBlobStream = await attachment.openBlob(transaction, blob);
711
+ const buffer = Buffer.alloc(3);
712
+ expect(await readBlobStream.seek(2)).toBe(2);
713
+ expect(await readBlobStream.read(buffer)).toBe(3);
714
+ expect(buffer.toString()).toBe('345');
715
+ expect(await readBlobStream.seek(-1, 1 /* BlobSeekWhence.CURRENT */)).toBe(4);
716
+ expect(await readBlobStream.read(buffer)).toBe(3);
717
+ expect(buffer.toString()).toBe('567');
718
+ expect(await readBlobStream.seek(1, 0 /* BlobSeekWhence.START */)).toBe(1);
719
+ expect(await readBlobStream.read(buffer)).toBe(3);
720
+ expect(buffer.toString()).toBe('234');
721
+ expect(await readBlobStream.seek(-2, 2 /* BlobSeekWhence.END */)).toBe(8);
722
+ expect(await readBlobStream.read(buffer)).toBe(2);
723
+ expect(buffer.slice(0, 2).toString()).toBe('90');
724
+ await transaction.commit();
725
+ await attachment.dropDatabase();
726
+ });
703
727
  });
704
728
  });
705
729
  }