Skip to content

Commit bc0eb99

Browse files
authored
Merge pull request #65 from outerbase/invisal/sdk-transform
Moving to SDK transform
2 parents 3acf7fc + b810ce1 commit bc0eb99

File tree

12 files changed

+176
-479
lines changed

12 files changed

+176
-479
lines changed

package-lock.json

Lines changed: 9 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@outerbase/sdk",
3-
"version": "2.0.0-rc.4",
3+
"version": "2.0.0-rc.5",
44
"description": "",
55
"main": "dist/index.js",
66
"module": "dist/index.js",
@@ -34,6 +34,7 @@
3434
"author": "Outerbase",
3535
"license": "MIT",
3636
"dependencies": {
37+
"@outerbase/sdk-transform": "^1.0.3",
3738
"handlebars": "^4.7.8"
3839
},
3940
"devDependencies": {
@@ -53,11 +54,11 @@
5354
"mysql2": "^3.11.3",
5455
"pg": "^8.13.0",
5556
"prettier": "^3.2.5",
57+
"snowflake-sdk": "^1.15.0",
5658
"ts-jest": "^29.1.3",
5759
"ts-node": "^10.9.2",
5860
"tsconfig-paths": "^4.2.0",
5961
"typescript": "^5.4.5",
60-
"ws": "^8.17.1",
61-
"snowflake-sdk": "^1.15.0"
62+
"ws": "^8.17.1"
6263
}
6364
}

src/connections/index.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,17 @@
1+
import { ColumnHeader, ResultSet } from '@outerbase/sdk-transform';
12
import {
23
Database,
34
TableColumn,
45
TableColumnDefinition,
56
} from '../models/database';
67

7-
export interface QueryResultHeader {
8-
name: string;
9-
displayName: string;
10-
type?: string;
11-
tableName?: string;
12-
}
13-
export interface QueryResult<T = Record<string, unknown>> {
8+
export interface QueryResult<T = Record<string, unknown>>
9+
extends Omit<ResultSet, 'rows'> {
1410
data: T[];
1511
count?: number;
16-
headers: QueryResultHeader[];
1712
error: Error | null;
1813
query: string;
1914
}
20-
2115
export interface ConnectionSelectOptions {
2216
where?: { name: string; value: unknown; operator: string }[];
2317
orderBy?: (string | [string, 'ASC' | 'DESC'])[];

src/connections/mysql.ts

Lines changed: 26 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,15 @@ import {
77
import { SqlConnection } from './sql-base';
88
import { Query } from '../query';
99
import { QueryType } from '../query-params';
10-
import {
11-
Constraint,
12-
Database,
13-
Table,
14-
TableColumn,
15-
TableColumnDefinition,
16-
} from './../models/database';
10+
import { Constraint, Database, Table, TableColumn } from './../models/database';
1711
import { MySQLDialect } from './../query-builder/dialects/mysql';
1812
import {
1913
createErrorResult,
20-
transformArrayBasedResult,
14+
transformFromSdkTransform,
2115
} from './../utils/transformer';
2216
import { QueryResult } from '.';
2317
import { ColumnDataType } from '../query-builder';
18+
import { transformMySQLResult } from '@outerbase/sdk-transform';
2419

2520
interface MySQLSchemaResult {
2621
SCHEMA_NAME: string;
@@ -127,10 +122,10 @@ export function buildMySQLDatabaseSchmea({
127122

128123
columnLookup[
129124
column.TABLE_SCHEMA +
130-
'.' +
131-
column.TABLE_NAME +
132-
'.' +
133-
column.COLUMN_NAME
125+
'.' +
126+
column.TABLE_NAME +
127+
'.' +
128+
column.COLUMN_NAME
134129
] = columnObject;
135130

136131
table.columns.push(columnObject);
@@ -156,10 +151,10 @@ export function buildMySQLDatabaseSchmea({
156151

157152
constraintLookup[
158153
constraint.TABLE_SCHEMA +
159-
'.' +
160-
constraint.TABLE_NAME +
161-
'.' +
162-
constraint.CONSTRAINT_NAME
154+
'.' +
155+
constraint.TABLE_NAME +
156+
'.' +
157+
constraint.CONSTRAINT_NAME
163158
] = constraintObject;
164159

165160
table.constraints.push(constraintObject);
@@ -169,22 +164,22 @@ export function buildMySQLDatabaseSchmea({
169164
for (const constraintColumn of constraintColumnsList) {
170165
const constraint =
171166
constraintLookup[
172-
constraintColumn.TABLE_SCHEMA +
173-
'.' +
174-
constraintColumn.TABLE_NAME +
175-
'.' +
176-
constraintColumn.CONSTRAINT_NAME
167+
constraintColumn.TABLE_SCHEMA +
168+
'.' +
169+
constraintColumn.TABLE_NAME +
170+
'.' +
171+
constraintColumn.CONSTRAINT_NAME
177172
];
178173

179174
if (!constraint) continue;
180175

181176
const currentColumn =
182177
columnLookup[
183-
constraintColumn.TABLE_SCHEMA +
184-
'.' +
185-
constraintColumn.TABLE_NAME +
186-
'.' +
187-
constraintColumn.COLUMN_NAME
178+
constraintColumn.TABLE_SCHEMA +
179+
'.' +
180+
constraintColumn.TABLE_NAME +
181+
'.' +
182+
constraintColumn.COLUMN_NAME
188183
];
189184
if (currentColumn && constraintColumn.REFERENCED_COLUMN_NAME) {
190185
currentColumn.definition.references = {
@@ -254,18 +249,11 @@ export class MySQLConnection extends SqlConnection {
254249
);
255250

256251
if (error) {
257-
return createErrorResult(error.message) as QueryResult<T>;
252+
return createErrorResult<T>(error.message);
258253
} else {
259-
return transformArrayBasedResult(
260-
fields,
261-
(header) => {
262-
return {
263-
name: header.name,
264-
tableName: header.table,
265-
};
266-
},
267-
rows as unknown[][]
268-
) as QueryResult<T>;
254+
return transformFromSdkTransform(
255+
transformMySQLResult([rows, fields])
256+
);
269257
}
270258
} catch {
271259
return createErrorResult('Unknown error') as QueryResult<T>;
@@ -377,7 +365,7 @@ export class MySQLConnection extends SqlConnection {
377365
);
378366
}
379367

380-
async connect(): Promise<any> { }
368+
async connect(): Promise<any> {}
381369
async disconnect(): Promise<any> {
382370
this.conn.destroy();
383371
}

src/connections/outerbase.bk.txt

Lines changed: 0 additions & 139 deletions
This file was deleted.

0 commit comments

Comments
 (0)