sql-dashboard 1.0.0
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/LICENSE +21 -0
- package/README.md +494 -0
- package/dist/base.driver-BKzf8BxS.d.mts +102 -0
- package/dist/base.driver-BdK7obt0.d.ts +102 -0
- package/dist/chunk-7YLO3OSN.mjs +19513 -0
- package/dist/chunk-BPXOTU3D.js +76 -0
- package/dist/chunk-HIQUIRDJ.mjs +76 -0
- package/dist/chunk-MTCZXLV5.mjs +232 -0
- package/dist/chunk-OCL5Y3AH.mjs +51 -0
- package/dist/chunk-OQJUWTZV.js +51 -0
- package/dist/chunk-P4QE6SGC.mjs +69 -0
- package/dist/chunk-TNHUK2FI.mjs +1033 -0
- package/dist/chunk-YGKUVVJT.mjs +5494 -0
- package/dist/connection-CzduPMhl.d.mts +68 -0
- package/dist/connection-CzduPMhl.d.ts +68 -0
- package/dist/dashboard-CkGz4ID-.d.mts +45 -0
- package/dist/dashboard-D9xSb-hQ.d.ts +45 -0
- package/dist/drivers/mssql.driver.d.mts +26 -0
- package/dist/drivers/mssql.driver.d.ts +26 -0
- package/dist/drivers/mssql.driver.js +64824 -0
- package/dist/drivers/mssql.driver.mjs +8 -0
- package/dist/drivers/mysql.driver.d.mts +29 -0
- package/dist/drivers/mysql.driver.d.ts +29 -0
- package/dist/drivers/mysql.driver.js +19672 -0
- package/dist/drivers/mysql.driver.mjs +9 -0
- package/dist/drivers/postgres.driver.d.mts +29 -0
- package/dist/drivers/postgres.driver.d.ts +29 -0
- package/dist/drivers/postgres.driver.js +5588 -0
- package/dist/drivers/postgres.driver.mjs +8 -0
- package/dist/export/index.d.mts +23 -0
- package/dist/export/index.d.ts +23 -0
- package/dist/export/index.js +102 -0
- package/dist/export/index.mjs +75 -0
- package/dist/index.d.mts +579 -0
- package/dist/index.d.ts +579 -0
- package/dist/index.js +26694 -0
- package/dist/index.mjs +26694 -0
- package/dist/middleware/express.d.mts +11 -0
- package/dist/middleware/express.d.ts +11 -0
- package/dist/middleware/express.js +90896 -0
- package/dist/middleware/express.mjs +91 -0
- package/dist/middleware/fastify.d.mts +10 -0
- package/dist/middleware/fastify.d.ts +10 -0
- package/dist/middleware/fastify.js +90860 -0
- package/dist/middleware/fastify.mjs +54 -0
- package/dist/open-JHAWMLA2.mjs +602 -0
- package/dist/open-T3PIT3AO.js +602 -0
- package/dist/query-BFhJHNeb.d.mts +16 -0
- package/dist/query-BFhJHNeb.d.ts +16 -0
- package/dist/tedious-LLE7JVQC.js +63830 -0
- package/dist/tedious-PHHFLMLD.mjs +63830 -0
- package/package.json +131 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var _chunkOQJUWTZVjs = require('./chunk-OQJUWTZV.js');
|
|
5
|
+
|
|
6
|
+
// node_modules/safer-buffer/safer.js
|
|
7
|
+
var require_safer = _chunkOQJUWTZVjs.__commonJS.call(void 0, {
|
|
8
|
+
"node_modules/safer-buffer/safer.js"(exports, module) {
|
|
9
|
+
"use strict";
|
|
10
|
+
var buffer = _chunkOQJUWTZVjs.__require.call(void 0, "buffer");
|
|
11
|
+
var Buffer = buffer.Buffer;
|
|
12
|
+
var safer = {};
|
|
13
|
+
var key;
|
|
14
|
+
for (key in buffer) {
|
|
15
|
+
if (!buffer.hasOwnProperty(key)) continue;
|
|
16
|
+
if (key === "SlowBuffer" || key === "Buffer") continue;
|
|
17
|
+
safer[key] = buffer[key];
|
|
18
|
+
}
|
|
19
|
+
var Safer = safer.Buffer = {};
|
|
20
|
+
for (key in Buffer) {
|
|
21
|
+
if (!Buffer.hasOwnProperty(key)) continue;
|
|
22
|
+
if (key === "allocUnsafe" || key === "allocUnsafeSlow") continue;
|
|
23
|
+
Safer[key] = Buffer[key];
|
|
24
|
+
}
|
|
25
|
+
safer.Buffer.prototype = Buffer.prototype;
|
|
26
|
+
if (!Safer.from || Safer.from === Uint8Array.from) {
|
|
27
|
+
Safer.from = function(value, encodingOrOffset, length) {
|
|
28
|
+
if (typeof value === "number") {
|
|
29
|
+
throw new TypeError('The "value" argument must not be of type number. Received type ' + typeof value);
|
|
30
|
+
}
|
|
31
|
+
if (value && typeof value.length === "undefined") {
|
|
32
|
+
throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type " + typeof value);
|
|
33
|
+
}
|
|
34
|
+
return Buffer(value, encodingOrOffset, length);
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
if (!Safer.alloc) {
|
|
38
|
+
Safer.alloc = function(size, fill, encoding) {
|
|
39
|
+
if (typeof size !== "number") {
|
|
40
|
+
throw new TypeError('The "size" argument must be of type number. Received type ' + typeof size);
|
|
41
|
+
}
|
|
42
|
+
if (size < 0 || size >= 2 * (1 << 30)) {
|
|
43
|
+
throw new RangeError('The value "' + size + '" is invalid for option "size"');
|
|
44
|
+
}
|
|
45
|
+
var buf = Buffer(size);
|
|
46
|
+
if (!fill || fill.length === 0) {
|
|
47
|
+
buf.fill(0);
|
|
48
|
+
} else if (typeof encoding === "string") {
|
|
49
|
+
buf.fill(fill, encoding);
|
|
50
|
+
} else {
|
|
51
|
+
buf.fill(fill);
|
|
52
|
+
}
|
|
53
|
+
return buf;
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
if (!safer.kStringMaxLength) {
|
|
57
|
+
try {
|
|
58
|
+
safer.kStringMaxLength = process.binding("buffer").kStringMaxLength;
|
|
59
|
+
} catch (e) {
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (!safer.constants) {
|
|
63
|
+
safer.constants = {
|
|
64
|
+
MAX_LENGTH: safer.kMaxLength
|
|
65
|
+
};
|
|
66
|
+
if (safer.kStringMaxLength) {
|
|
67
|
+
safer.constants.MAX_STRING_LENGTH = safer.kStringMaxLength;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
module.exports = safer;
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
exports.require_safer = require_safer;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__commonJS,
|
|
3
|
+
__require
|
|
4
|
+
} from "./chunk-OCL5Y3AH.mjs";
|
|
5
|
+
|
|
6
|
+
// node_modules/safer-buffer/safer.js
|
|
7
|
+
var require_safer = __commonJS({
|
|
8
|
+
"node_modules/safer-buffer/safer.js"(exports, module) {
|
|
9
|
+
"use strict";
|
|
10
|
+
var buffer = __require("buffer");
|
|
11
|
+
var Buffer = buffer.Buffer;
|
|
12
|
+
var safer = {};
|
|
13
|
+
var key;
|
|
14
|
+
for (key in buffer) {
|
|
15
|
+
if (!buffer.hasOwnProperty(key)) continue;
|
|
16
|
+
if (key === "SlowBuffer" || key === "Buffer") continue;
|
|
17
|
+
safer[key] = buffer[key];
|
|
18
|
+
}
|
|
19
|
+
var Safer = safer.Buffer = {};
|
|
20
|
+
for (key in Buffer) {
|
|
21
|
+
if (!Buffer.hasOwnProperty(key)) continue;
|
|
22
|
+
if (key === "allocUnsafe" || key === "allocUnsafeSlow") continue;
|
|
23
|
+
Safer[key] = Buffer[key];
|
|
24
|
+
}
|
|
25
|
+
safer.Buffer.prototype = Buffer.prototype;
|
|
26
|
+
if (!Safer.from || Safer.from === Uint8Array.from) {
|
|
27
|
+
Safer.from = function(value, encodingOrOffset, length) {
|
|
28
|
+
if (typeof value === "number") {
|
|
29
|
+
throw new TypeError('The "value" argument must not be of type number. Received type ' + typeof value);
|
|
30
|
+
}
|
|
31
|
+
if (value && typeof value.length === "undefined") {
|
|
32
|
+
throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type " + typeof value);
|
|
33
|
+
}
|
|
34
|
+
return Buffer(value, encodingOrOffset, length);
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
if (!Safer.alloc) {
|
|
38
|
+
Safer.alloc = function(size, fill, encoding) {
|
|
39
|
+
if (typeof size !== "number") {
|
|
40
|
+
throw new TypeError('The "size" argument must be of type number. Received type ' + typeof size);
|
|
41
|
+
}
|
|
42
|
+
if (size < 0 || size >= 2 * (1 << 30)) {
|
|
43
|
+
throw new RangeError('The value "' + size + '" is invalid for option "size"');
|
|
44
|
+
}
|
|
45
|
+
var buf = Buffer(size);
|
|
46
|
+
if (!fill || fill.length === 0) {
|
|
47
|
+
buf.fill(0);
|
|
48
|
+
} else if (typeof encoding === "string") {
|
|
49
|
+
buf.fill(fill, encoding);
|
|
50
|
+
} else {
|
|
51
|
+
buf.fill(fill);
|
|
52
|
+
}
|
|
53
|
+
return buf;
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
if (!safer.kStringMaxLength) {
|
|
57
|
+
try {
|
|
58
|
+
safer.kStringMaxLength = process.binding("buffer").kStringMaxLength;
|
|
59
|
+
} catch (e) {
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (!safer.constants) {
|
|
63
|
+
safer.constants = {
|
|
64
|
+
MAX_LENGTH: safer.kMaxLength
|
|
65
|
+
};
|
|
66
|
+
if (safer.kStringMaxLength) {
|
|
67
|
+
safer.constants.MAX_STRING_LENGTH = safer.kStringMaxLength;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
module.exports = safer;
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
export {
|
|
75
|
+
require_safer
|
|
76
|
+
};
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BaseDriver,
|
|
3
|
+
QueryTimer
|
|
4
|
+
} from "./chunk-P4QE6SGC.mjs";
|
|
5
|
+
|
|
6
|
+
// src/drivers/mssql.driver.ts
|
|
7
|
+
var MSSQLDriver = class extends BaseDriver {
|
|
8
|
+
constructor(config) {
|
|
9
|
+
super();
|
|
10
|
+
this.type = "mssql" /* MSSQL */;
|
|
11
|
+
this.connection = null;
|
|
12
|
+
this.config = {
|
|
13
|
+
server: "localhost",
|
|
14
|
+
port: 1433,
|
|
15
|
+
user: "sa",
|
|
16
|
+
password: "",
|
|
17
|
+
database: "master",
|
|
18
|
+
schema: "dbo",
|
|
19
|
+
encrypt: false,
|
|
20
|
+
trustServerCertificate: true,
|
|
21
|
+
...config
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
async connect() {
|
|
25
|
+
const config = this.config;
|
|
26
|
+
const tedious = await import("./tedious-PHHFLMLD.mjs");
|
|
27
|
+
return new Promise((resolve, reject) => {
|
|
28
|
+
this.connection = new tedious.Connection({
|
|
29
|
+
server: config.server || "localhost",
|
|
30
|
+
authentication: {
|
|
31
|
+
type: "default",
|
|
32
|
+
options: {
|
|
33
|
+
userName: config.user,
|
|
34
|
+
password: config.password
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
options: {
|
|
38
|
+
port: config.port || 1433,
|
|
39
|
+
database: config.database,
|
|
40
|
+
encrypt: config.encrypt || false,
|
|
41
|
+
trustServerCertificate: config.trustServerCertificate ?? true,
|
|
42
|
+
rowCollectionOnRequestCompletion: true,
|
|
43
|
+
useColumnNames: false
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
this.connection.on("connect", (err) => {
|
|
47
|
+
if (err) {
|
|
48
|
+
reject(new Error(`Failed to connect to MSSQL: ${err.message}`));
|
|
49
|
+
} else {
|
|
50
|
+
this.connected = true;
|
|
51
|
+
resolve();
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
this.connection.on("error", (err) => {
|
|
55
|
+
this.connected = false;
|
|
56
|
+
reject(new Error(`MSSQL connection error: ${err.message}`));
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
async disconnect() {
|
|
61
|
+
if (this.connection) {
|
|
62
|
+
this.connection.close();
|
|
63
|
+
this.connection = null;
|
|
64
|
+
}
|
|
65
|
+
this.connected = false;
|
|
66
|
+
}
|
|
67
|
+
isConnected() {
|
|
68
|
+
return this.connected && this.connection !== null;
|
|
69
|
+
}
|
|
70
|
+
async executeQuery(sql, _params) {
|
|
71
|
+
this.ensureConnected();
|
|
72
|
+
const timer = new QueryTimer();
|
|
73
|
+
const tedious = await import("./tedious-PHHFLMLD.mjs");
|
|
74
|
+
return new Promise((resolve) => {
|
|
75
|
+
const rows = [];
|
|
76
|
+
const columns = [];
|
|
77
|
+
const request = new tedious.Request(sql, (err) => {
|
|
78
|
+
if (err) {
|
|
79
|
+
resolve(this.createErrorResult(sql, err, timer.elapsed));
|
|
80
|
+
} else {
|
|
81
|
+
if (rows.length > 0) {
|
|
82
|
+
resolve(this.createResult(sql, rows, timer.elapsed));
|
|
83
|
+
} else {
|
|
84
|
+
resolve({
|
|
85
|
+
id: crypto.randomUUID(),
|
|
86
|
+
status: "success",
|
|
87
|
+
rows: [],
|
|
88
|
+
columns: [],
|
|
89
|
+
rowCount: 0,
|
|
90
|
+
duration: timer.elapsed,
|
|
91
|
+
query: sql
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
request.on("column", (column) => {
|
|
97
|
+
if (column && column.metadata && !columns.includes(column.metadata.colName)) {
|
|
98
|
+
columns.push(column.metadata.colName);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
request.on("row", (rowData) => {
|
|
102
|
+
const row = {};
|
|
103
|
+
rowData.forEach((cell, index) => {
|
|
104
|
+
const colName = columns[index] || `col${index}`;
|
|
105
|
+
row[colName] = cell && typeof cell === "object" && "value" in cell ? cell.value : cell;
|
|
106
|
+
});
|
|
107
|
+
rows.push(row);
|
|
108
|
+
});
|
|
109
|
+
this.connection.execSql(request);
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
async executeBatch(queries) {
|
|
113
|
+
const results = [];
|
|
114
|
+
for (const query of queries) {
|
|
115
|
+
const result = await this.executeQuery(query);
|
|
116
|
+
results.push(result);
|
|
117
|
+
if (result.status === "error") break;
|
|
118
|
+
}
|
|
119
|
+
return results;
|
|
120
|
+
}
|
|
121
|
+
async getSchema() {
|
|
122
|
+
const config = this.config;
|
|
123
|
+
return {
|
|
124
|
+
name: config.schema || "dbo",
|
|
125
|
+
tables: await this.getTables(),
|
|
126
|
+
views: await this.getViews(),
|
|
127
|
+
procedures: []
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
async getTables() {
|
|
131
|
+
const result = await this.executeQuery(
|
|
132
|
+
`SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_SCHEMA = '${this.config.schema || "dbo"}' ORDER BY TABLE_NAME;`
|
|
133
|
+
);
|
|
134
|
+
const tables = [];
|
|
135
|
+
for (const row of result.rows) {
|
|
136
|
+
const tableName = row.TABLE_NAME;
|
|
137
|
+
tables.push({
|
|
138
|
+
name: tableName,
|
|
139
|
+
schema: this.config.schema || "dbo",
|
|
140
|
+
type: "table",
|
|
141
|
+
columns: await this.getColumns(tableName),
|
|
142
|
+
indexes: await this.getIndexes(tableName),
|
|
143
|
+
foreignKeys: await this.getForeignKeys(tableName),
|
|
144
|
+
rowCount: await this.getTableRowCount(tableName)
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
return tables;
|
|
148
|
+
}
|
|
149
|
+
async getTableInfo(tableName) {
|
|
150
|
+
const [columns, indexes, foreignKeys, rowCount] = await Promise.all([
|
|
151
|
+
this.getColumns(tableName),
|
|
152
|
+
this.getIndexes(tableName),
|
|
153
|
+
this.getForeignKeys(tableName),
|
|
154
|
+
this.getTableRowCount(tableName)
|
|
155
|
+
]);
|
|
156
|
+
return {
|
|
157
|
+
name: tableName,
|
|
158
|
+
schema: this.config.schema || "dbo",
|
|
159
|
+
type: "table",
|
|
160
|
+
columns,
|
|
161
|
+
indexes,
|
|
162
|
+
foreignKeys,
|
|
163
|
+
rowCount
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
async getColumns(tableName) {
|
|
167
|
+
const schema = this.config.schema || "dbo";
|
|
168
|
+
const result = await this.executeQuery(
|
|
169
|
+
`SELECT c.COLUMN_NAME, c.DATA_TYPE, c.IS_NULLABLE, c.COLUMN_DEFAULT, c.CHARACTER_MAXIMUM_LENGTH, c.NUMERIC_PRECISION, c.NUMERIC_SCALE, COLUMNPROPERTY(OBJECT_ID('${schema}.${tableName}'), c.COLUMN_NAME, 'IsIdentity') as IS_IDENTITY, COLUMNPROPERTY(OBJECT_ID('${schema}.${tableName}'), c.COLUMN_NAME, 'IsPrimaryKey') as IS_PK FROM INFORMATION_SCHEMA.COLUMNS c WHERE c.TABLE_SCHEMA = '${schema}' AND c.TABLE_NAME = '${tableName}' ORDER BY c.ORDINAL_POSITION;`
|
|
170
|
+
);
|
|
171
|
+
return result.rows.map((row) => ({
|
|
172
|
+
name: row.COLUMN_NAME,
|
|
173
|
+
type: row.DATA_TYPE.toUpperCase(),
|
|
174
|
+
nullable: row.IS_NULLABLE === "YES",
|
|
175
|
+
primaryKey: !!row.IS_PK,
|
|
176
|
+
defaultValue: row.COLUMN_DEFAULT,
|
|
177
|
+
autoIncrement: !!row.IS_IDENTITY,
|
|
178
|
+
maxLength: row.CHARACTER_MAXIMUM_LENGTH,
|
|
179
|
+
precision: row.NUMERIC_PRECISION,
|
|
180
|
+
scale: row.NUMERIC_SCALE
|
|
181
|
+
}));
|
|
182
|
+
}
|
|
183
|
+
async getIndexes(tableName) {
|
|
184
|
+
const schema = this.config.schema || "dbo";
|
|
185
|
+
const result = await this.executeQuery(
|
|
186
|
+
`SELECT i.name, i.is_unique, i.is_primary_key, STUFF((SELECT ',' + col.name FROM sys.index_columns ic JOIN sys.columns col ON ic.object_id = col.object_id AND ic.column_id = col.column_id WHERE ic.object_id = i.object_id AND ic.index_id = i.index_id ORDER BY ic.key_ordinal FOR XML PATH('')), 1, 1, '') as columns FROM sys.indexes i JOIN sys.tables t ON i.object_id = t.object_id JOIN sys.schemas s ON t.schema_id = s.schema_id WHERE s.name = '${schema}' AND t.name = '${tableName}';`
|
|
187
|
+
);
|
|
188
|
+
return result.rows.map((row) => {
|
|
189
|
+
const cols = (row.columns || "").split(",").filter(Boolean);
|
|
190
|
+
return { name: row.name, columns: cols, unique: !!row.is_unique, primary: !!row.is_primary_key, type: row.is_primary_key ? "primary" : row.is_unique ? "unique" : "index" };
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
async getForeignKeys(tableName) {
|
|
194
|
+
const schema = this.config.schema || "dbo";
|
|
195
|
+
const result = await this.executeQuery(
|
|
196
|
+
`SELECT fk.name as constraint_name, COL_NAME(fkc.parent_object_id, fkc.parent_column_id) as column_name, OBJECT_SCHEMA_NAME(fkc.referenced_object_id) as ref_schema, OBJECT_NAME(fkc.referenced_object_id) as ref_table, COL_NAME(fkc.referenced_object_id, fkc.referenced_column_id) as ref_column, fk.delete_referential_action_desc, fk.update_referential_action_desc FROM sys.foreign_keys fk JOIN sys.foreign_key_columns fkc ON fk.object_id = fkc.constraint_object_id JOIN sys.tables t ON fk.parent_object_id = t.object_id JOIN sys.schemas s ON t.schema_id = s.schema_id WHERE s.name = '${schema}' AND t.name = '${tableName}';`
|
|
197
|
+
);
|
|
198
|
+
return result.rows.map((row) => ({
|
|
199
|
+
name: row.constraint_name,
|
|
200
|
+
column: row.column_name,
|
|
201
|
+
referencedSchema: row.ref_schema || schema,
|
|
202
|
+
referencedTable: row.ref_table,
|
|
203
|
+
referencedColumn: row.ref_column,
|
|
204
|
+
onDelete: (row.delete_referential_action_desc || "NO_ACTION").replace(/_/g, " "),
|
|
205
|
+
onUpdate: (row.update_referential_action_desc || "NO_ACTION").replace(/_/g, " ")
|
|
206
|
+
}));
|
|
207
|
+
}
|
|
208
|
+
async getViews() {
|
|
209
|
+
const schema = this.config.schema || "dbo";
|
|
210
|
+
const result = await this.executeQuery(
|
|
211
|
+
`SELECT TABLE_NAME, VIEW_DEFINITION FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_SCHEMA = '${schema}' ORDER BY TABLE_NAME;`
|
|
212
|
+
);
|
|
213
|
+
return result.rows.map((row) => ({ name: row.TABLE_NAME, schema, definition: row.VIEW_DEFINITION || "", columns: [] }));
|
|
214
|
+
}
|
|
215
|
+
async getTableRowCount(tableName) {
|
|
216
|
+
const schema = this.config.schema || "dbo";
|
|
217
|
+
const result = await this.executeQuery(`SELECT COUNT(*) as count FROM [${schema}].[${tableName}];`);
|
|
218
|
+
return result.rows[0]?.count || 0;
|
|
219
|
+
}
|
|
220
|
+
async getVersion() {
|
|
221
|
+
const result = await this.executeQuery("SELECT @@VERSION as version;");
|
|
222
|
+
return result.rows[0]?.version || "unknown";
|
|
223
|
+
}
|
|
224
|
+
async getDatabases() {
|
|
225
|
+
const result = await this.executeQuery("SELECT name FROM sys.databases ORDER BY name;");
|
|
226
|
+
return result.rows.map((r) => r.name);
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
export {
|
|
231
|
+
MSSQLDriver
|
|
232
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
9
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
10
|
+
}) : x)(function(x) {
|
|
11
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
12
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
13
|
+
});
|
|
14
|
+
var __esm = (fn, res) => function __init() {
|
|
15
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
16
|
+
};
|
|
17
|
+
var __commonJS = (cb, mod) => function __require2() {
|
|
18
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
19
|
+
};
|
|
20
|
+
var __export = (target, all) => {
|
|
21
|
+
for (var name in all)
|
|
22
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
23
|
+
};
|
|
24
|
+
var __copyProps = (to, from, except, desc) => {
|
|
25
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
26
|
+
for (let key of __getOwnPropNames(from))
|
|
27
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
28
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
29
|
+
}
|
|
30
|
+
return to;
|
|
31
|
+
};
|
|
32
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
33
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
34
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
35
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
36
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
37
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
38
|
+
mod
|
|
39
|
+
));
|
|
40
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
41
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
42
|
+
|
|
43
|
+
export {
|
|
44
|
+
__require,
|
|
45
|
+
__esm,
|
|
46
|
+
__commonJS,
|
|
47
|
+
__export,
|
|
48
|
+
__toESM,
|
|
49
|
+
__toCommonJS,
|
|
50
|
+
__publicField
|
|
51
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
9
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
10
|
+
}) : x)(function(x) {
|
|
11
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
12
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
13
|
+
});
|
|
14
|
+
var __esm = (fn, res) => function __init() {
|
|
15
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
16
|
+
};
|
|
17
|
+
var __commonJS = (cb, mod) => function __require2() {
|
|
18
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
19
|
+
};
|
|
20
|
+
var __export = (target, all) => {
|
|
21
|
+
for (var name in all)
|
|
22
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
23
|
+
};
|
|
24
|
+
var __copyProps = (to, from, except, desc) => {
|
|
25
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
26
|
+
for (let key of __getOwnPropNames(from))
|
|
27
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
28
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
29
|
+
}
|
|
30
|
+
return to;
|
|
31
|
+
};
|
|
32
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
33
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
34
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
35
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
36
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
37
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
38
|
+
mod
|
|
39
|
+
));
|
|
40
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
41
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
exports.__require = __require; exports.__esm = __esm; exports.__commonJS = __commonJS; exports.__export = __export; exports.__toESM = __toESM; exports.__toCommonJS = __toCommonJS; exports.__publicField = __publicField;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// src/drivers/base.driver.ts
|
|
2
|
+
import { v4 as uuid } from "uuid";
|
|
3
|
+
var BaseDriver = class {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.connected = false;
|
|
6
|
+
this.config = {};
|
|
7
|
+
}
|
|
8
|
+
createResult(query, rows, duration, affectedRows) {
|
|
9
|
+
const columns = rows.length > 0 ? Object.keys(rows[0]) : [];
|
|
10
|
+
return {
|
|
11
|
+
id: uuid(),
|
|
12
|
+
status: "success",
|
|
13
|
+
rows,
|
|
14
|
+
columns,
|
|
15
|
+
rowCount: rows.length,
|
|
16
|
+
affectedRows,
|
|
17
|
+
duration,
|
|
18
|
+
query
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
createErrorResult(query, error, duration) {
|
|
22
|
+
return {
|
|
23
|
+
id: uuid(),
|
|
24
|
+
status: "error",
|
|
25
|
+
rows: [],
|
|
26
|
+
columns: [],
|
|
27
|
+
rowCount: 0,
|
|
28
|
+
duration,
|
|
29
|
+
query,
|
|
30
|
+
error: error.message
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
ensureConnected() {
|
|
34
|
+
if (!this.connected) {
|
|
35
|
+
throw new Error(`Driver ${this.type} is not connected. Call connect() first.`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
// src/utils/timer.ts
|
|
41
|
+
var QueryTimer = class {
|
|
42
|
+
constructor() {
|
|
43
|
+
this.startTime = performance.now();
|
|
44
|
+
}
|
|
45
|
+
get elapsed() {
|
|
46
|
+
return performance.now() - this.startTime;
|
|
47
|
+
}
|
|
48
|
+
reset() {
|
|
49
|
+
this.startTime = performance.now();
|
|
50
|
+
}
|
|
51
|
+
stop() {
|
|
52
|
+
const endTime = /* @__PURE__ */ new Date();
|
|
53
|
+
return {
|
|
54
|
+
duration: this.elapsed,
|
|
55
|
+
startTime: new Date(Date.now() - this.elapsed),
|
|
56
|
+
endTime
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
static async measure(fn) {
|
|
60
|
+
const start = performance.now();
|
|
61
|
+
const result = await fn();
|
|
62
|
+
return { result, duration: performance.now() - start };
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export {
|
|
67
|
+
BaseDriver,
|
|
68
|
+
QueryTimer
|
|
69
|
+
};
|