Skip to content

Commit 8d12c4d

Browse files
author
Denis Gursky
authored
Merge pull request #34 from RelationalAI/dg-list-txns-filter
Added filtering transactions and tags for exec*
2 parents 5f8c3ea + 809901f commit 8d12c4d

File tree

8 files changed

+45
-8
lines changed

8 files changed

+45
-8
lines changed

examples/execAsync.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@ async function run(
2525
queryString: string,
2626
readonly: boolean,
2727
poll: boolean,
28+
tag: string,
2829
profile?: string,
2930
) {
3031
const config = await readConfig(profile);
3132
const client = new Client(config);
33+
const tags = tag ? [tag] : undefined;
3234
const result = poll
33-
? await client.exec(database, engine, queryString, [], readonly)
34-
: await client.execAsync(database, engine, queryString, [], readonly);
35+
? await client.exec(database, engine, queryString, [], readonly, tags)
36+
: await client.execAsync(database, engine, queryString, [], readonly, tags);
3537

3638
showTransactionResult(result);
3739
}
@@ -43,6 +45,7 @@ async function run(
4345
.requiredOption('-d, --database <type>', 'database name')
4446
.requiredOption('-e, --engine <type>', 'engine name')
4547
.requiredOption('-c, --command <type>', 'rel source string')
48+
.option('-t, --tag <type>', 'tag', '')
4649
.option('-r, --readonly', 'readonly', false)
4750
.option('--poll', 'poll results', false)
4851
.option('-p, --profile <type>', 'profile', 'default')
@@ -56,6 +59,7 @@ async function run(
5659
options.command,
5760
options.readonly,
5861
options.poll,
62+
options.tag,
5963
options.profile,
6064
);
6165
} catch (error: any) {

examples/listTransactions.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ import { Command } from 'commander';
1919
import { Client, readConfig } from '../index.node';
2020
import { show } from './show';
2121

22-
async function run(profile?: string) {
22+
async function run(tag: string, profile?: string) {
2323
const config = await readConfig(profile);
2424
const client = new Client(config);
25-
const result = await client.listTransactions();
25+
const options = tag ? { tags: [tag] } : undefined;
26+
const result = await client.listTransactions(options);
2627

2728
show(result);
2829
}
@@ -31,12 +32,13 @@ async function run(profile?: string) {
3132
const program = new Command();
3233

3334
const options = program
35+
.option('-t, --tag <type>', 'tag', '')
3436
.option('-p, --profile <type>', 'profile', 'default')
3537
.parse(process.argv)
3638
.opts();
3739

3840
try {
39-
await run(options.profile);
41+
await run(options.tag, options.profile);
4042
} catch (error: any) {
4143
console.error(error.toString());
4244
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@relationalai/rai-sdk-javascript",
33
"description": "RelationalAI SDK for JavaScript",
4-
"version": "0.6.1",
4+
"version": "0.6.2",
55
"author": {
66
"name": "RelationalAI",
77
"url": "https://relational.ai"

src/query/execAsyncApi.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ describe('QueryAsyncApi', () => {
4444
nowait_durable: false,
4545
readonly: true,
4646
v1_inputs: [],
47+
tags: [],
4748
})
4849
.reply(200, response);
4950
const result = await api.execAsync(database, engine, query, [], true);

src/query/execAsyncApi.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,15 @@ export class ExecAsyncApi extends TransactionAsyncApi {
3333
queryString: string,
3434
inputs: QueryInput[] = [],
3535
readonly = true,
36+
tags: string[] = [],
3637
) {
3738
const transaction: TransactionAsyncPayload = {
3839
dbname: database,
3940
query: queryString,
4041
nowait_durable: false,
4142
readonly,
4243
v1_inputs: inputs.map(input => makeQueryInput(input.name, input.value)),
44+
tags,
4345
};
4446

4547
if (engine) {
@@ -55,6 +57,7 @@ export class ExecAsyncApi extends TransactionAsyncApi {
5557
queryString: string,
5658
inputs: QueryInput[] = [],
5759
readonly = true,
60+
tags: string[] = [],
5861
interval = 3 * 1000, // 3 seconds
5962
timeout = Number.POSITIVE_INFINITY,
6063
) {
@@ -64,6 +67,7 @@ export class ExecAsyncApi extends TransactionAsyncApi {
6467
queryString,
6568
inputs,
6669
readonly,
70+
tags,
6771
);
6872
const txnId = result.transaction.id;
6973

src/transaction/transactionAsyncApi.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,22 @@ describe('TransactionAsyncApi', () => {
111111
expect(result).toEqual(mockTransactions);
112112
});
113113

114+
it('should list transactions with params', async () => {
115+
const response = {
116+
transactions: mockTransactions,
117+
};
118+
const query = {
119+
engine_name: 'test_engine',
120+
tags: ['tag1', 'tag2'],
121+
};
122+
const scope = nock(baseUrl).get(path).query(query).reply(200, response);
123+
const result = await api.listTransactions(query);
124+
125+
scope.done();
126+
127+
expect(result).toEqual(mockTransactions);
128+
});
129+
114130
it('should get transaction', async () => {
115131
const response = {
116132
transaction: mockTransactions[0],

src/transaction/transactionAsyncApi.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
TransactionAsyncCompact,
2323
TransactionAsyncFile,
2424
TransactionAsyncPayload,
25+
TransactionListOptions,
2526
TransactionMetadata,
2627
} from './types';
2728

@@ -50,8 +51,8 @@ export class TransactionAsyncApi extends Base {
5051
};
5152
}
5253

53-
async listTransactions() {
54-
const result = await this.get<ListResponse>(ENDPOINT);
54+
async listTransactions(options?: TransactionListOptions) {
55+
const result = await this.get<ListResponse>(ENDPOINT, options);
5556

5657
return result.transactions;
5758
}

src/transaction/types.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ export type TransactionAsyncPayload = {
179179
engine_name?: string;
180180
query: string;
181181
v1_inputs: Relation[];
182+
tags?: string[];
182183
};
183184

184185
export type TransactionAsync = {
@@ -197,6 +198,7 @@ export type TransactionAsync = {
197198
query: string;
198199
user_agent: string;
199200
abort_reason?: string;
201+
tags?: string[];
200202
};
201203

202204
export type TransactionAsyncCompact = {
@@ -226,3 +228,10 @@ export type TransactionAsyncResult = {
226228
problems?: Problem[];
227229
results: ArrowRelation[];
228230
};
231+
232+
export type TransactionListOptions = {
233+
database_name?: string | string[];
234+
engine_name?: string | string[];
235+
state?: TransactionAsyncState | TransactionAsyncState[];
236+
tags?: string | string[];
237+
};

0 commit comments

Comments
 (0)