@quillsql/node 0.5.9 → 0.6.1
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/assets/pgtypes.js +1391 -1391
- package/dist/db/BigQuery.js +1 -0
- package/dist/db/CachedConnection.d.ts +11 -6
- package/dist/db/CachedConnection.js +12 -26
- package/dist/db/DatabaseHelper.d.ts +3 -1
- package/dist/db/DatabaseHelper.js +21 -2
- package/dist/db/Postgres.js +28 -21
- package/dist/db/Snowflake.js +2 -2
- package/dist/index.d.ts +4 -3
- package/dist/index.ispec.js +3 -0
- package/dist/index.js +21 -7
- package/dist/index.uspec.js +3 -0
- package/dist/models/Cache.d.ts +1 -1
- package/dist/utils/Error.d.ts +1 -0
- package/dist/utils/Error.js +12 -3
- package/dist/utils/RunQueryProcesses.d.ts +6 -0
- package/eslint.config.mjs +16 -0
- package/examples/mysql-node/app.ts +62 -0
- package/examples/node-server/app.ts +8 -9
- package/package.json +16 -3
- package/src/assets/pgtypes.ts +1392 -1392
- package/src/db/BigQuery.ts +10 -10
- package/src/db/CachedConnection.ts +27 -37
- package/src/db/DatabaseHelper.ts +58 -33
- package/src/db/Mysql.ts +0 -2
- package/src/db/Postgres.ts +38 -40
- package/src/db/Snowflake.ts +14 -15
- package/src/index.ispec.ts +4 -0
- package/src/index.ts +30 -11
- package/src/index.uspec.ts +4 -0
- package/src/models/Cache.ts +3 -3
- package/src/utils/Error.ts +18 -4
- package/src/utils/RunQueryProcesses.ts +3 -3
- package/src/utils/textProcessing.ts +1 -1
package/dist/db/BigQuery.js
CHANGED
|
@@ -164,6 +164,7 @@ function convertBigQueryTypeToPostgresOID(type) {
|
|
|
164
164
|
FLOAT: 700,
|
|
165
165
|
TIMESTAMP: 1114,
|
|
166
166
|
DATE: 1082,
|
|
167
|
+
BOOL: 16,
|
|
167
168
|
};
|
|
168
169
|
const postgresType = typeToOidMap[type.toUpperCase()] || "VARCHAR"; // Default to 'text' if the type is not recognized
|
|
169
170
|
return typeToOidMap[postgresType] || 1043; // Default to OID for 'text' if the type is not recognized
|
|
@@ -1,14 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Mappable, CacheCredentials } from "../models/Cache";
|
|
2
2
|
import { DatabaseConnection } from "./DatabaseHelper";
|
|
3
|
+
import { PostgresConnectionConfig } from "./Postgres";
|
|
4
|
+
import { SnowflakeConnectionConfig } from "./Snowflake";
|
|
5
|
+
import { BigQueryConfig } from "./BigQuery";
|
|
6
|
+
import { MysqlConnectionConfig } from "./Mysql";
|
|
3
7
|
export declare class CachedConnection {
|
|
4
8
|
databaseType: "postgresql" | "snowflake" | "bigquery" | "mysql";
|
|
5
|
-
pool: DatabaseConnection
|
|
9
|
+
readonly pool: DatabaseConnection;
|
|
6
10
|
orgId: any;
|
|
7
11
|
ttl: number;
|
|
8
|
-
cache:
|
|
9
|
-
private
|
|
10
|
-
|
|
11
|
-
|
|
12
|
+
cache: Mappable | null;
|
|
13
|
+
private _isClosed;
|
|
14
|
+
get isClosed(): boolean;
|
|
15
|
+
constructor(databaseType: "postgresql" | "snowflake" | "bigquery" | "mysql", config: PostgresConnectionConfig | SnowflakeConnectionConfig | BigQueryConfig | MysqlConnectionConfig, cacheConfig?: Partial<CacheCredentials>);
|
|
16
|
+
query(text: string): Promise<any>;
|
|
12
17
|
/**
|
|
13
18
|
* Configures and returns a cache instance or null if none could be created.
|
|
14
19
|
*/
|
|
@@ -13,30 +13,26 @@ exports.CachedConnection = void 0;
|
|
|
13
13
|
const redis_1 = require("redis");
|
|
14
14
|
const Error_1 = require("../utils/Error");
|
|
15
15
|
const DatabaseHelper_1 = require("./DatabaseHelper");
|
|
16
|
-
class PgError extends Error {
|
|
17
|
-
// Add other properties if needed
|
|
18
|
-
constructor(detail, hint, position) {
|
|
19
|
-
super();
|
|
20
|
-
this.detail = detail;
|
|
21
|
-
this.hint = hint;
|
|
22
|
-
this.position = position;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
16
|
/** The TTL for new cache entries (default: 1h) */
|
|
26
17
|
const DEFAULT_CACHE_TTL = 24 * 60 * 60;
|
|
27
18
|
class CachedConnection {
|
|
19
|
+
get isClosed() {
|
|
20
|
+
return this._isClosed;
|
|
21
|
+
}
|
|
28
22
|
constructor(databaseType, config, cacheConfig = {}) {
|
|
29
23
|
var _a;
|
|
24
|
+
this._isClosed = false;
|
|
30
25
|
this.databaseType = databaseType;
|
|
31
26
|
this.pool = (0, DatabaseHelper_1.connectToDatabase)(databaseType, config);
|
|
32
|
-
this.config = config;
|
|
33
27
|
this.ttl = (_a = cacheConfig === null || cacheConfig === void 0 ? void 0 : cacheConfig.ttl) !== null && _a !== void 0 ? _a : DEFAULT_CACHE_TTL;
|
|
34
28
|
this.cache = this.getCache(cacheConfig);
|
|
35
29
|
}
|
|
36
|
-
query(text
|
|
30
|
+
query(text) {
|
|
37
31
|
return __awaiter(this, void 0, void 0, function* () {
|
|
38
32
|
try {
|
|
39
|
-
|
|
33
|
+
if (this.isClosed) {
|
|
34
|
+
throw new Error("Connection is closed");
|
|
35
|
+
}
|
|
40
36
|
if (!this.cache) {
|
|
41
37
|
return yield (0, DatabaseHelper_1.runQueryByDatabase)(this.databaseType, this.pool, text);
|
|
42
38
|
}
|
|
@@ -53,18 +49,13 @@ class CachedConnection {
|
|
|
53
49
|
}
|
|
54
50
|
}
|
|
55
51
|
catch (err) {
|
|
56
|
-
if ((0, Error_1.isSuperset)(err, PgError)) {
|
|
57
|
-
throw new PgError(err.detail, err.hint, err.position);
|
|
52
|
+
if ((0, Error_1.isSuperset)(err, Error_1.PgError)) {
|
|
53
|
+
throw new Error_1.PgError(err.message, err.detail, err.hint, err.position);
|
|
58
54
|
}
|
|
59
55
|
else if (err instanceof Error) {
|
|
60
56
|
throw new Error(err.message);
|
|
61
57
|
}
|
|
62
58
|
}
|
|
63
|
-
finally {
|
|
64
|
-
if (this.databaseType.toLowerCase() === "mysql") {
|
|
65
|
-
this.close();
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
59
|
});
|
|
69
60
|
}
|
|
70
61
|
/**
|
|
@@ -80,17 +71,12 @@ class CachedConnection {
|
|
|
80
71
|
return null;
|
|
81
72
|
}
|
|
82
73
|
getPool() {
|
|
83
|
-
if (!this.pool) {
|
|
84
|
-
this.pool = (0, DatabaseHelper_1.connectToDatabase)(this.databaseType, this.config);
|
|
85
|
-
}
|
|
86
74
|
return this.pool;
|
|
87
75
|
}
|
|
88
76
|
close() {
|
|
89
77
|
return __awaiter(this, void 0, void 0, function* () {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
this.pool = null;
|
|
93
|
-
}
|
|
78
|
+
(0, DatabaseHelper_1.disconnectFromDatabase)(this.databaseType, this.pool);
|
|
79
|
+
this._isClosed = true;
|
|
94
80
|
});
|
|
95
81
|
}
|
|
96
82
|
}
|
|
@@ -16,9 +16,11 @@ export interface QuillQueryResults {
|
|
|
16
16
|
[fieldName: string]: any;
|
|
17
17
|
}[];
|
|
18
18
|
}
|
|
19
|
-
export declare function getDatabaseCredentials(databaseType: "postgresql" | "snowflake" | "bigquery" | "mysql", connectionString: string): PostgresConnectionConfig | SnowflakeConnectionConfig | BigQueryConfig | MysqlConnectionConfig
|
|
19
|
+
export declare function getDatabaseCredentials(databaseType: "postgresql" | "snowflake" | "bigquery" | "mysql", connectionString: string): PostgresConnectionConfig | SnowflakeConnectionConfig | BigQueryConfig | MysqlConnectionConfig;
|
|
20
20
|
export declare function connectToDatabase(databaseType: "postgresql" | "snowflake" | "bigquery" | "mysql", config: PostgresConnectionConfig | SnowflakeConnectionConfig | BigQueryConfig | MysqlConnectionConfig): DatabaseConnection;
|
|
21
|
+
export declare function withConnection<T>(databaseType: "postgresql" | "snowflake" | "bigquery" | "mysql", connectionString: string, callback: (connection: DatabaseConnection) => T): Promise<T>;
|
|
21
22
|
export declare function runQueryByDatabase(databaseType: "postgresql" | "snowflake" | "bigquery" | "mysql", connection: DatabaseConnection, sql: string): Promise<QuillQueryResults> | undefined;
|
|
23
|
+
export declare function connectAndRunQuery(databaseType: "postgresql" | "snowflake" | "bigquery" | "mysql", connectionString: string, sql: string): Promise<QuillQueryResults | undefined>;
|
|
22
24
|
export declare function disconnectFromDatabase(databaseType: "postgresql" | "snowflake" | "bigquery" | "mysql", database: DatabaseConnection): void | Promise<void>;
|
|
23
25
|
export declare function getSchemasByDatabase(databaseType: "postgresql" | "snowflake" | "bigquery" | "mysql", connection: DatabaseConnection): Promise<string[] | undefined>;
|
|
24
26
|
export declare function getTablesBySchemaByDatabase(databaseType: "postgresql" | "snowflake" | "bigquery" | "mysql", connection: DatabaseConnection, schemaName: string | string[]): Promise<string[] | {
|
|
@@ -9,7 +9,7 @@ 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 = void 0;
|
|
12
|
+
exports.getColumnInfoBySchemaByDatabase = exports.getForiegnKeysByDatabase = exports.getColumnsByTableByDatabase = exports.getTablesBySchemaByDatabase = exports.getSchemasByDatabase = exports.disconnectFromDatabase = exports.connectAndRunQuery = exports.runQueryByDatabase = exports.withConnection = exports.connectToDatabase = exports.getDatabaseCredentials = void 0;
|
|
13
13
|
const Postgres_1 = require("./Postgres");
|
|
14
14
|
const Snowflake_1 = require("./Snowflake");
|
|
15
15
|
const BigQuery_1 = require("./BigQuery");
|
|
@@ -27,7 +27,7 @@ function getDatabaseCredentials(databaseType, connectionString) {
|
|
|
27
27
|
case "mysql":
|
|
28
28
|
return (0, Mysql_1.formatMysqlConfig)(connectionString);
|
|
29
29
|
default:
|
|
30
|
-
|
|
30
|
+
throw new Error("Invalid database type");
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
exports.getDatabaseCredentials = getDatabaseCredentials;
|
|
@@ -48,6 +48,19 @@ function connectToDatabase(databaseType, config) {
|
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
exports.connectToDatabase = connectToDatabase;
|
|
51
|
+
function withConnection(databaseType, connectionString, callback) {
|
|
52
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
const config = getDatabaseCredentials(databaseType, connectionString);
|
|
54
|
+
const connection = connectToDatabase(databaseType, config);
|
|
55
|
+
try {
|
|
56
|
+
return yield callback(connection);
|
|
57
|
+
}
|
|
58
|
+
finally {
|
|
59
|
+
yield disconnectFromDatabase(databaseType, connection);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
exports.withConnection = withConnection;
|
|
51
64
|
function runQueryByDatabase(databaseType, connection, sql) {
|
|
52
65
|
switch (databaseType.toLowerCase()) {
|
|
53
66
|
case "postgres":
|
|
@@ -65,6 +78,12 @@ function runQueryByDatabase(databaseType, connection, sql) {
|
|
|
65
78
|
}
|
|
66
79
|
}
|
|
67
80
|
exports.runQueryByDatabase = runQueryByDatabase;
|
|
81
|
+
function connectAndRunQuery(databaseType, connectionString, sql) {
|
|
82
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
+
return withConnection(databaseType, connectionString, (connection) => __awaiter(this, void 0, void 0, function* () { return yield runQueryByDatabase(databaseType, connection, sql); }));
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
exports.connectAndRunQuery = connectAndRunQuery;
|
|
68
87
|
function disconnectFromDatabase(databaseType, database) {
|
|
69
88
|
switch (databaseType.toLowerCase()) {
|
|
70
89
|
case "postgres":
|
package/dist/db/Postgres.js
CHANGED
|
@@ -138,24 +138,31 @@ function formatPostgresConfig(connectionString) {
|
|
|
138
138
|
}
|
|
139
139
|
exports.formatPostgresConfig = formatPostgresConfig;
|
|
140
140
|
// CURRENTLY UNUSED BUT MAYBE USEFUL IN THE FUTURE
|
|
141
|
-
function getSslConfig(client)
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
141
|
+
// function getSslConfig(client: Client):
|
|
142
|
+
// | {
|
|
143
|
+
// rejectUnauthorized: false;
|
|
144
|
+
// ca?: string;
|
|
145
|
+
// key?: string;
|
|
146
|
+
// cert?: string;
|
|
147
|
+
// }
|
|
148
|
+
// | undefined {
|
|
149
|
+
// if (!client.useSsl) {
|
|
150
|
+
// return undefined;
|
|
151
|
+
// }
|
|
152
|
+
// if (client.serverCa && client.clientKey && client.clientCert) {
|
|
153
|
+
// return {
|
|
154
|
+
// rejectUnauthorized: false,
|
|
155
|
+
// ca: client.serverCa,
|
|
156
|
+
// key: client.clientKey,
|
|
157
|
+
// cert: client.clientCert,
|
|
158
|
+
// };
|
|
159
|
+
// }
|
|
160
|
+
// if (client.serverCa) {
|
|
161
|
+
// return {
|
|
162
|
+
// rejectUnauthorized: false,
|
|
163
|
+
// ca: client.serverCa,
|
|
164
|
+
// };
|
|
165
|
+
// }
|
|
166
|
+
// // if using ssl with no certificates
|
|
167
|
+
// return { rejectUnauthorized: false };
|
|
168
|
+
// }
|
package/dist/db/Snowflake.js
CHANGED
|
@@ -116,7 +116,7 @@ function connectToSnowflake(config) {
|
|
|
116
116
|
exports.connectToSnowflake = connectToSnowflake;
|
|
117
117
|
function disconnectFromSnowflake(connection) {
|
|
118
118
|
return __awaiter(this, void 0, void 0, function* () {
|
|
119
|
-
connection.destroy((err
|
|
119
|
+
connection.destroy((err) => {
|
|
120
120
|
if (err) {
|
|
121
121
|
console.error(`Failed to disconnect from Snowflake: ${err.message}`);
|
|
122
122
|
}
|
|
@@ -126,7 +126,7 @@ function disconnectFromSnowflake(connection) {
|
|
|
126
126
|
exports.disconnectFromSnowflake = disconnectFromSnowflake;
|
|
127
127
|
function getForeignKeysSnowflake(connection, schemaName, tableName, primaryKey) {
|
|
128
128
|
return __awaiter(this, void 0, void 0, function* () {
|
|
129
|
-
|
|
129
|
+
const depluralizedTableName = (0, textProcessing_1.depluralize)(tableName);
|
|
130
130
|
let sql = `SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS
|
|
131
131
|
WHERE TABLE_SCHEMA = '${schemaName}'
|
|
132
132
|
AND TABLE_NAME = '${schemaName}'
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import { CacheCredentials } from "./models/Cache";
|
|
2
3
|
import { QuillQueryParams } from "./models/Quill";
|
|
3
|
-
import { CachedConnection } from "./db/CachedConnection";
|
|
4
4
|
import "dotenv/config";
|
|
5
5
|
/**
|
|
6
6
|
* Quill - Fullstack API Platform for Dashboards and Reporting.
|
|
@@ -20,8 +20,8 @@ export declare enum DatabaseType {
|
|
|
20
20
|
bigquery = "bigquery",
|
|
21
21
|
mysql = "mysql"
|
|
22
22
|
}
|
|
23
|
-
export declare class Quill {
|
|
24
|
-
targetConnection
|
|
23
|
+
export declare class Quill implements AsyncDisposable {
|
|
24
|
+
private targetConnection;
|
|
25
25
|
private baseUrl;
|
|
26
26
|
private config;
|
|
27
27
|
constructor(data: {
|
|
@@ -35,6 +35,7 @@ export declare class Quill {
|
|
|
35
35
|
query({ orgId, metadata, }: QuillQueryParams): Promise<QuillQueryResult>;
|
|
36
36
|
private runQueries;
|
|
37
37
|
private postQuill;
|
|
38
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
38
39
|
close(): Promise<void>;
|
|
39
40
|
}
|
|
40
41
|
export { QuillQueryParams as QuillRequest } from "./models/Quill";
|
package/dist/index.ispec.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -41,10 +41,13 @@ class Quill {
|
|
|
41
41
|
this.targetConnection = new CachedConnection_1.CachedConnection(databaseType, credentials, cache || {});
|
|
42
42
|
}
|
|
43
43
|
query({ orgId, metadata, }) {
|
|
44
|
-
var _a, _b;
|
|
44
|
+
var _a, _b, _c, _d, _e;
|
|
45
45
|
return __awaiter(this, void 0, void 0, function* () {
|
|
46
46
|
this.targetConnection.orgId = orgId;
|
|
47
47
|
let responseMetadata = {};
|
|
48
|
+
if (!metadata.task) {
|
|
49
|
+
return { error: "Missing task.", status: "error", data: {} };
|
|
50
|
+
}
|
|
48
51
|
try {
|
|
49
52
|
const preQueryResults = metadata.preQueries
|
|
50
53
|
? yield this.runQueries(metadata.preQueries, this.targetConnection.databaseType, metadata.databaseType, metadata.runQueryConfig)
|
|
@@ -57,7 +60,11 @@ class Quill {
|
|
|
57
60
|
}
|
|
58
61
|
const response = yield this.postQuill(metadata.task, Object.assign(Object.assign(Object.assign({}, metadata), preQueryResults), { orgId, viewQuery: metadata.preQueries ? metadata.preQueries[0] : undefined }));
|
|
59
62
|
if (response.error) {
|
|
60
|
-
return {
|
|
63
|
+
return {
|
|
64
|
+
status: "error",
|
|
65
|
+
error: response.error,
|
|
66
|
+
data: response.metadata || {},
|
|
67
|
+
};
|
|
61
68
|
}
|
|
62
69
|
// if there is no metadata object in the response, create one
|
|
63
70
|
if (response.metadata) {
|
|
@@ -92,8 +99,8 @@ class Quill {
|
|
|
92
99
|
catch (err) {
|
|
93
100
|
return {
|
|
94
101
|
status: "error",
|
|
95
|
-
error: err.message,
|
|
96
|
-
data: responseMetadata,
|
|
102
|
+
error: (_e = (_d = (_c = err.response) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.error) !== null && _e !== void 0 ? _e : err.message,
|
|
103
|
+
data: responseMetadata || {},
|
|
97
104
|
};
|
|
98
105
|
}
|
|
99
106
|
});
|
|
@@ -152,7 +159,9 @@ class Quill {
|
|
|
152
159
|
return Object.assign(Object.assign({}, table), { columns: columns, rows: queryResult.rows });
|
|
153
160
|
}
|
|
154
161
|
catch (err) {
|
|
155
|
-
return Object.assign(Object.assign({}, table), { error:
|
|
162
|
+
return Object.assign(Object.assign({}, table), { error: err.message
|
|
163
|
+
? `Error fetching columns: ${err.message}`
|
|
164
|
+
: "Error fetching columns" });
|
|
156
165
|
}
|
|
157
166
|
})));
|
|
158
167
|
results = Object.assign(Object.assign({}, results), { queryResults });
|
|
@@ -169,7 +178,6 @@ class Quill {
|
|
|
169
178
|
else if (runQueryConfig === null || runQueryConfig === void 0 ? void 0 : runQueryConfig.getTables) {
|
|
170
179
|
const queryResult = yield (0, DatabaseHelper_1.getTablesBySchemaByDatabase)(this.targetConnection.databaseType, this.targetConnection.getPool(), runQueryConfig.schemaNames || runQueryConfig.schema);
|
|
171
180
|
const schemaInfo = yield (0, DatabaseHelper_1.getColumnInfoBySchemaByDatabase)(this.targetConnection.databaseType, this.targetConnection.getPool(), runQueryConfig.schema, queryResult);
|
|
172
|
-
this.targetConnection.close();
|
|
173
181
|
return schemaInfo;
|
|
174
182
|
}
|
|
175
183
|
else {
|
|
@@ -212,6 +220,11 @@ class Quill {
|
|
|
212
220
|
return response.data;
|
|
213
221
|
});
|
|
214
222
|
}
|
|
223
|
+
[Symbol.asyncDispose]() {
|
|
224
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
225
|
+
yield this.close();
|
|
226
|
+
});
|
|
227
|
+
}
|
|
215
228
|
close() {
|
|
216
229
|
return __awaiter(this, void 0, void 0, function* () {
|
|
217
230
|
yield this.targetConnection.close();
|
|
@@ -231,6 +244,8 @@ const requireQuill = ({ privateKey, databaseConnectionString, databaseConfig, ca
|
|
|
231
244
|
};
|
|
232
245
|
module.exports = requireQuill;
|
|
233
246
|
module.exports.default = requireQuill;
|
|
247
|
+
module.exports.withConnection = DatabaseHelper_1.withConnection;
|
|
248
|
+
module.exports.connectAndRunQuery = DatabaseHelper_1.connectAndRunQuery;
|
|
234
249
|
module.exports.Quill = Quill;
|
|
235
250
|
module.exports.getTablesBySchemaByDatabase = DatabaseHelper_1.getTablesBySchemaByDatabase;
|
|
236
251
|
module.exports.getDatabaseCredentials = DatabaseHelper_1.getDatabaseCredentials;
|
|
@@ -239,6 +254,5 @@ module.exports.getForiegnKeysByDatabase = DatabaseHelper_1.getForiegnKeysByDatab
|
|
|
239
254
|
module.exports.getSchemasByDatabase = DatabaseHelper_1.getSchemasByDatabase;
|
|
240
255
|
module.exports.getColumnInfoBySchemaByDatabase =
|
|
241
256
|
DatabaseHelper_1.getColumnInfoBySchemaByDatabase;
|
|
242
|
-
module.exports.connectToDatabase = DatabaseHelper_1.connectToDatabase;
|
|
243
257
|
module.exports.runQueryByDatabase = DatabaseHelper_1.runQueryByDatabase;
|
|
244
258
|
module.exports.DatabaseType = DatabaseType;
|
package/dist/index.uspec.js
CHANGED
|
@@ -14,6 +14,9 @@
|
|
|
14
14
|
// );
|
|
15
15
|
// quill.targetConnection.query = jest.fn().mockResolvedValue([]);
|
|
16
16
|
// });
|
|
17
|
+
// afterEach(async () => {
|
|
18
|
+
// await quill.close();
|
|
19
|
+
// });
|
|
17
20
|
// describe("query", () => {
|
|
18
21
|
// it("return nothing when suppling no queries", () => {
|
|
19
22
|
// const metadata = {
|
package/dist/models/Cache.d.ts
CHANGED
package/dist/utils/Error.d.ts
CHANGED
|
@@ -3,5 +3,6 @@ export declare class PgError extends Error {
|
|
|
3
3
|
detail?: string;
|
|
4
4
|
hint?: string;
|
|
5
5
|
position?: string;
|
|
6
|
+
constructor(message: string, detail?: string, hint?: string, position?: string, code?: string);
|
|
6
7
|
}
|
|
7
8
|
export declare function isSuperset(obj: any, baseClass: any): boolean;
|
package/dist/utils/Error.js
CHANGED
|
@@ -2,14 +2,23 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isSuperset = exports.PgError = void 0;
|
|
4
4
|
class PgError extends Error {
|
|
5
|
+
// Add other properties if needed
|
|
6
|
+
constructor(message, detail, hint, position, code) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.code = code;
|
|
9
|
+
this.detail = detail;
|
|
10
|
+
this.hint = hint;
|
|
11
|
+
this.position = position;
|
|
12
|
+
}
|
|
5
13
|
}
|
|
6
14
|
exports.PgError = PgError;
|
|
7
15
|
function isSuperset(obj, baseClass) {
|
|
8
|
-
// Get the property names of the base class
|
|
9
|
-
const
|
|
16
|
+
// Get the property names of the base class instance
|
|
17
|
+
const baseInstance = new baseClass();
|
|
18
|
+
const baseProps = Object.keys(baseInstance);
|
|
10
19
|
// Check if the object has all the properties of the base class
|
|
11
20
|
for (const prop of baseProps) {
|
|
12
|
-
if (!
|
|
21
|
+
if (!Object.prototype.hasOwnProperty.call(obj, prop)) {
|
|
13
22
|
return false;
|
|
14
23
|
}
|
|
15
24
|
}
|
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
import { CachedConnection } from "../db/CachedConnection";
|
|
2
|
+
export interface TableSchemaInfo {
|
|
3
|
+
fieldType: string;
|
|
4
|
+
name: string;
|
|
5
|
+
displayName: string;
|
|
6
|
+
isVisible: boolean;
|
|
7
|
+
}
|
|
2
8
|
export declare function removeFields(queryResults: any, fieldsToRemove: string[]): any;
|
|
3
9
|
export declare function mapQueries(queries: string[], targetConnection: CachedConnection): Promise<any[]>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import globals from "globals";
|
|
2
|
+
import pluginJs from "@eslint/js";
|
|
3
|
+
import tseslint from "typescript-eslint";
|
|
4
|
+
|
|
5
|
+
export default [
|
|
6
|
+
{ files: ["**/*.{js,mjs,cjs,ts,jsx,tsx}"] },
|
|
7
|
+
{ languageOptions: { globals: globals.node } },
|
|
8
|
+
pluginJs.configs.recommended,
|
|
9
|
+
...tseslint.configs.recommended,
|
|
10
|
+
{
|
|
11
|
+
rules: {
|
|
12
|
+
"@typescript-eslint/no-explicit-any": "off",
|
|
13
|
+
"@typescript-eslint/no-require-imports": "off",
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
];
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// Write a simple node server to test the SDK
|
|
2
|
+
|
|
3
|
+
import express from "express";
|
|
4
|
+
import cors from "cors";
|
|
5
|
+
import requireQuill from "../../src/index";
|
|
6
|
+
|
|
7
|
+
const app = express();
|
|
8
|
+
const port = 3005;
|
|
9
|
+
|
|
10
|
+
// postgresqlConfigExample {
|
|
11
|
+
// connectionString: process.env.DB_URL,
|
|
12
|
+
// ssl: {
|
|
13
|
+
// rejectUnauthorized: false,
|
|
14
|
+
// },
|
|
15
|
+
// };
|
|
16
|
+
|
|
17
|
+
// bigqueryConfigExample {
|
|
18
|
+
// projectId: process.env.PROJECT_ID,
|
|
19
|
+
// credentials: serviceAccount // You need to make the serviceAccount JSON
|
|
20
|
+
// }
|
|
21
|
+
|
|
22
|
+
// snowflakeConfigExample {
|
|
23
|
+
// account: process.env.ACCOUNT,
|
|
24
|
+
// username: process.env.USERNAME,
|
|
25
|
+
// password: process.env.PASSWORD,
|
|
26
|
+
// warehouse: process.env.WAREHOUSE,
|
|
27
|
+
// database: process.env.DATABASE,
|
|
28
|
+
// }
|
|
29
|
+
|
|
30
|
+
// mysqlConfigExample {
|
|
31
|
+
// host: process.env.HOST,
|
|
32
|
+
// user: process.env.USER,
|
|
33
|
+
// password: process.env.PASSWORD,
|
|
34
|
+
// database: process.env.DATABASE,
|
|
35
|
+
// }
|
|
36
|
+
|
|
37
|
+
app.use(cors());
|
|
38
|
+
app.use(express.json());
|
|
39
|
+
|
|
40
|
+
app.get("/", (req, res) => {
|
|
41
|
+
res.send("Hello World!");
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const quill = requireQuill({
|
|
45
|
+
privateKey: process.env.MYSQL_PRIVATE_KEY ?? "",
|
|
46
|
+
databaseConnectionString: process.env.MYSQL_DB_URL ?? "",
|
|
47
|
+
databaseConfig: {}, // TODO: Add database config
|
|
48
|
+
databaseType: "mysql",
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
app.post("/quill", async (req, res) => {
|
|
52
|
+
const { orgId, metadata } = req.body;
|
|
53
|
+
const result = await quill.query({
|
|
54
|
+
orgId: orgId ?? metadata.orgId,
|
|
55
|
+
metadata,
|
|
56
|
+
});
|
|
57
|
+
res.send(result);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
app.listen(port, () => {
|
|
61
|
+
console.log(`Example app listening at http://localhost:${port}`);
|
|
62
|
+
});
|
|
@@ -34,15 +34,14 @@ const port = 3001;
|
|
|
34
34
|
// }
|
|
35
35
|
|
|
36
36
|
const quill = require("../../src/index")({
|
|
37
|
-
privateKey: process.env.PRIVATE_KEY,
|
|
38
|
-
databaseConnectionString: process.env.DB_URL,
|
|
39
|
-
//
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
databaseType: process.env.DB_TYPE,
|
|
37
|
+
privateKey: process.env.PRIVATE_KEY ?? "",
|
|
38
|
+
databaseConnectionString: process.env.DB_URL ?? "",
|
|
39
|
+
databaseConfig: {}, // TODO: Add database config
|
|
40
|
+
databaseType: process.env.DB_TYPE as
|
|
41
|
+
| "postgresql"
|
|
42
|
+
| "snowflake"
|
|
43
|
+
| "bigquery"
|
|
44
|
+
| "mysql",
|
|
46
45
|
});
|
|
47
46
|
|
|
48
47
|
app.use(cors());
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quillsql/node",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "Quill Server SDK for Node.js",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -8,12 +8,18 @@
|
|
|
8
8
|
"scripts": {
|
|
9
9
|
"build": "tsc --outDir dist",
|
|
10
10
|
"start:dev": "nodemon ./examples/node-server/app.ts",
|
|
11
|
+
"mysql:dev": "nodemon ./examples/mysql-node/app.ts",
|
|
11
12
|
"integration-tests": "jest '.*\\.ispec\\.ts$'",
|
|
12
|
-
"test": "tsc src && jest --detectOpenHandles"
|
|
13
|
+
"test": "tsc src && jest --detectOpenHandles",
|
|
14
|
+
"style-check": "prettier --check \"**/*.{ts,tsx,md}\"",
|
|
15
|
+
"style-fix": "prettier --write \"**/*.{ts,tsx,md}\"",
|
|
16
|
+
"lint-check": "eslint \"**/*.{ts,tsx}\"",
|
|
17
|
+
"lint-fix": "eslint '**/*.{ts,tsx}' --fix"
|
|
13
18
|
},
|
|
14
19
|
"author": "lagambino",
|
|
15
20
|
"license": "ISC",
|
|
16
21
|
"devDependencies": {
|
|
22
|
+
"@eslint/js": "^9.9.0",
|
|
17
23
|
"@types/cors": "^2.8.17",
|
|
18
24
|
"@types/express": "^4.17.21",
|
|
19
25
|
"@types/jest": "^29.5.11",
|
|
@@ -21,11 +27,18 @@
|
|
|
21
27
|
"@types/pg": "^8.10.9",
|
|
22
28
|
"@types/snowflake-sdk": "^1.6.20",
|
|
23
29
|
"cors": "^2.8.5",
|
|
30
|
+
"eslint": "^9.9.0",
|
|
31
|
+
"eslint-config-prettier": "^9.1.0",
|
|
32
|
+
"eslint-plugin-prettier": "^5.2.1",
|
|
33
|
+
"eslint-plugin-react": "^7.35.0",
|
|
24
34
|
"express": "^4.18.2",
|
|
35
|
+
"globals": "^15.9.0",
|
|
25
36
|
"jest": "^29.7.0",
|
|
26
37
|
"nodemon": "^3.0.2",
|
|
38
|
+
"prettier": "^3.3.3",
|
|
27
39
|
"ts-node": "^10.9.2",
|
|
28
|
-
"typescript": "^5.3.3"
|
|
40
|
+
"typescript": "^5.3.3",
|
|
41
|
+
"typescript-eslint": "^8.1.0"
|
|
29
42
|
},
|
|
30
43
|
"dependencies": {
|
|
31
44
|
"@google-cloud/bigquery": "^7.4.0",
|