Skip to content

Commit f6a8eeb

Browse files
authored
[Rel v0.2] Migrate Javascript SDK files (#110)
1 parent d5fda38 commit f6a8eeb

11 files changed

+408
-406
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ $ npm run example -- ./examples/listEngines.ts
8888
```
8989

9090
```console
91-
$ npm run example -- ./examples/runQuery.ts -d dbName -e engineName -c "def output = 1 + 2"
91+
$ npm run example -- ./examples/runQuery.ts -d dbName -e engineName -c "def output {1 + 2}"
9292
```
9393

9494
## Data Types

examples/hello.rel

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
def R = "hello", "world"
1+
def R {("hello", "world")}

src/api/model/modelApi.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ describe('ModelApi', () => {
4545

4646
it('should installModel', async () => {
4747
const testModels: Model[] = [
48-
{ name: 'test_model_1', value: 'def foo = :bar' },
48+
{ name: 'test_model_1', value: 'def foo {:bar}' },
4949
];
5050
const resp = await client.installModels(
5151
databaseName,
@@ -68,7 +68,7 @@ describe('ModelApi', () => {
6868

6969
it('should deleteModel', async () => {
7070
const testModels: Model[] = [
71-
{ name: 'test_model_2', value: 'def foo = :bar' },
71+
{ name: 'test_model_2', value: 'def foo {:bar}' },
7272
];
7373
let resp = await client.installModels(
7474
databaseName,

src/api/model/modelApi.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ export class ModelApi extends ExecAsyncApi {
2727
models.map((model, index) => {
2828
const inputName = `input_${randInt}_${index}`;
2929
queryInputs.push({ name: inputName, value: model.value });
30-
queries.push(`def delete:rel:catalog:model["${model.name}"] = rel:catalog:model["${model.name}"]
31-
def insert:rel:catalog:model["${model.name}"] = ${inputName}`);
30+
queries.push(`def delete[:rel, :catalog, :model, "${model.name}"]: rel[:catalog, :model, "${model.name}"]
31+
def insert[:rel, :catalog, :model, "${model.name}"]: ${inputName}`);
3232
});
3333

3434
return await this.exec(
@@ -48,8 +48,8 @@ export class ModelApi extends ExecAsyncApi {
4848
models.map((model, index) => {
4949
const inputName = `input_${randInt}_${index}`;
5050
queryInputs.push({ name: inputName, value: model.value });
51-
queries.push(`def delete:rel:catalog:model["${model.name}"] = rel:catalog:model["${model.name}"]
52-
def insert:rel:catalog:model["${model.name}"] = ${inputName}`);
51+
queries.push(`def delete[:rel, :catalog, :model, "${model.name}"]: rel[:catalog, :model, "${model.name}"]
52+
def insert[:rel, :catalog, :model, "${model.name}"]: ${inputName}`);
5353
});
5454

5555
return await this.execAsync(
@@ -67,7 +67,7 @@ export class ModelApi extends ExecAsyncApi {
6767
const rsp = await this.exec(
6868
database,
6969
engine,
70-
`def output:${outName}[name] = rel:catalog:model(name, _)`,
70+
`def output(:${outName}, name): rel(:catalog, :model, name, _)`,
7171
);
7272

7373
const result = rsp.results.find(
@@ -86,7 +86,7 @@ export class ModelApi extends ExecAsyncApi {
8686
const rsp = await this.exec(
8787
database,
8888
engine,
89-
`def output:${outName} = rel:catalog:model["${name}"]`,
89+
`def output[:${outName}]: rel[:catalog, :model, "${name}"]`,
9090
);
9191

9292
const result = rsp.results.find(
@@ -106,15 +106,15 @@ export class ModelApi extends ExecAsyncApi {
106106
async deleteModels(database: string, engine: string, names: string[]) {
107107
const queries = names.map(
108108
name =>
109-
`def delete:rel:catalog:model["${name}"] = rel:catalog:model["${name}"]`,
109+
`def delete[:rel, :catalog, :model, "${name}"]: rel[:catalog, :model, "${name}"]`,
110110
);
111111
return await this.exec(database, engine, queries.join('\n'), [], false);
112112
}
113113

114114
async deleteModelsAsync(database: string, engine: string, names: string[]) {
115115
const queries = names.map(
116116
name =>
117-
`def delete:rel:catalog:model["${name}"] = rel:catalog:model["${name}"]`,
117+
`def delete[:rel, :catalog, :model, "${name}"]: rel[:catalog, :model, "${name}"]`,
118118
);
119119

120120
return await this.execAsync(

src/api/query/execAsyncApi.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ export class ExecAsyncApi extends TransactionAsyncApi {
117117
json: any,
118118
) {
119119
const qs = [
120-
`def config:data = data`,
121-
`def insert:${relation} = load_json[config]`,
120+
`def config[:data]: data`,
121+
`def insert[:${relation}]: load_json[config]`,
122122
];
123123
const inputs: QueryInput[] = [
124124
{
@@ -138,7 +138,7 @@ export class ExecAsyncApi extends TransactionAsyncApi {
138138
syntax?: CsvConfigSyntax,
139139
schema?: CsvConfigSchema,
140140
) {
141-
const qs = [`def config:data = data`];
141+
const qs = [`def config[:data]: data`];
142142
const inputs: QueryInput[] = [
143143
{
144144
name: 'data',
@@ -154,7 +154,7 @@ export class ExecAsyncApi extends TransactionAsyncApi {
154154
qs.push(...schemaToRel(schema));
155155
}
156156

157-
qs.push(`def insert:${relation} = load_csv[config]`);
157+
qs.push(`def insert[:${relation}]: load_csv[config]`);
158158

159159
return this.exec(database, engine, qs.join('\n'), inputs, false);
160160
}

src/api/query/loadData.test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ describe('Load data integration tests', () => {
5151
resp = await client.exec(
5252
databaseName,
5353
engineName,
54-
'def output = test_relation',
54+
'def output {test_relation}',
5555
);
5656

5757
expect(resp.transaction.state).toEqual('COMPLETED');
@@ -74,7 +74,7 @@ describe('Load data integration tests', () => {
7474
resp = await client.exec(
7575
databaseName,
7676
engineName,
77-
'def output = test_relation',
77+
'def output {test_relation}',
7878
);
7979

8080
expect(resp.transaction.state).toEqual('COMPLETED');
@@ -109,7 +109,7 @@ describe('Load data integration tests', () => {
109109
resp = await client.exec(
110110
databaseName,
111111
engineName,
112-
'def output = test_relation_1',
112+
'def output {test_relation_1}',
113113
);
114114

115115
expect(resp.transaction.state).toEqual('COMPLETED');
@@ -142,7 +142,7 @@ describe('Load data integration tests', () => {
142142
resp = await client.exec(
143143
databaseName,
144144
engineName,
145-
'def output = test_relation_2',
145+
'def output {test_relation_2}',
146146
);
147147

148148
expect(resp.transaction.state).toEqual('COMPLETED');

src/api/query/queryApi.test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ describe('QueryApi', () => {
6464
persist: [],
6565
inputs: [],
6666
source: {
67-
value: 'def output = 123',
67+
value: 'def output {123}',
6868
name: 'query',
6969
type: 'Source',
7070
path: '',
@@ -92,7 +92,7 @@ describe('QueryApi', () => {
9292
})
9393
.reply(200, response);
9494

95-
const result = await api.query(database, engine, 'def output = 123');
95+
const result = await api.query(database, engine, 'def output {123}');
9696

9797
scope.done();
9898

@@ -119,7 +119,7 @@ describe('QueryApi', () => {
119119
},
120120
],
121121
source: {
122-
value: 'def output = 123',
122+
value: 'def output {123}',
123123
name: 'query',
124124
type: 'Source',
125125
path: '',
@@ -146,7 +146,7 @@ describe('QueryApi', () => {
146146
compute_name: engine,
147147
})
148148
.reply(200, response);
149-
const result = await api.query(database, engine, 'def output = 123', [
149+
const result = await api.query(database, engine, 'def output {123}', [
150150
{ name: 'input1', value: 'value1' },
151151
]);
152152

src/api/query/utils.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ export function syntaxToRel(syntax: CsvConfigSyntax) {
8686
return `(${key}, :${toRelLiteral(syntax.header![key])})`;
8787
})
8888
.join('; ');
89-
qs.push(`def config:syntax:header = ${headerStr}`);
89+
qs.push(`def config[:syntax, :header]: { ${headerStr} }`);
9090
} else {
91-
qs.push(`def config:syntax:${prop} = ${toRelLiteral(syntax[prop])}`);
91+
qs.push(`def config[:syntax, :${prop}]: ${toRelLiteral(syntax[prop])}`);
9292
}
9393
});
9494

@@ -99,7 +99,9 @@ export function schemaToRel(schema: CsvConfigSchema) {
9999
const qs: string[] = [];
100100

101101
Object.keys(schema).forEach(colName => {
102-
qs.push(`def config:schema${colName} = ${toRelLiteral(schema[colName])}`);
102+
qs.push(
103+
`def config[:schema, ${colName}]: ${toRelLiteral(schema[colName])}`,
104+
);
103105
});
104106

105107
return qs;

src/api/transaction/transactionAsyncApi.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ const protobufMock = readFileSync(__dirname + '/mocks/metadata.pb');
2828
const multipartContentType =
2929
'multipart/form-data; boundary=28deee55b43d20e109a8fe119e47c5393620ea568b7059405c4cf23bad7b';
3030

31-
// def output = :foo
32-
// def output = :"foo;bar", 1
33-
// def output = 1
31+
// def output {:foo}
32+
// def output {(:"foo;bar", 1)}
33+
// def output {1}
3434
const expectedArrow = [
3535
{
3636
filename: '0.arrow',

src/results/resultTable.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export class ResultTable implements IteratorOf<RelTypedValue['value'][]> {
8989
* Instantiate a new ResultTable instance.
9090
*
9191
* @example
92-
* cosnt result = await client.exec('database', 'engine', 'def output = 123, "test"')
92+
* cosnt result = await client.exec('database', 'engine', 'def output {123}, "test"')
9393
* cosnt table = new ResultTable(result.results[0]);
9494
*
9595
* console.log(table.values()); // Prints [[123n, "test"]];

0 commit comments

Comments
 (0)