@quillsql/node 0.4.3 → 0.4.5
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.
- package/dist/db/CachedConnection.d.ts +3 -3
- package/dist/db/DatabaseHelper.d.ts +10 -11
- package/dist/db/DatabaseHelper.js +8 -9
- package/dist/index.d.ts +20 -3
- package/dist/index.js +14 -8
- package/dist/index.uspec.d.ts +0 -1
- package/dist/index.uspec.js +40 -38
- package/package.json +1 -1
- package/src/db/CachedConnection.ts +3 -3
- package/src/db/DatabaseHelper.ts +10 -11
- package/src/index.ts +35 -15
- package/src/index.uspec.ts +40 -40
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Mapable, CacheCredentials } from "../models/Cache";
|
|
2
|
-
import { DatabaseConnection,
|
|
2
|
+
import { DatabaseConnection, QuillDatabaseType } from "./DatabaseHelper";
|
|
3
3
|
export declare class CachedConnection {
|
|
4
|
-
databaseType:
|
|
4
|
+
databaseType: QuillDatabaseType;
|
|
5
5
|
pool: DatabaseConnection;
|
|
6
6
|
orgId: any;
|
|
7
7
|
ttl: number;
|
|
8
8
|
cache: Mapable | null;
|
|
9
|
-
constructor(databaseType:
|
|
9
|
+
constructor(databaseType: QuillDatabaseType, config: any, cacheConfig?: Partial<CacheCredentials>);
|
|
10
10
|
query(text: string, values?: any[]): Promise<any>;
|
|
11
11
|
/**
|
|
12
12
|
* Configures and returns a cache instance or null if none could be created.
|
|
@@ -6,8 +6,7 @@ import { PostgresConnectionConfig } from "./Postgres";
|
|
|
6
6
|
import { SnowflakeConnectionConfig } from "./Snowflake";
|
|
7
7
|
import { BigQueryConfig } from "./BigQuery";
|
|
8
8
|
import { MysqlConnectionConfig } from "./Mysql";
|
|
9
|
-
export declare enum
|
|
10
|
-
postgres = "postgres",
|
|
9
|
+
export declare enum QuillDatabaseType {
|
|
11
10
|
postgresql = "postgresql",
|
|
12
11
|
snowflake = "snowflake",
|
|
13
12
|
bigquery = "bigquery",
|
|
@@ -23,18 +22,18 @@ export interface QuillQueryResults {
|
|
|
23
22
|
[fieldName: string]: any;
|
|
24
23
|
}[];
|
|
25
24
|
}
|
|
26
|
-
export declare function getDatabaseCredentials(databaseType:
|
|
27
|
-
export declare function connectToDatabase(databaseType:
|
|
28
|
-
export declare function runQueryByDatabase(databaseType:
|
|
29
|
-
export declare function disconnectFromDatabase(databaseType:
|
|
30
|
-
export declare function getSchemasByDatabase(databaseType:
|
|
31
|
-
export declare function getTablesBySchemaByDatabase(databaseType:
|
|
25
|
+
export declare function getDatabaseCredentials(databaseType: QuillDatabaseType, connectionString: string): PostgresConnectionConfig | SnowflakeConnectionConfig | BigQueryConfig | MysqlConnectionConfig | undefined;
|
|
26
|
+
export declare function connectToDatabase(databaseType: QuillDatabaseType, config: PostgresConnectionConfig | SnowflakeConnectionConfig | BigQueryConfig | MysqlConnectionConfig): DatabaseConnection;
|
|
27
|
+
export declare function runQueryByDatabase(databaseType: QuillDatabaseType, connection: DatabaseConnection, sql: string): Promise<QuillQueryResults> | undefined;
|
|
28
|
+
export declare function disconnectFromDatabase(databaseType: QuillDatabaseType, database: DatabaseConnection): void | Promise<void>;
|
|
29
|
+
export declare function getSchemasByDatabase(databaseType: QuillDatabaseType, connection: DatabaseConnection): Promise<string[] | undefined>;
|
|
30
|
+
export declare function getTablesBySchemaByDatabase(databaseType: QuillDatabaseType, connection: DatabaseConnection, schemaName: string | string[]): Promise<string[] | {
|
|
32
31
|
tableName: string;
|
|
33
32
|
schemaName: string;
|
|
34
33
|
}[] | undefined>;
|
|
35
|
-
export declare function getColumnsByTableByDatabase(databaseType:
|
|
36
|
-
export declare function getForiegnKeysByDatabase(databaseType:
|
|
37
|
-
export declare function getColumnInfoBySchemaByDatabase(databaseType:
|
|
34
|
+
export declare function getColumnsByTableByDatabase(databaseType: QuillDatabaseType, connection: DatabaseConnection, schemaName: string, tableName: string): Promise<string[] | undefined>;
|
|
35
|
+
export declare function getForiegnKeysByDatabase(databaseType: QuillDatabaseType, connection: DatabaseConnection, schemaName: string, tableName: string, primaryKey: string): Promise<string[] | undefined>;
|
|
36
|
+
export declare function getColumnInfoBySchemaByDatabase(databaseType: QuillDatabaseType, connection: DatabaseConnection, schemaName: string, tables: string[] | {
|
|
38
37
|
tableName: string;
|
|
39
38
|
schemaName: string;
|
|
40
39
|
}[]): Promise<{
|
|
@@ -9,19 +9,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.getColumnInfoBySchemaByDatabase = exports.getForiegnKeysByDatabase = exports.getColumnsByTableByDatabase = exports.getTablesBySchemaByDatabase = exports.getSchemasByDatabase = exports.disconnectFromDatabase = exports.runQueryByDatabase = exports.connectToDatabase = exports.getDatabaseCredentials = exports.
|
|
12
|
+
exports.getColumnInfoBySchemaByDatabase = exports.getForiegnKeysByDatabase = exports.getColumnsByTableByDatabase = exports.getTablesBySchemaByDatabase = exports.getSchemasByDatabase = exports.disconnectFromDatabase = exports.runQueryByDatabase = exports.connectToDatabase = exports.getDatabaseCredentials = exports.QuillDatabaseType = void 0;
|
|
13
13
|
const Postgres_1 = require("./Postgres");
|
|
14
14
|
const Snowflake_1 = require("./Snowflake");
|
|
15
15
|
const BigQuery_1 = require("./BigQuery");
|
|
16
16
|
const Mysql_1 = require("./Mysql");
|
|
17
|
-
var
|
|
18
|
-
(function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
})(DatabaseType || (exports.DatabaseType = DatabaseType = {}));
|
|
17
|
+
var QuillDatabaseType;
|
|
18
|
+
(function (QuillDatabaseType) {
|
|
19
|
+
QuillDatabaseType["postgresql"] = "postgresql";
|
|
20
|
+
QuillDatabaseType["snowflake"] = "snowflake";
|
|
21
|
+
QuillDatabaseType["bigquery"] = "bigquery";
|
|
22
|
+
QuillDatabaseType["mysql"] = "mysql";
|
|
23
|
+
})(QuillDatabaseType || (exports.QuillDatabaseType = QuillDatabaseType = {}));
|
|
25
24
|
function getDatabaseCredentials(databaseType, connectionString) {
|
|
26
25
|
switch (databaseType.toLowerCase()) {
|
|
27
26
|
case "postgres":
|
package/dist/index.d.ts
CHANGED
|
@@ -2,16 +2,33 @@ import { CacheCredentials } from "./models/Cache";
|
|
|
2
2
|
import { QuillQueryParams } from "./models/Quill";
|
|
3
3
|
import { CachedConnection } from "./db/CachedConnection";
|
|
4
4
|
import "dotenv/config";
|
|
5
|
-
import {
|
|
5
|
+
import { QuillDatabaseType } from "./db/DatabaseHelper";
|
|
6
6
|
/**
|
|
7
7
|
* Quill - Fullstack API Platform for Dashboards and Reporting.
|
|
8
8
|
*/
|
|
9
|
+
export interface QuillQueryResult {
|
|
10
|
+
data?: any;
|
|
11
|
+
status: string;
|
|
12
|
+
error?: string;
|
|
13
|
+
queries?: {
|
|
14
|
+
rows: any[];
|
|
15
|
+
fields: any[];
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export type DatabaseType = QuillDatabaseType;
|
|
9
19
|
export default class QuillClass {
|
|
10
20
|
targetConnection: CachedConnection;
|
|
11
21
|
private baseUrl;
|
|
12
22
|
private config;
|
|
13
|
-
constructor(
|
|
14
|
-
|
|
23
|
+
constructor(data: {
|
|
24
|
+
privateKey: string;
|
|
25
|
+
databaseType: DatabaseType;
|
|
26
|
+
databaseConnectionString?: string;
|
|
27
|
+
databaseConfig?: any;
|
|
28
|
+
cache?: Partial<CacheCredentials>;
|
|
29
|
+
metadataServerURL?: string;
|
|
30
|
+
});
|
|
31
|
+
query({ orgId, metadata, }: QuillQueryParams): Promise<QuillQueryResult>;
|
|
15
32
|
private runQueries;
|
|
16
33
|
private postQuill;
|
|
17
34
|
close(): Promise<void>;
|
package/dist/index.js
CHANGED
|
@@ -21,20 +21,18 @@ const schemaConversion_1 = require("./utils/schemaConversion");
|
|
|
21
21
|
const HOST = process.env.ENV === "development"
|
|
22
22
|
? "http://localhost:8080"
|
|
23
23
|
: "https://quill-344421.uc.r.appspot.com";
|
|
24
|
-
/**
|
|
25
|
-
* Quill - Fullstack API Platform for Dashboards and Reporting.
|
|
26
|
-
*/
|
|
27
24
|
class QuillClass {
|
|
28
|
-
constructor(
|
|
25
|
+
constructor(data) {
|
|
26
|
+
const { privateKey, databaseType, databaseConnectionString, databaseConfig, cache, metadataServerURL, } = data;
|
|
29
27
|
this.baseUrl = metadataServerURL ? metadataServerURL : HOST;
|
|
30
28
|
this.config = { headers: { Authorization: `Bearer ${privateKey}` } };
|
|
31
|
-
let credentials =
|
|
29
|
+
let credentials = databaseConfig;
|
|
32
30
|
if (databaseConnectionString) {
|
|
33
31
|
credentials = (0, DatabaseHelper_1.getDatabaseCredentials)(databaseType, databaseConnectionString);
|
|
34
32
|
}
|
|
35
|
-
this.targetConnection = new CachedConnection_1.CachedConnection(databaseType, credentials, cache);
|
|
33
|
+
this.targetConnection = new CachedConnection_1.CachedConnection(databaseType, credentials, cache || {});
|
|
36
34
|
}
|
|
37
|
-
query({ orgId, metadata }) {
|
|
35
|
+
query({ orgId, metadata, }) {
|
|
38
36
|
var _a, _b, _c;
|
|
39
37
|
return __awaiter(this, void 0, void 0, function* () {
|
|
40
38
|
this.targetConnection.orgId = orgId;
|
|
@@ -169,7 +167,14 @@ class QuillClass {
|
|
|
169
167
|
}
|
|
170
168
|
exports.default = QuillClass;
|
|
171
169
|
const Quill = ({ privateKey, databaseConnectionString, databaseConfig, cache, databaseType, metadataServerURL, }) => {
|
|
172
|
-
return new QuillClass(
|
|
170
|
+
return new QuillClass({
|
|
171
|
+
privateKey,
|
|
172
|
+
databaseType,
|
|
173
|
+
databaseConnectionString,
|
|
174
|
+
databaseConfig,
|
|
175
|
+
cache,
|
|
176
|
+
metadataServerURL,
|
|
177
|
+
});
|
|
173
178
|
};
|
|
174
179
|
module.exports = Quill;
|
|
175
180
|
module.exports.Quill = Quill;
|
|
@@ -183,3 +188,4 @@ module.exports.getColumnInfoBySchemaByDatabase =
|
|
|
183
188
|
DatabaseHelper_1.getColumnInfoBySchemaByDatabase;
|
|
184
189
|
module.exports.connectToDatabase = DatabaseHelper_1.connectToDatabase;
|
|
185
190
|
module.exports.runQueryByDatabase = DatabaseHelper_1.runQueryByDatabase;
|
|
191
|
+
module.exports.DatabaseType = DatabaseHelper_1.QuillDatabaseType;
|
package/dist/index.uspec.d.ts
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/index.uspec.js
CHANGED
|
@@ -1,39 +1,41 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
});
|
|
2
|
+
// import Quill from ".";
|
|
3
|
+
// import { DatabaseType } from "./db/DatabaseHelper";
|
|
4
|
+
// jest.mock(".");
|
|
5
|
+
// describe("Quill", () => {
|
|
6
|
+
// let quill: Quill;
|
|
7
|
+
// beforeEach(() => {
|
|
8
|
+
// quill = new Quill(
|
|
9
|
+
// "dummy_private_key",
|
|
10
|
+
// DatabaseType.postgres,
|
|
11
|
+
// "dummy_db_url",
|
|
12
|
+
// {},
|
|
13
|
+
// undefined
|
|
14
|
+
// );
|
|
15
|
+
// quill.targetConnection.query = jest.fn().mockResolvedValue([]);
|
|
16
|
+
// });
|
|
17
|
+
// describe("query", () => {
|
|
18
|
+
// it("return nothing when suppling no queries", () => {
|
|
19
|
+
// const metadata = {
|
|
20
|
+
// task: "test",
|
|
21
|
+
// queries: [],
|
|
22
|
+
// };
|
|
23
|
+
// const result = quill.query({
|
|
24
|
+
// orgId: "dummy",
|
|
25
|
+
// metadata,
|
|
26
|
+
// });
|
|
27
|
+
// expect(result).resolves.toEqual([]);
|
|
28
|
+
// });
|
|
29
|
+
// it("returns an error for the improper query", () => {
|
|
30
|
+
// const metadata = {
|
|
31
|
+
// task: "test",
|
|
32
|
+
// queries: ["SELECT * FROM test"],
|
|
33
|
+
// };
|
|
34
|
+
// const result = quill.query({
|
|
35
|
+
// orgId: "dummy",
|
|
36
|
+
// metadata,
|
|
37
|
+
// });
|
|
38
|
+
// });
|
|
39
|
+
// });
|
|
40
|
+
// // Add more test cases as needed
|
|
41
|
+
// });
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@ import { createClient } from "redis";
|
|
|
5
5
|
import { isSuperset } from "../utils/Error";
|
|
6
6
|
import {
|
|
7
7
|
DatabaseConnection,
|
|
8
|
-
|
|
8
|
+
QuillDatabaseType,
|
|
9
9
|
connectToDatabase,
|
|
10
10
|
disconnectFromDatabase,
|
|
11
11
|
runQueryByDatabase,
|
|
@@ -29,14 +29,14 @@ class PgError extends Error {
|
|
|
29
29
|
const DEFAULT_CACHE_TTL = 24 * 60 * 60;
|
|
30
30
|
|
|
31
31
|
export class CachedConnection {
|
|
32
|
-
public databaseType:
|
|
32
|
+
public databaseType: QuillDatabaseType;
|
|
33
33
|
public pool: DatabaseConnection;
|
|
34
34
|
public orgId: any;
|
|
35
35
|
public ttl: number;
|
|
36
36
|
public cache: Mapable | null;
|
|
37
37
|
|
|
38
38
|
constructor(
|
|
39
|
-
databaseType:
|
|
39
|
+
databaseType: QuillDatabaseType,
|
|
40
40
|
config: any,
|
|
41
41
|
cacheConfig: Partial<CacheCredentials> = {}
|
|
42
42
|
) {
|
package/src/db/DatabaseHelper.ts
CHANGED
|
@@ -51,8 +51,7 @@ import {
|
|
|
51
51
|
getSchemasMysql,
|
|
52
52
|
} from "./Mysql";
|
|
53
53
|
|
|
54
|
-
export enum
|
|
55
|
-
postgres = "postgres",
|
|
54
|
+
export enum QuillDatabaseType {
|
|
56
55
|
postgresql = "postgresql",
|
|
57
56
|
snowflake = "snowflake",
|
|
58
57
|
bigquery = "bigquery",
|
|
@@ -72,7 +71,7 @@ export interface QuillQueryResults {
|
|
|
72
71
|
}
|
|
73
72
|
|
|
74
73
|
export function getDatabaseCredentials(
|
|
75
|
-
databaseType:
|
|
74
|
+
databaseType: QuillDatabaseType,
|
|
76
75
|
connectionString: string
|
|
77
76
|
):
|
|
78
77
|
| PostgresConnectionConfig
|
|
@@ -97,7 +96,7 @@ export function getDatabaseCredentials(
|
|
|
97
96
|
}
|
|
98
97
|
|
|
99
98
|
export function connectToDatabase(
|
|
100
|
-
databaseType:
|
|
99
|
+
databaseType: QuillDatabaseType,
|
|
101
100
|
config:
|
|
102
101
|
| PostgresConnectionConfig
|
|
103
102
|
| SnowflakeConnectionConfig
|
|
@@ -121,7 +120,7 @@ export function connectToDatabase(
|
|
|
121
120
|
}
|
|
122
121
|
|
|
123
122
|
export function runQueryByDatabase(
|
|
124
|
-
databaseType:
|
|
123
|
+
databaseType: QuillDatabaseType,
|
|
125
124
|
connection: DatabaseConnection,
|
|
126
125
|
sql: string
|
|
127
126
|
): Promise<QuillQueryResults> | undefined {
|
|
@@ -142,7 +141,7 @@ export function runQueryByDatabase(
|
|
|
142
141
|
}
|
|
143
142
|
|
|
144
143
|
export function disconnectFromDatabase(
|
|
145
|
-
databaseType:
|
|
144
|
+
databaseType: QuillDatabaseType,
|
|
146
145
|
database: DatabaseConnection
|
|
147
146
|
) {
|
|
148
147
|
switch (databaseType.toLowerCase()) {
|
|
@@ -162,7 +161,7 @@ export function disconnectFromDatabase(
|
|
|
162
161
|
}
|
|
163
162
|
|
|
164
163
|
export async function getSchemasByDatabase(
|
|
165
|
-
databaseType:
|
|
164
|
+
databaseType: QuillDatabaseType,
|
|
166
165
|
connection: DatabaseConnection
|
|
167
166
|
): Promise<string[] | undefined> {
|
|
168
167
|
switch (databaseType.toLowerCase()) {
|
|
@@ -183,7 +182,7 @@ export async function getSchemasByDatabase(
|
|
|
183
182
|
|
|
184
183
|
// INFORMATION SCHEMA SELECTS
|
|
185
184
|
export async function getTablesBySchemaByDatabase(
|
|
186
|
-
databaseType:
|
|
185
|
+
databaseType: QuillDatabaseType,
|
|
187
186
|
connection: DatabaseConnection,
|
|
188
187
|
schemaName: string | string[]
|
|
189
188
|
): Promise<string[] | { tableName: string; schemaName: string }[] | undefined> {
|
|
@@ -220,7 +219,7 @@ export async function getTablesBySchemaByDatabase(
|
|
|
220
219
|
|
|
221
220
|
// INFORMATION SCHEMA SELECTS
|
|
222
221
|
export async function getColumnsByTableByDatabase(
|
|
223
|
-
databaseType:
|
|
222
|
+
databaseType: QuillDatabaseType,
|
|
224
223
|
connection: DatabaseConnection,
|
|
225
224
|
schemaName: string,
|
|
226
225
|
tableName: string
|
|
@@ -262,7 +261,7 @@ export async function getColumnsByTableByDatabase(
|
|
|
262
261
|
}
|
|
263
262
|
|
|
264
263
|
export async function getForiegnKeysByDatabase(
|
|
265
|
-
databaseType:
|
|
264
|
+
databaseType: QuillDatabaseType,
|
|
266
265
|
connection: DatabaseConnection,
|
|
267
266
|
schemaName: string,
|
|
268
267
|
tableName: string,
|
|
@@ -310,7 +309,7 @@ export async function getForiegnKeysByDatabase(
|
|
|
310
309
|
}
|
|
311
310
|
|
|
312
311
|
export function getColumnInfoBySchemaByDatabase(
|
|
313
|
-
databaseType:
|
|
312
|
+
databaseType: QuillDatabaseType,
|
|
314
313
|
connection: DatabaseConnection,
|
|
315
314
|
schemaName: string,
|
|
316
315
|
tables: string[] | { tableName: string; schemaName: string }[]
|
package/src/index.ts
CHANGED
|
@@ -10,7 +10,7 @@ import axios from "axios";
|
|
|
10
10
|
import "dotenv/config";
|
|
11
11
|
import { mapQueries, removeFields } from "./utils/RunQueryProcesses";
|
|
12
12
|
import {
|
|
13
|
-
|
|
13
|
+
QuillDatabaseType,
|
|
14
14
|
connectToDatabase,
|
|
15
15
|
getColumnInfoBySchemaByDatabase,
|
|
16
16
|
getColumnsByTableByDatabase,
|
|
@@ -31,6 +31,14 @@ const HOST =
|
|
|
31
31
|
* Quill - Fullstack API Platform for Dashboards and Reporting.
|
|
32
32
|
*/
|
|
33
33
|
|
|
34
|
+
export interface QuillQueryResult {
|
|
35
|
+
data?: any;
|
|
36
|
+
status: string;
|
|
37
|
+
error?: string;
|
|
38
|
+
queries?: { rows: any[]; fields: any[] };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export type DatabaseType = QuillDatabaseType;
|
|
34
42
|
export default class QuillClass {
|
|
35
43
|
// Configure cached connection pools with the given config.
|
|
36
44
|
public targetConnection;
|
|
@@ -41,17 +49,25 @@ export default class QuillClass {
|
|
|
41
49
|
};
|
|
42
50
|
};
|
|
43
51
|
|
|
44
|
-
constructor(
|
|
45
|
-
privateKey: string
|
|
46
|
-
databaseType: DatabaseType
|
|
47
|
-
databaseConnectionString?: string
|
|
48
|
-
|
|
49
|
-
cache
|
|
50
|
-
metadataServerURL?: string
|
|
51
|
-
) {
|
|
52
|
+
constructor(data: {
|
|
53
|
+
privateKey: string;
|
|
54
|
+
databaseType: DatabaseType;
|
|
55
|
+
databaseConnectionString?: string;
|
|
56
|
+
databaseConfig?: any;
|
|
57
|
+
cache?: Partial<CacheCredentials>;
|
|
58
|
+
metadataServerURL?: string;
|
|
59
|
+
}) {
|
|
60
|
+
const {
|
|
61
|
+
privateKey,
|
|
62
|
+
databaseType,
|
|
63
|
+
databaseConnectionString,
|
|
64
|
+
databaseConfig,
|
|
65
|
+
cache,
|
|
66
|
+
metadataServerURL,
|
|
67
|
+
} = data;
|
|
52
68
|
this.baseUrl = metadataServerURL ? metadataServerURL : HOST;
|
|
53
69
|
this.config = { headers: { Authorization: `Bearer ${privateKey}` } };
|
|
54
|
-
let credentials =
|
|
70
|
+
let credentials = databaseConfig;
|
|
55
71
|
if (databaseConnectionString) {
|
|
56
72
|
credentials = getDatabaseCredentials(
|
|
57
73
|
databaseType,
|
|
@@ -61,11 +77,14 @@ export default class QuillClass {
|
|
|
61
77
|
this.targetConnection = new CachedConnection(
|
|
62
78
|
databaseType,
|
|
63
79
|
credentials,
|
|
64
|
-
cache
|
|
80
|
+
cache || {}
|
|
65
81
|
);
|
|
66
82
|
}
|
|
67
83
|
|
|
68
|
-
public async query({
|
|
84
|
+
public async query({
|
|
85
|
+
orgId,
|
|
86
|
+
metadata,
|
|
87
|
+
}: QuillQueryParams): Promise<QuillQueryResult> {
|
|
69
88
|
this.targetConnection.orgId = orgId;
|
|
70
89
|
try {
|
|
71
90
|
const preQueryResults = metadata.preQueries
|
|
@@ -256,14 +275,14 @@ const Quill = ({
|
|
|
256
275
|
databaseConfig: any;
|
|
257
276
|
metadataServerURL?: string;
|
|
258
277
|
}) => {
|
|
259
|
-
return new QuillClass(
|
|
278
|
+
return new QuillClass({
|
|
260
279
|
privateKey,
|
|
261
280
|
databaseType,
|
|
262
281
|
databaseConnectionString,
|
|
263
282
|
databaseConfig,
|
|
264
283
|
cache,
|
|
265
|
-
metadataServerURL
|
|
266
|
-
);
|
|
284
|
+
metadataServerURL,
|
|
285
|
+
});
|
|
267
286
|
};
|
|
268
287
|
|
|
269
288
|
module.exports = Quill;
|
|
@@ -278,3 +297,4 @@ module.exports.getColumnInfoBySchemaByDatabase =
|
|
|
278
297
|
getColumnInfoBySchemaByDatabase;
|
|
279
298
|
module.exports.connectToDatabase = connectToDatabase;
|
|
280
299
|
module.exports.runQueryByDatabase = runQueryByDatabase;
|
|
300
|
+
module.exports.DatabaseType = QuillDatabaseType;
|
package/src/index.uspec.ts
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
import Quill from ".";
|
|
2
|
-
import { DatabaseType } from "./db/DatabaseHelper";
|
|
1
|
+
// import Quill from ".";
|
|
2
|
+
// import { DatabaseType } from "./db/DatabaseHelper";
|
|
3
3
|
|
|
4
|
-
jest.mock(".");
|
|
4
|
+
// jest.mock(".");
|
|
5
5
|
|
|
6
|
-
describe("Quill", () => {
|
|
7
|
-
|
|
6
|
+
// describe("Quill", () => {
|
|
7
|
+
// let quill: Quill;
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
9
|
+
// beforeEach(() => {
|
|
10
|
+
// quill = new Quill(
|
|
11
|
+
// "dummy_private_key",
|
|
12
|
+
// DatabaseType.postgres,
|
|
13
|
+
// "dummy_db_url",
|
|
14
|
+
// {},
|
|
15
|
+
// undefined
|
|
16
|
+
// );
|
|
17
|
+
// quill.targetConnection.query = jest.fn().mockResolvedValue([]);
|
|
18
|
+
// });
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
20
|
+
// describe("query", () => {
|
|
21
|
+
// it("return nothing when suppling no queries", () => {
|
|
22
|
+
// const metadata = {
|
|
23
|
+
// task: "test",
|
|
24
|
+
// queries: [],
|
|
25
|
+
// };
|
|
26
|
+
// const result = quill.query({
|
|
27
|
+
// orgId: "dummy",
|
|
28
|
+
// metadata,
|
|
29
|
+
// });
|
|
30
|
+
// expect(result).resolves.toEqual([]);
|
|
31
|
+
// });
|
|
32
|
+
// it("returns an error for the improper query", () => {
|
|
33
|
+
// const metadata = {
|
|
34
|
+
// task: "test",
|
|
35
|
+
// queries: ["SELECT * FROM test"],
|
|
36
|
+
// };
|
|
37
|
+
// const result = quill.query({
|
|
38
|
+
// orgId: "dummy",
|
|
39
|
+
// metadata,
|
|
40
|
+
// });
|
|
41
|
+
// });
|
|
42
|
+
// });
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
});
|
|
44
|
+
// // Add more test cases as needed
|
|
45
|
+
// });
|