Skip to content

Commit 0f78d0e

Browse files
author
Denis Gursky
authored
added getTransactionQuery (#86)
1 parent 813127a commit 0f78d0e

File tree

4 files changed

+63
-1
lines changed

4 files changed

+63
-1
lines changed

examples/getTransactionQuery.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* Copyright 2021 RelationalAI, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy
6+
* of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations
14+
* under the License.
15+
*/
16+
17+
import { Command } from 'commander';
18+
19+
import { Client, readConfig } from '../index.node';
20+
import { show } from './show';
21+
22+
async function run(id: string, profile?: string) {
23+
const config = await readConfig(profile);
24+
const client = new Client(config);
25+
const result = await client.getTransactionQuery(id);
26+
27+
show(result);
28+
}
29+
30+
(async () => {
31+
const program = new Command();
32+
33+
const options = program
34+
.requiredOption('--id <type>', 'transaction id')
35+
.option('-p, --profile <type>', 'profile', 'default')
36+
.parse(process.argv)
37+
.opts();
38+
39+
try {
40+
await run(options.id, options.profile);
41+
} catch (error: any) {
42+
console.error(error.toString());
43+
}
44+
})();

src/api/transaction/transactionAsyncApi.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,16 @@ describe('TransactionAsyncApi', () => {
418418
expect(result).toEqual(response);
419419
});
420420

421+
it('should get transaction query', async () => {
422+
const response = 'query-text';
423+
const scope = nock(baseUrl).get(`${path}/id1/query`).reply(200, response);
424+
const result = await api.getTransactionQuery('id1');
425+
426+
scope.done();
427+
428+
expect(result).toEqual(response);
429+
});
430+
421431
it('should cancel transaction', async () => {
422432
const response = {};
423433
const scope = nock(baseUrl).post(`${path}/id1/cancel`).reply(200, response);

src/api/transaction/transactionAsyncApi.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ export class TransactionAsyncApi extends Base {
9696
return result;
9797
}
9898

99+
async getTransactionQuery(transactionId: string) {
100+
const result = await this.get<string>(`${ENDPOINT}/${transactionId}/query`);
101+
102+
return result;
103+
}
104+
99105
async cancelTransaction(transactionId: string) {
100106
const result = await this.post<CancelResponse>(
101107
`${ENDPOINT}/${transactionId}/cancel`,

src/api/transaction/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,11 @@ export type TransactionAsync = {
200200
finished_at?: number;
201201
duration?: number;
202202
read_only: boolean;
203-
last_requested_interval: string;
203+
last_requested_interval: number;
204204
response_format_version: string;
205205
query: string;
206+
query_size: number;
207+
language: string;
206208
user_agent: string;
207209
abort_reason?: string;
208210
tags?: string[];

0 commit comments

Comments
 (0)