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
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,579 @@
|
|
|
1
|
+
import { EventEmitter } from 'eventemitter3';
|
|
2
|
+
import { Router } from 'express';
|
|
3
|
+
import { FastifyInstance, FastifyPluginOptions } from 'fastify';
|
|
4
|
+
|
|
5
|
+
declare enum DriverType {
|
|
6
|
+
SQLITE = "sqlite",
|
|
7
|
+
MYSQL = "mysql",
|
|
8
|
+
POSTGRES = "postgres",
|
|
9
|
+
MSSQL = "mssql"
|
|
10
|
+
}
|
|
11
|
+
interface PoolConfig {
|
|
12
|
+
min?: number;
|
|
13
|
+
max?: number;
|
|
14
|
+
acquireTimeout?: number;
|
|
15
|
+
idleTimeout?: number;
|
|
16
|
+
}
|
|
17
|
+
interface MySQLConfig {
|
|
18
|
+
host?: string;
|
|
19
|
+
port?: number;
|
|
20
|
+
user?: string;
|
|
21
|
+
password?: string;
|
|
22
|
+
database?: string;
|
|
23
|
+
charset?: string;
|
|
24
|
+
timezone?: string;
|
|
25
|
+
multipleStatements?: boolean;
|
|
26
|
+
ssl?: boolean | object;
|
|
27
|
+
}
|
|
28
|
+
interface PostgreSQLConfig {
|
|
29
|
+
host?: string;
|
|
30
|
+
port?: number;
|
|
31
|
+
user?: string;
|
|
32
|
+
password?: string;
|
|
33
|
+
database?: string;
|
|
34
|
+
schema?: string;
|
|
35
|
+
ssl?: boolean | object;
|
|
36
|
+
applicationName?: string;
|
|
37
|
+
}
|
|
38
|
+
interface MSSQLConfig {
|
|
39
|
+
server?: string;
|
|
40
|
+
port?: number;
|
|
41
|
+
user?: string;
|
|
42
|
+
password?: string;
|
|
43
|
+
database?: string;
|
|
44
|
+
schema?: string;
|
|
45
|
+
encrypt?: boolean;
|
|
46
|
+
trustServerCertificate?: boolean;
|
|
47
|
+
options?: Record<string, unknown>;
|
|
48
|
+
}
|
|
49
|
+
interface SQLiteConfig {
|
|
50
|
+
path?: string;
|
|
51
|
+
mode?: 'memory' | 'file';
|
|
52
|
+
readOnly?: boolean;
|
|
53
|
+
}
|
|
54
|
+
type DriverConfig = {
|
|
55
|
+
type: DriverType.SQLITE;
|
|
56
|
+
connection: SQLiteConfig;
|
|
57
|
+
pool?: PoolConfig;
|
|
58
|
+
} | {
|
|
59
|
+
type: DriverType.MYSQL;
|
|
60
|
+
connection: MySQLConfig;
|
|
61
|
+
pool?: PoolConfig;
|
|
62
|
+
} | {
|
|
63
|
+
type: DriverType.POSTGRES;
|
|
64
|
+
connection: PostgreSQLConfig;
|
|
65
|
+
pool?: PoolConfig;
|
|
66
|
+
} | {
|
|
67
|
+
type: DriverType.MSSQL;
|
|
68
|
+
connection: MSSQLConfig;
|
|
69
|
+
pool?: PoolConfig;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
type QueryStatus = 'success' | 'error' | 'cancelled';
|
|
73
|
+
interface QueryOptions {
|
|
74
|
+
timeout?: number;
|
|
75
|
+
params?: unknown[];
|
|
76
|
+
readOnly?: boolean;
|
|
77
|
+
transaction?: boolean;
|
|
78
|
+
stream?: boolean;
|
|
79
|
+
maxRows?: number;
|
|
80
|
+
}
|
|
81
|
+
interface QueryResult {
|
|
82
|
+
id: string;
|
|
83
|
+
status: QueryStatus;
|
|
84
|
+
rows: Record<string, unknown>[];
|
|
85
|
+
columns: string[];
|
|
86
|
+
rowCount: number;
|
|
87
|
+
affectedRows?: number;
|
|
88
|
+
duration: number;
|
|
89
|
+
query: string;
|
|
90
|
+
error?: string;
|
|
91
|
+
warning?: string;
|
|
92
|
+
insertedId?: string | number;
|
|
93
|
+
}
|
|
94
|
+
interface QueryHistoryEntry {
|
|
95
|
+
id: string;
|
|
96
|
+
query: string;
|
|
97
|
+
executedAt: Date;
|
|
98
|
+
duration: number;
|
|
99
|
+
status: QueryStatus;
|
|
100
|
+
rowCount: number;
|
|
101
|
+
database: string;
|
|
102
|
+
user?: string;
|
|
103
|
+
}
|
|
104
|
+
interface PaginatedResult<T> {
|
|
105
|
+
data: T[];
|
|
106
|
+
total: number;
|
|
107
|
+
page: number;
|
|
108
|
+
pageSize: number;
|
|
109
|
+
totalPages: number;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
interface SchemaFilter {
|
|
113
|
+
schema?: string;
|
|
114
|
+
table?: string;
|
|
115
|
+
type?: 'table' | 'view' | 'index' | 'procedure';
|
|
116
|
+
}
|
|
117
|
+
interface SchemaInfo {
|
|
118
|
+
name: string;
|
|
119
|
+
tables: TableInfo[];
|
|
120
|
+
views: ViewInfo[];
|
|
121
|
+
procedures: ProcedureInfo[];
|
|
122
|
+
}
|
|
123
|
+
interface TableInfo {
|
|
124
|
+
name: string;
|
|
125
|
+
schema: string;
|
|
126
|
+
type: 'table' | 'view';
|
|
127
|
+
columns: ColumnInfo[];
|
|
128
|
+
indexes: IndexInfo[];
|
|
129
|
+
foreignKeys: ForeignKeyInfo[];
|
|
130
|
+
rowCount?: number;
|
|
131
|
+
size?: string;
|
|
132
|
+
comment?: string;
|
|
133
|
+
createdAt?: Date;
|
|
134
|
+
updatedAt?: Date;
|
|
135
|
+
engine?: string;
|
|
136
|
+
collation?: string;
|
|
137
|
+
}
|
|
138
|
+
interface ColumnInfo {
|
|
139
|
+
name: string;
|
|
140
|
+
type: string;
|
|
141
|
+
nullable: boolean;
|
|
142
|
+
primaryKey: boolean;
|
|
143
|
+
defaultValue?: string | null;
|
|
144
|
+
autoIncrement?: boolean;
|
|
145
|
+
maxLength?: number;
|
|
146
|
+
precision?: number;
|
|
147
|
+
scale?: number;
|
|
148
|
+
comment?: string;
|
|
149
|
+
enumValues?: string[];
|
|
150
|
+
foreignKey?: {
|
|
151
|
+
table: string;
|
|
152
|
+
column: string;
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
interface IndexInfo {
|
|
156
|
+
name: string;
|
|
157
|
+
columns: string[];
|
|
158
|
+
unique: boolean;
|
|
159
|
+
primary: boolean;
|
|
160
|
+
type: string;
|
|
161
|
+
method?: string;
|
|
162
|
+
}
|
|
163
|
+
interface ForeignKeyInfo {
|
|
164
|
+
name: string;
|
|
165
|
+
column: string;
|
|
166
|
+
referencedSchema: string;
|
|
167
|
+
referencedTable: string;
|
|
168
|
+
referencedColumn: string;
|
|
169
|
+
onDelete: string;
|
|
170
|
+
onUpdate: string;
|
|
171
|
+
}
|
|
172
|
+
interface ViewInfo {
|
|
173
|
+
name: string;
|
|
174
|
+
schema: string;
|
|
175
|
+
definition: string;
|
|
176
|
+
columns: ColumnInfo[];
|
|
177
|
+
}
|
|
178
|
+
interface ProcedureInfo {
|
|
179
|
+
name: string;
|
|
180
|
+
schema: string;
|
|
181
|
+
type: 'procedure' | 'function';
|
|
182
|
+
params: {
|
|
183
|
+
name: string;
|
|
184
|
+
type: string;
|
|
185
|
+
mode: 'IN' | 'OUT' | 'INOUT';
|
|
186
|
+
}[];
|
|
187
|
+
returnType?: string;
|
|
188
|
+
definition: string;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
interface RateLimitConfig {
|
|
192
|
+
enabled?: boolean;
|
|
193
|
+
windowMs?: number;
|
|
194
|
+
maxQueries?: number;
|
|
195
|
+
maxQueriesPerUser?: Record<string, number>;
|
|
196
|
+
errorMessage?: string;
|
|
197
|
+
}
|
|
198
|
+
interface ReadOnlyRule {
|
|
199
|
+
enabled?: boolean;
|
|
200
|
+
allowSelect?: boolean;
|
|
201
|
+
allowShow?: boolean;
|
|
202
|
+
allowDescribe?: boolean;
|
|
203
|
+
allowExplain?: boolean;
|
|
204
|
+
bypassUsers?: string[];
|
|
205
|
+
}
|
|
206
|
+
interface SecurityConfig {
|
|
207
|
+
readOnly?: boolean | ReadOnlyRule;
|
|
208
|
+
rateLimit?: RateLimitConfig;
|
|
209
|
+
maxQueryLength?: number;
|
|
210
|
+
maxRows?: number;
|
|
211
|
+
bannedStatements?: string[];
|
|
212
|
+
bannedDatabases?: string[];
|
|
213
|
+
allowedDatabases?: string[];
|
|
214
|
+
requireWhere?: boolean;
|
|
215
|
+
queryTimeout?: number;
|
|
216
|
+
allowedHosts?: string[];
|
|
217
|
+
}
|
|
218
|
+
interface ValidationError {
|
|
219
|
+
code: string;
|
|
220
|
+
message: string;
|
|
221
|
+
line?: number;
|
|
222
|
+
column?: number;
|
|
223
|
+
severity: 'error' | 'warning';
|
|
224
|
+
}
|
|
225
|
+
interface ValidationResult {
|
|
226
|
+
valid: boolean;
|
|
227
|
+
errors: ValidationError[];
|
|
228
|
+
normalizedQuery: string;
|
|
229
|
+
statementType: string;
|
|
230
|
+
isReadOnly: boolean;
|
|
231
|
+
tables: string[];
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'silent';
|
|
235
|
+
interface LoggerConfig {
|
|
236
|
+
level?: LogLevel;
|
|
237
|
+
queries?: boolean;
|
|
238
|
+
slowQueryThreshold?: number;
|
|
239
|
+
format?: 'json' | 'text';
|
|
240
|
+
}
|
|
241
|
+
interface DashboardOptions {
|
|
242
|
+
driver: DriverConfig;
|
|
243
|
+
security?: SecurityConfig;
|
|
244
|
+
logger?: LoggerConfig;
|
|
245
|
+
autoConnect?: boolean;
|
|
246
|
+
}
|
|
247
|
+
interface DashboardConfig extends Required<DashboardOptions> {
|
|
248
|
+
version: string;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
declare abstract class BaseDriver {
|
|
252
|
+
abstract readonly type: DriverType;
|
|
253
|
+
protected connected: boolean;
|
|
254
|
+
protected config: Record<string, unknown>;
|
|
255
|
+
abstract connect(): Promise<void>;
|
|
256
|
+
abstract disconnect(): Promise<void>;
|
|
257
|
+
abstract executeQuery(sql: string, params?: unknown[]): Promise<QueryResult>;
|
|
258
|
+
abstract executeBatch(queries: string[]): Promise<QueryResult[]>;
|
|
259
|
+
abstract isConnected(): boolean;
|
|
260
|
+
protected createResult(query: string, rows: Record<string, unknown>[], duration: number, affectedRows?: number): QueryResult;
|
|
261
|
+
protected createErrorResult(query: string, error: Error, duration: number): QueryResult;
|
|
262
|
+
protected ensureConnected(): void;
|
|
263
|
+
abstract getSchema(): Promise<SchemaInfo>;
|
|
264
|
+
abstract getTables(): Promise<TableInfo[]>;
|
|
265
|
+
abstract getTableInfo(tableName: string): Promise<TableInfo>;
|
|
266
|
+
abstract getColumns(tableName: string): Promise<ColumnInfo[]>;
|
|
267
|
+
abstract getIndexes(tableName: string): Promise<IndexInfo[]>;
|
|
268
|
+
abstract getForeignKeys(tableName: string): Promise<ForeignKeyInfo[]>;
|
|
269
|
+
abstract getViews(): Promise<ViewInfo[]>;
|
|
270
|
+
abstract getTableRowCount(tableName: string): Promise<number>;
|
|
271
|
+
abstract getVersion(): Promise<string>;
|
|
272
|
+
abstract getDatabases(): Promise<string[]>;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
declare class SQLiteDriver extends BaseDriver {
|
|
276
|
+
readonly type = DriverType.SQLITE;
|
|
277
|
+
private db;
|
|
278
|
+
private sqlJs;
|
|
279
|
+
private dbPath;
|
|
280
|
+
private memoryMode;
|
|
281
|
+
constructor(config: SQLiteConfig);
|
|
282
|
+
connect(): Promise<void>;
|
|
283
|
+
disconnect(): Promise<void>;
|
|
284
|
+
isConnected(): boolean;
|
|
285
|
+
private saveToFile;
|
|
286
|
+
executeQuery(sql: string, params?: unknown[]): Promise<QueryResult>;
|
|
287
|
+
executeBatch(queries: string[]): Promise<QueryResult[]>;
|
|
288
|
+
getSchema(): Promise<SchemaInfo>;
|
|
289
|
+
getTables(): Promise<TableInfo[]>;
|
|
290
|
+
getTableInfo(tableName: string): Promise<TableInfo>;
|
|
291
|
+
getColumns(tableName: string): Promise<ColumnInfo[]>;
|
|
292
|
+
getIndexes(tableName: string): Promise<IndexInfo[]>;
|
|
293
|
+
getForeignKeys(tableName: string): Promise<ForeignKeyInfo[]>;
|
|
294
|
+
getViews(): Promise<ViewInfo[]>;
|
|
295
|
+
getTableRowCount(tableName: string): Promise<number>;
|
|
296
|
+
getVersion(): Promise<string>;
|
|
297
|
+
getDatabases(): Promise<string[]>;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
declare class MySQLDriver extends BaseDriver {
|
|
301
|
+
readonly type = DriverType.MYSQL;
|
|
302
|
+
private pool;
|
|
303
|
+
constructor(config: MySQLConfig);
|
|
304
|
+
connect(): Promise<void>;
|
|
305
|
+
disconnect(): Promise<void>;
|
|
306
|
+
isConnected(): boolean;
|
|
307
|
+
executeQuery(sql: string, params?: unknown[]): Promise<QueryResult>;
|
|
308
|
+
executeBatch(queries: string[]): Promise<QueryResult[]>;
|
|
309
|
+
getSchema(): Promise<SchemaInfo>;
|
|
310
|
+
private getCurrentDatabase;
|
|
311
|
+
getTables(): Promise<TableInfo[]>;
|
|
312
|
+
getTableInfo(tableName: string): Promise<TableInfo>;
|
|
313
|
+
getColumns(tableName: string): Promise<ColumnInfo[]>;
|
|
314
|
+
getIndexes(tableName: string): Promise<IndexInfo[]>;
|
|
315
|
+
getForeignKeys(tableName: string): Promise<ForeignKeyInfo[]>;
|
|
316
|
+
getViews(): Promise<ViewInfo[]>;
|
|
317
|
+
private getProcedures;
|
|
318
|
+
private getTableSize;
|
|
319
|
+
getTableRowCount(tableName: string): Promise<number>;
|
|
320
|
+
getVersion(): Promise<string>;
|
|
321
|
+
getDatabases(): Promise<string[]>;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
declare class PostgresDriver extends BaseDriver {
|
|
325
|
+
readonly type = DriverType.POSTGRES;
|
|
326
|
+
private pool;
|
|
327
|
+
private currentSchema;
|
|
328
|
+
constructor(config: PostgreSQLConfig);
|
|
329
|
+
connect(): Promise<void>;
|
|
330
|
+
disconnect(): Promise<void>;
|
|
331
|
+
isConnected(): boolean;
|
|
332
|
+
executeQuery(sql: string, params?: unknown[]): Promise<QueryResult>;
|
|
333
|
+
executeBatch(queries: string[]): Promise<QueryResult[]>;
|
|
334
|
+
getSchema(): Promise<SchemaInfo>;
|
|
335
|
+
getTables(): Promise<TableInfo[]>;
|
|
336
|
+
getTableInfo(tableName: string): Promise<TableInfo>;
|
|
337
|
+
getColumns(tableName: string): Promise<ColumnInfo[]>;
|
|
338
|
+
private mapPostgresType;
|
|
339
|
+
getIndexes(tableName: string): Promise<IndexInfo[]>;
|
|
340
|
+
getForeignKeys(tableName: string): Promise<ForeignKeyInfo[]>;
|
|
341
|
+
getViews(): Promise<ViewInfo[]>;
|
|
342
|
+
private getProcedures;
|
|
343
|
+
getTableRowCount(tableName: string): Promise<number>;
|
|
344
|
+
getVersion(): Promise<string>;
|
|
345
|
+
getDatabases(): Promise<string[]>;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
declare class MSSQLDriver extends BaseDriver {
|
|
349
|
+
readonly type = DriverType.MSSQL;
|
|
350
|
+
private connection;
|
|
351
|
+
constructor(config: MSSQLConfig);
|
|
352
|
+
connect(): Promise<void>;
|
|
353
|
+
disconnect(): Promise<void>;
|
|
354
|
+
isConnected(): boolean;
|
|
355
|
+
executeQuery(sql: string, _params?: unknown[]): Promise<QueryResult>;
|
|
356
|
+
executeBatch(queries: string[]): Promise<QueryResult[]>;
|
|
357
|
+
getSchema(): Promise<SchemaInfo>;
|
|
358
|
+
getTables(): Promise<TableInfo[]>;
|
|
359
|
+
getTableInfo(tableName: string): Promise<TableInfo>;
|
|
360
|
+
getColumns(tableName: string): Promise<ColumnInfo[]>;
|
|
361
|
+
getIndexes(tableName: string): Promise<IndexInfo[]>;
|
|
362
|
+
getForeignKeys(tableName: string): Promise<ForeignKeyInfo[]>;
|
|
363
|
+
getViews(): Promise<ViewInfo[]>;
|
|
364
|
+
getTableRowCount(tableName: string): Promise<number>;
|
|
365
|
+
getVersion(): Promise<string>;
|
|
366
|
+
getDatabases(): Promise<string[]>;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
declare function createDriver(config: DriverConfig): BaseDriver;
|
|
370
|
+
|
|
371
|
+
declare class SchemaBrowser {
|
|
372
|
+
private driver;
|
|
373
|
+
constructor(driver: BaseDriver);
|
|
374
|
+
getSchema(): Promise<SchemaInfo>;
|
|
375
|
+
getTables(filter?: SchemaFilter): Promise<TableInfo[]>;
|
|
376
|
+
getTable(name: string): Promise<TableInfo>;
|
|
377
|
+
getColumns(tableName: string): Promise<ColumnInfo[]>;
|
|
378
|
+
getIndexes(tableName: string): Promise<IndexInfo[]>;
|
|
379
|
+
getForeignKeys(tableName: string): Promise<ForeignKeyInfo[]>;
|
|
380
|
+
getViews(): Promise<ViewInfo[]>;
|
|
381
|
+
getTableRowCount(tableName: string): Promise<number>;
|
|
382
|
+
searchTables(query: string): Promise<TableInfo[]>;
|
|
383
|
+
getTableSummary(tableName: string): Promise<{
|
|
384
|
+
name: string;
|
|
385
|
+
columnCount: number;
|
|
386
|
+
indexCount: number;
|
|
387
|
+
foreignKeyCount: number;
|
|
388
|
+
rowCount: number;
|
|
389
|
+
size?: string;
|
|
390
|
+
}>;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
declare class QueryHistory {
|
|
394
|
+
private storage;
|
|
395
|
+
constructor(maxEntries?: number);
|
|
396
|
+
record(result: QueryResult, database: string, user?: string): QueryHistoryEntry;
|
|
397
|
+
list(params?: {
|
|
398
|
+
page?: number;
|
|
399
|
+
pageSize?: number;
|
|
400
|
+
database?: string;
|
|
401
|
+
status?: string;
|
|
402
|
+
search?: string;
|
|
403
|
+
}): PaginatedResult<QueryHistoryEntry>;
|
|
404
|
+
getRecent(limit?: number): QueryHistoryEntry[];
|
|
405
|
+
getStats(): {
|
|
406
|
+
totalQueries: number;
|
|
407
|
+
successfulQueries: number;
|
|
408
|
+
failedQueries: number;
|
|
409
|
+
avgDuration: number;
|
|
410
|
+
};
|
|
411
|
+
clear(): void;
|
|
412
|
+
remove(id: string): void;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
type DashboardEvents = {
|
|
416
|
+
query: (result: QueryResult) => void;
|
|
417
|
+
error: (error: Error, query?: string) => void;
|
|
418
|
+
connect: () => void;
|
|
419
|
+
disconnect: () => void;
|
|
420
|
+
warning: (warning: string) => void;
|
|
421
|
+
};
|
|
422
|
+
declare class SQLDashboard extends EventEmitter<DashboardEvents> {
|
|
423
|
+
readonly schema: SchemaBrowser;
|
|
424
|
+
readonly history: QueryHistory;
|
|
425
|
+
readonly config: DashboardConfig;
|
|
426
|
+
readonly version: string;
|
|
427
|
+
private driver;
|
|
428
|
+
private logger;
|
|
429
|
+
private readOnlyGuard?;
|
|
430
|
+
private rateLimiter?;
|
|
431
|
+
private connected;
|
|
432
|
+
private connectionPromise;
|
|
433
|
+
constructor(options: DashboardOptions);
|
|
434
|
+
private setupSecurity;
|
|
435
|
+
private setupEventHandlers;
|
|
436
|
+
connect(): Promise<void>;
|
|
437
|
+
disconnect(): Promise<void>;
|
|
438
|
+
query(sql: string, options?: QueryOptions): Promise<QueryResult>;
|
|
439
|
+
execute(sql: string, options?: QueryOptions): Promise<QueryResult>;
|
|
440
|
+
batch(queries: string[]): Promise<QueryResult[]>;
|
|
441
|
+
executeBatch(sql: string): Promise<QueryResult[]>;
|
|
442
|
+
transaction<T>(callback: (query: (sql: string, params?: unknown[]) => Promise<QueryResult>) => Promise<T>): Promise<T>;
|
|
443
|
+
explain(sql: string): Promise<QueryResult>;
|
|
444
|
+
analyze(sql: string): Promise<QueryResult>;
|
|
445
|
+
status(): Promise<{
|
|
446
|
+
connected: boolean;
|
|
447
|
+
driver: string;
|
|
448
|
+
version: string;
|
|
449
|
+
uptime: number;
|
|
450
|
+
history: {
|
|
451
|
+
total: number;
|
|
452
|
+
successful: number;
|
|
453
|
+
failed: number;
|
|
454
|
+
};
|
|
455
|
+
databaseVersion?: string;
|
|
456
|
+
}>;
|
|
457
|
+
getDriverVersion(): Promise<string>;
|
|
458
|
+
getDatabases(): Promise<string[]>;
|
|
459
|
+
validate(sql: string): ValidationResult;
|
|
460
|
+
private validateQuery;
|
|
461
|
+
private ensureConnected;
|
|
462
|
+
private withTimeout;
|
|
463
|
+
private getDriverType;
|
|
464
|
+
updateSecurity(config: Partial<SecurityConfig>): void;
|
|
465
|
+
destroy(): void;
|
|
466
|
+
}
|
|
467
|
+
declare function createDashboard(options: DashboardOptions): SQLDashboard;
|
|
468
|
+
|
|
469
|
+
declare class ReadOnlyGuard {
|
|
470
|
+
private rule;
|
|
471
|
+
constructor(rule?: ReadOnlyRule);
|
|
472
|
+
isAllowed(sql: string, user?: string): boolean;
|
|
473
|
+
checkReadOnly(sql: string, user?: string): {
|
|
474
|
+
allowed: boolean;
|
|
475
|
+
reason?: string;
|
|
476
|
+
};
|
|
477
|
+
updateRule(rule: Partial<ReadOnlyRule>): void;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
declare class RateLimiter {
|
|
481
|
+
private config;
|
|
482
|
+
private store;
|
|
483
|
+
private cleanupInterval;
|
|
484
|
+
constructor(config?: RateLimitConfig);
|
|
485
|
+
private cleanup;
|
|
486
|
+
check(key: string): {
|
|
487
|
+
allowed: boolean;
|
|
488
|
+
remaining: number;
|
|
489
|
+
resetAt: number;
|
|
490
|
+
error?: string;
|
|
491
|
+
};
|
|
492
|
+
getRemaining(key: string): number;
|
|
493
|
+
reset(key?: string): void;
|
|
494
|
+
updateConfig(config: Partial<RateLimitConfig>): void;
|
|
495
|
+
destroy(): void;
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
interface ExpressMiddlewareOptions extends DashboardOptions {
|
|
499
|
+
basePath?: string;
|
|
500
|
+
}
|
|
501
|
+
declare function createExpressRouter(options: ExpressMiddlewareOptions): Router;
|
|
502
|
+
declare function sqlDashboard(options: ExpressMiddlewareOptions): Router;
|
|
503
|
+
|
|
504
|
+
interface FastifyPluginConfig extends FastifyPluginOptions, DashboardOptions {
|
|
505
|
+
basePath?: string;
|
|
506
|
+
}
|
|
507
|
+
declare function registerFastifyPlugin(fastify: FastifyInstance, options: FastifyPluginConfig): Promise<void>;
|
|
508
|
+
|
|
509
|
+
interface CSVExportOptions {
|
|
510
|
+
delimiter?: string;
|
|
511
|
+
includeHeader?: boolean;
|
|
512
|
+
quoteAll?: boolean;
|
|
513
|
+
encoding?: string;
|
|
514
|
+
nullValue?: string;
|
|
515
|
+
}
|
|
516
|
+
declare function toCSV(result: QueryResult, options?: CSVExportOptions): string;
|
|
517
|
+
declare function toCSVStream(result: QueryResult, options?: CSVExportOptions): NodeJS.ReadableStream;
|
|
518
|
+
|
|
519
|
+
interface JSONExportOptions {
|
|
520
|
+
pretty?: boolean;
|
|
521
|
+
indent?: number;
|
|
522
|
+
dateFormat?: 'iso' | 'timestamp';
|
|
523
|
+
includeMeta?: boolean;
|
|
524
|
+
}
|
|
525
|
+
declare function toJSON(result: QueryResult, options?: JSONExportOptions): string;
|
|
526
|
+
declare function toJSONLines(result: QueryResult): string;
|
|
527
|
+
declare function toJSONArray(result: QueryResult): string;
|
|
528
|
+
|
|
529
|
+
declare function detectStatementType(sql: string): string;
|
|
530
|
+
declare function isReadOnlyStatement(sql: string): boolean;
|
|
531
|
+
declare function validateQuery(sql: string, security?: SecurityConfig): ValidationResult;
|
|
532
|
+
|
|
533
|
+
interface FormatOptions {
|
|
534
|
+
uppercase?: boolean;
|
|
535
|
+
indent?: string;
|
|
536
|
+
}
|
|
537
|
+
declare function formatSQL(sql: string, options?: FormatOptions): string;
|
|
538
|
+
declare function formatResultRow(row: Record<string, unknown>, columns?: string[]): Record<string, unknown>;
|
|
539
|
+
|
|
540
|
+
declare class Logger {
|
|
541
|
+
private config;
|
|
542
|
+
private timers;
|
|
543
|
+
constructor(config?: LoggerConfig);
|
|
544
|
+
private shouldLog;
|
|
545
|
+
private formatMessage;
|
|
546
|
+
debug(message: string, data?: unknown): void;
|
|
547
|
+
info(message: string, data?: unknown): void;
|
|
548
|
+
warn(message: string, data?: unknown): void;
|
|
549
|
+
error(message: string, data?: unknown): void;
|
|
550
|
+
query(sql: string, duration: number, rowCount: number): void;
|
|
551
|
+
startTimer(label: string): void;
|
|
552
|
+
endTimer(label: string): number;
|
|
553
|
+
updateConfig(config: Partial<LoggerConfig>): void;
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
declare class QueryTimer {
|
|
557
|
+
private startTime;
|
|
558
|
+
constructor();
|
|
559
|
+
get elapsed(): number;
|
|
560
|
+
reset(): void;
|
|
561
|
+
stop(): {
|
|
562
|
+
duration: number;
|
|
563
|
+
startTime: Date;
|
|
564
|
+
endTime: Date;
|
|
565
|
+
};
|
|
566
|
+
static measure<T>(fn: () => Promise<T>): Promise<{
|
|
567
|
+
result: T;
|
|
568
|
+
duration: number;
|
|
569
|
+
}>;
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
interface PaginationParams {
|
|
573
|
+
page?: number;
|
|
574
|
+
pageSize?: number;
|
|
575
|
+
offset?: number;
|
|
576
|
+
}
|
|
577
|
+
declare function createPaginatedResult<T>(data: T[], total: number, params: PaginationParams): PaginatedResult<T>;
|
|
578
|
+
|
|
579
|
+
export { type ColumnInfo, type DashboardOptions, type DriverConfig, DriverType, Logger, MSSQLDriver, MySQLDriver, type PaginatedResult, PostgresDriver, QueryHistory, type QueryHistoryEntry, type QueryOptions, type QueryResult, QueryTimer, RateLimiter, ReadOnlyGuard, SQLDashboard, SQLiteDriver, SchemaBrowser, type SchemaInfo, type SecurityConfig, type TableInfo, type ValidationResult, createDashboard, createDriver, createExpressRouter, createPaginatedResult, SQLDashboard as default, detectStatementType, formatResultRow, formatSQL, isReadOnlyStatement, registerFastifyPlugin, sqlDashboard, toCSV, toCSVStream, toJSON, toJSONArray, toJSONLines, validateQuery };
|