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/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 SQL Dashboard
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,494 @@
|
|
|
1
|
+
# SQL Dashboard
|
|
2
|
+
|
|
3
|
+
<div align="center">
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/sql-dashboard)
|
|
6
|
+
[](https://www.npmjs.com/package/sql-dashboard)
|
|
7
|
+
[](https://opensource.org/licenses/MIT)
|
|
8
|
+
[](https://www.typescriptlang.org/)
|
|
9
|
+
[](CONTRIBUTING.md)
|
|
10
|
+
[](https://github.com/Karan-Safaie-Qadi/sql-dashboard/actions/workflows/ci.yml)
|
|
11
|
+
|
|
12
|
+
**SQL Dashboard** - A professional, feature-rich SQL management library for Node.js admin panels.
|
|
13
|
+
|
|
14
|
+
Execute queries, browse schemas, manage databases, and build powerful admin interfaces with ease.
|
|
15
|
+
|
|
16
|
+
[Installation](#installation) •
|
|
17
|
+
[Quick Start](#quick-start) •
|
|
18
|
+
[Features](#features) •
|
|
19
|
+
[API Reference](#api-reference) •
|
|
20
|
+
[Examples](#examples) •
|
|
21
|
+
[Security](#security)
|
|
22
|
+
|
|
23
|
+
</div>
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## ✨ Features
|
|
28
|
+
|
|
29
|
+
| Feature | Description |
|
|
30
|
+
|---------|-------------|
|
|
31
|
+
| **🚀 Multi-Database** | SQLite (built-in), MySQL, PostgreSQL, MSSQL |
|
|
32
|
+
| **⚡ Query Execution** | Run SQL, batch queries, transactions, prepared statements |
|
|
33
|
+
| **📊 Schema Browser** | Browse tables, columns, indexes, foreign keys, views |
|
|
34
|
+
| **🔒 Security** | Read-only mode, rate limiting, SQL injection detection, query validation |
|
|
35
|
+
| **📝 Query History** | Auto-recorded history with search, stats, and pagination |
|
|
36
|
+
| **📦 Export** | CSV, JSON, JSON Lines export utilities |
|
|
37
|
+
| **🔌 Express Plugin** | Mount a full SQL admin REST API in one line |
|
|
38
|
+
| **⚡ Fastify Plugin** | Native Fastify plugin support |
|
|
39
|
+
| **📐 TypeScript** | Full type definitions, strict mode |
|
|
40
|
+
| **📋 Query Formatting** | Built-in SQL formatter |
|
|
41
|
+
| **⏱ Performance** | Query timing, slow query logging, connection pooling |
|
|
42
|
+
| **🌐 Zero Config** | Works out of the box with SQLite (in-memory or file-based) |
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## 📦 Installation
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
npm install sql-dashboard
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Optional Drivers
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
# For MySQL support
|
|
56
|
+
npm install mysql2
|
|
57
|
+
|
|
58
|
+
# For PostgreSQL support
|
|
59
|
+
npm install pg
|
|
60
|
+
|
|
61
|
+
# For MSSQL support
|
|
62
|
+
npm install tedious
|
|
63
|
+
|
|
64
|
+
# For Express middleware
|
|
65
|
+
npm install express
|
|
66
|
+
|
|
67
|
+
# For Fastify plugin
|
|
68
|
+
npm install fastify
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## 🚀 Quick Start
|
|
74
|
+
|
|
75
|
+
### Basic Usage (30 seconds)
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
import { SQLDashboard } from 'sql-dashboard';
|
|
79
|
+
import { DriverType } from 'sql-dashboard';
|
|
80
|
+
|
|
81
|
+
// 1 line initialization
|
|
82
|
+
const db = new SQLDashboard({
|
|
83
|
+
driver: {
|
|
84
|
+
type: DriverType.SQLITE,
|
|
85
|
+
connection: { mode: 'memory' }, // or { path: './data.db' }
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
// Run queries
|
|
90
|
+
const result = await db.query('SELECT * FROM users WHERE age > ?', {
|
|
91
|
+
params: [18],
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
console.log(result.rows); // Array of rows
|
|
95
|
+
console.log(result.columns); // Column names
|
|
96
|
+
console.log(result.duration); // Execution time (ms)
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### With Express (10 seconds)
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
import express from 'express';
|
|
103
|
+
import { sqlDashboard } from 'sql-dashboard/express';
|
|
104
|
+
|
|
105
|
+
const app = express();
|
|
106
|
+
app.use(express.json());
|
|
107
|
+
|
|
108
|
+
// Mount full SQL dashboard API in one line
|
|
109
|
+
app.use(sqlDashboard({
|
|
110
|
+
driver: { type: 'sqlite', connection: { path: './data.db' } },
|
|
111
|
+
basePath: '/admin/sql',
|
|
112
|
+
}));
|
|
113
|
+
|
|
114
|
+
app.listen(3000);
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
**Now you have a full SQL admin REST API:**
|
|
118
|
+
|
|
119
|
+
```
|
|
120
|
+
POST /admin/sql/query - Execute SQL
|
|
121
|
+
GET /admin/sql/schema - Browse schema
|
|
122
|
+
GET /admin/sql/tables - List tables
|
|
123
|
+
GET /admin/sql/status - Dashboard status
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
---
|
|
127
|
+
|
|
128
|
+
## 📚 API Reference
|
|
129
|
+
|
|
130
|
+
### `SQLDashboard`
|
|
131
|
+
|
|
132
|
+
The main class for all database operations.
|
|
133
|
+
|
|
134
|
+
```typescript
|
|
135
|
+
import { SQLDashboard, DriverType } from 'sql-dashboard';
|
|
136
|
+
|
|
137
|
+
const db = new SQLDashboard(options: DashboardOptions);
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
#### Options
|
|
141
|
+
|
|
142
|
+
| Option | Type | Default | Description |
|
|
143
|
+
|--------|------|---------|-------------|
|
|
144
|
+
| `driver` | `DriverConfig` | required | Database connection config |
|
|
145
|
+
| `security` | `SecurityConfig` | `{}` | Security settings |
|
|
146
|
+
| `logger` | `LoggerConfig` | `{ level: 'info' }` | Logger configuration |
|
|
147
|
+
| `autoConnect` | `boolean` | `true` | Auto-connect on instantiation |
|
|
148
|
+
|
|
149
|
+
#### Methods
|
|
150
|
+
|
|
151
|
+
```typescript
|
|
152
|
+
// Execute a query
|
|
153
|
+
const result: QueryResult = await db.query(sql, options?);
|
|
154
|
+
|
|
155
|
+
// Execute with separate params
|
|
156
|
+
const result = await db.query('SELECT * FROM users WHERE id = ?', { params: [1] });
|
|
157
|
+
|
|
158
|
+
// Batch execution
|
|
159
|
+
const results: QueryResult[] = await db.batch(['INSERT INTO ...', 'UPDATE ...']);
|
|
160
|
+
|
|
161
|
+
// Transaction
|
|
162
|
+
const result = await db.transaction(async (query) => {
|
|
163
|
+
const r1 = await query('INSERT INTO ...');
|
|
164
|
+
const r2 = await query('UPDATE ...');
|
|
165
|
+
return r2;
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
// Explain query plan
|
|
169
|
+
const plan = await db.explain('SELECT * FROM users');
|
|
170
|
+
|
|
171
|
+
// Database status
|
|
172
|
+
const status = await db.status();
|
|
173
|
+
|
|
174
|
+
// Validate without executing
|
|
175
|
+
const validation = db.validate('SELECT * FROM users');
|
|
176
|
+
|
|
177
|
+
// Schema browsing
|
|
178
|
+
const schema = await db.schema.getSchema();
|
|
179
|
+
const tables = await db.schema.getTables();
|
|
180
|
+
const columns = await db.schema.getColumns('users');
|
|
181
|
+
const indexes = await db.schema.getIndexes('users');
|
|
182
|
+
|
|
183
|
+
// Query history
|
|
184
|
+
const history = db.history.list({ page: 1, pageSize: 50 });
|
|
185
|
+
const stats = db.history.getStats();
|
|
186
|
+
|
|
187
|
+
// Export
|
|
188
|
+
import { toCSV, toJSON } from 'sql-dashboard/export';
|
|
189
|
+
const csv = toCSV(result);
|
|
190
|
+
const json = toJSON(result);
|
|
191
|
+
|
|
192
|
+
// Cleanup
|
|
193
|
+
db.destroy();
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
#### `QueryResult`
|
|
197
|
+
|
|
198
|
+
```typescript
|
|
199
|
+
interface QueryResult {
|
|
200
|
+
id: string; // Unique query ID
|
|
201
|
+
status: 'success' | 'error';
|
|
202
|
+
rows: Record<string, unknown>[]; // Result rows
|
|
203
|
+
columns: string[]; // Column names
|
|
204
|
+
rowCount: number; // Number of rows
|
|
205
|
+
affectedRows?: number; // For INSERT/UPDATE/DELETE
|
|
206
|
+
duration: number; // Execution time (ms)
|
|
207
|
+
query: string; // Original query
|
|
208
|
+
error?: string; // Error message if failed
|
|
209
|
+
insertedId?: string | number; // Last inserted ID
|
|
210
|
+
}
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
---
|
|
214
|
+
|
|
215
|
+
## 🔐 Security
|
|
216
|
+
|
|
217
|
+
SQL Dashboard comes with enterprise-grade security features:
|
|
218
|
+
|
|
219
|
+
```typescript
|
|
220
|
+
const db = new SQLDashboard({
|
|
221
|
+
driver: { type: 'sqlite', connection: { mode: 'memory' } },
|
|
222
|
+
security: {
|
|
223
|
+
// Read-only mode: blocks all write operations
|
|
224
|
+
readOnly: true,
|
|
225
|
+
|
|
226
|
+
// Or with fine-grained control
|
|
227
|
+
readOnly: {
|
|
228
|
+
allowSelect: true,
|
|
229
|
+
allowShow: true,
|
|
230
|
+
bypassUsers: ['admin'],
|
|
231
|
+
},
|
|
232
|
+
|
|
233
|
+
// Rate limiting: prevent abuse
|
|
234
|
+
rateLimit: {
|
|
235
|
+
enabled: true,
|
|
236
|
+
windowMs: 60000, // 1 minute
|
|
237
|
+
maxQueries: 100, // Max 100 queries per minute
|
|
238
|
+
},
|
|
239
|
+
|
|
240
|
+
// Banned statements
|
|
241
|
+
bannedStatements: ['DROP', 'TRUNCATE', 'GRANT'],
|
|
242
|
+
|
|
243
|
+
// Require WHERE clause for UPDATE/DELETE (prevents accidents)
|
|
244
|
+
requireWhere: true,
|
|
245
|
+
|
|
246
|
+
// Maximum query length
|
|
247
|
+
maxQueryLength: 10000,
|
|
248
|
+
|
|
249
|
+
// Maximum rows returned
|
|
250
|
+
maxRows: 1000,
|
|
251
|
+
|
|
252
|
+
// Query timeout (ms)
|
|
253
|
+
queryTimeout: 30000,
|
|
254
|
+
},
|
|
255
|
+
});
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
### SQL Injection Protection
|
|
259
|
+
|
|
260
|
+
All queries are automatically scanned for SQL injection patterns.
|
|
261
|
+
|
|
262
|
+
---
|
|
263
|
+
|
|
264
|
+
## 🗄 Database Drivers
|
|
265
|
+
|
|
266
|
+
### SQLite (built-in, no dependencies)
|
|
267
|
+
|
|
268
|
+
```typescript
|
|
269
|
+
const db = new SQLDashboard({
|
|
270
|
+
driver: {
|
|
271
|
+
type: 'sqlite',
|
|
272
|
+
connection: { mode: 'memory' }, // In-memory database
|
|
273
|
+
// or
|
|
274
|
+
connection: { path: './data/database.db' }, // File-based
|
|
275
|
+
},
|
|
276
|
+
});
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
### MySQL
|
|
280
|
+
|
|
281
|
+
```typescript
|
|
282
|
+
// npm install mysql2
|
|
283
|
+
const db = new SQLDashboard({
|
|
284
|
+
driver: {
|
|
285
|
+
type: 'mysql',
|
|
286
|
+
connection: {
|
|
287
|
+
host: 'localhost',
|
|
288
|
+
port: 3306,
|
|
289
|
+
user: 'root',
|
|
290
|
+
password: 'password',
|
|
291
|
+
database: 'myapp',
|
|
292
|
+
},
|
|
293
|
+
},
|
|
294
|
+
});
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
### PostgreSQL
|
|
298
|
+
|
|
299
|
+
```typescript
|
|
300
|
+
// npm install pg
|
|
301
|
+
const db = new SQLDashboard({
|
|
302
|
+
driver: {
|
|
303
|
+
type: 'postgres',
|
|
304
|
+
connection: {
|
|
305
|
+
host: 'localhost',
|
|
306
|
+
port: 5432,
|
|
307
|
+
user: 'postgres',
|
|
308
|
+
password: 'password',
|
|
309
|
+
database: 'myapp',
|
|
310
|
+
schema: 'public',
|
|
311
|
+
},
|
|
312
|
+
},
|
|
313
|
+
});
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
### MSSQL
|
|
317
|
+
|
|
318
|
+
```typescript
|
|
319
|
+
// npm install tedious
|
|
320
|
+
const db = new SQLDashboard({
|
|
321
|
+
driver: {
|
|
322
|
+
type: 'mssql',
|
|
323
|
+
connection: {
|
|
324
|
+
server: 'localhost',
|
|
325
|
+
port: 1433,
|
|
326
|
+
user: 'sa',
|
|
327
|
+
password: 'password',
|
|
328
|
+
database: 'myapp',
|
|
329
|
+
},
|
|
330
|
+
},
|
|
331
|
+
});
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
---
|
|
335
|
+
|
|
336
|
+
## 📊 Schema Browser
|
|
337
|
+
|
|
338
|
+
Explore your entire database structure programmatically:
|
|
339
|
+
|
|
340
|
+
```typescript
|
|
341
|
+
// Get complete schema
|
|
342
|
+
const schema = await db.schema.getSchema();
|
|
343
|
+
|
|
344
|
+
// List all tables
|
|
345
|
+
const tables = await db.schema.getTables();
|
|
346
|
+
|
|
347
|
+
// Get detailed table info
|
|
348
|
+
const table = await db.schema.getTable('users');
|
|
349
|
+
// table.columns - Column definitions
|
|
350
|
+
// table.indexes - Index information
|
|
351
|
+
// table.foreignKeys - Foreign key relationships
|
|
352
|
+
// table.rowCount - Approximate row count
|
|
353
|
+
|
|
354
|
+
// Get specific details
|
|
355
|
+
const columns = await db.schema.getColumns('users');
|
|
356
|
+
const indexes = await db.schema.getIndexes('users');
|
|
357
|
+
const foreignKeys = await db.schema.getForeignKeys('users');
|
|
358
|
+
const views = await db.schema.getViews();
|
|
359
|
+
|
|
360
|
+
// Get table summary
|
|
361
|
+
const summary = await db.schema.getTableSummary('users');
|
|
362
|
+
// { name, columnCount, indexCount, foreignKeyCount, rowCount, size }
|
|
363
|
+
|
|
364
|
+
// Search tables
|
|
365
|
+
const results = await db.schema.searchTables('user');
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
---
|
|
369
|
+
|
|
370
|
+
## 📝 Query History
|
|
371
|
+
|
|
372
|
+
Every query is automatically recorded:
|
|
373
|
+
|
|
374
|
+
```typescript
|
|
375
|
+
// List history with pagination
|
|
376
|
+
const history = db.history.list({
|
|
377
|
+
page: 1,
|
|
378
|
+
pageSize: 50,
|
|
379
|
+
database: 'myapp',
|
|
380
|
+
status: 'success',
|
|
381
|
+
search: 'SELECT',
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
// Get recent queries
|
|
385
|
+
const recent = db.history.getRecent(10);
|
|
386
|
+
|
|
387
|
+
// Get statistics
|
|
388
|
+
const stats = db.history.getStats();
|
|
389
|
+
// { totalQueries, successfulQueries, failedQueries, avgDuration }
|
|
390
|
+
|
|
391
|
+
// Clear history
|
|
392
|
+
db.history.clear();
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
---
|
|
396
|
+
|
|
397
|
+
## 💾 Export
|
|
398
|
+
|
|
399
|
+
```typescript
|
|
400
|
+
import { toCSV, toJSON, toJSONLines } from 'sql-dashboard/export';
|
|
401
|
+
|
|
402
|
+
const result = await db.query('SELECT * FROM users');
|
|
403
|
+
|
|
404
|
+
// CSV export
|
|
405
|
+
const csv = toCSV(result, { delimiter: ',', includeHeader: true });
|
|
406
|
+
fs.writeFileSync('users.csv', csv);
|
|
407
|
+
|
|
408
|
+
// JSON export
|
|
409
|
+
const json = toJSON(result, { pretty: true, includeMeta: false });
|
|
410
|
+
|
|
411
|
+
// JSON Lines (one JSON object per line)
|
|
412
|
+
const jsonl = toJSONLines(result);
|
|
413
|
+
```
|
|
414
|
+
|
|
415
|
+
---
|
|
416
|
+
|
|
417
|
+
## 🎯 Use Cases
|
|
418
|
+
|
|
419
|
+
### Admin Panel Backend
|
|
420
|
+
Mount the Express middleware and get a complete SQL management REST API.
|
|
421
|
+
|
|
422
|
+
### Development Tools
|
|
423
|
+
Quick database inspection, query debugging, schema exploration.
|
|
424
|
+
|
|
425
|
+
### Data Migration
|
|
426
|
+
Batch queries, transactions, export/import utilities.
|
|
427
|
+
|
|
428
|
+
### Monitoring
|
|
429
|
+
Query history, slow query logging, performance stats.
|
|
430
|
+
|
|
431
|
+
### Custom Admin Interfaces
|
|
432
|
+
Build your own admin panel on top of the robust API.
|
|
433
|
+
|
|
434
|
+
---
|
|
435
|
+
|
|
436
|
+
## 📖 Examples
|
|
437
|
+
|
|
438
|
+
Check out the [examples](./examples) directory:
|
|
439
|
+
|
|
440
|
+
- **basic.ts** - Quick start with all core features
|
|
441
|
+
- **express.ts** - Express middleware integration
|
|
442
|
+
- **admin-panel.ts** - Full admin panel example
|
|
443
|
+
|
|
444
|
+
---
|
|
445
|
+
|
|
446
|
+
## 🛠 Development
|
|
447
|
+
|
|
448
|
+
```bash
|
|
449
|
+
# Clone
|
|
450
|
+
git clone https://github.com/Karan-Safaie-Qadi/sql-dashboard.git
|
|
451
|
+
|
|
452
|
+
# Install dependencies
|
|
453
|
+
npm install
|
|
454
|
+
|
|
455
|
+
# Build
|
|
456
|
+
npm run build:all
|
|
457
|
+
|
|
458
|
+
# Test
|
|
459
|
+
npm test
|
|
460
|
+
|
|
461
|
+
# Watch mode
|
|
462
|
+
npm run dev
|
|
463
|
+
```
|
|
464
|
+
|
|
465
|
+
---
|
|
466
|
+
|
|
467
|
+
## 🤝 Contributing
|
|
468
|
+
|
|
469
|
+
Contributions are welcome! Please read our [Contributing Guidelines](CONTRIBUTING.md).
|
|
470
|
+
|
|
471
|
+
1. Fork the repository
|
|
472
|
+
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
|
|
473
|
+
3. Commit your changes (`git commit -m 'Add amazing feature'`)
|
|
474
|
+
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
475
|
+
5. Open a Pull Request
|
|
476
|
+
|
|
477
|
+
---
|
|
478
|
+
|
|
479
|
+
## 📄 License
|
|
480
|
+
|
|
481
|
+
MIT License - see the [LICENSE](LICENSE) file for details.
|
|
482
|
+
|
|
483
|
+
---
|
|
484
|
+
|
|
485
|
+
## 🙏 Support
|
|
486
|
+
|
|
487
|
+
- [GitHub Issues](https://github.com/Karan-Safaie-Qadi/sql-dashboard/issues)
|
|
488
|
+
- [Documentation](https://github.com/Karan-Safaie-Qadi/sql-dashboard/wiki)
|
|
489
|
+
|
|
490
|
+
---
|
|
491
|
+
|
|
492
|
+
<div align="center">
|
|
493
|
+
Made with ❤️ for the open source community
|
|
494
|
+
</div>
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { D as DriverType } from './connection-CzduPMhl.mjs';
|
|
2
|
+
import { Q as QueryResult } from './query-BFhJHNeb.mjs';
|
|
3
|
+
|
|
4
|
+
interface SchemaInfo {
|
|
5
|
+
name: string;
|
|
6
|
+
tables: TableInfo[];
|
|
7
|
+
views: ViewInfo[];
|
|
8
|
+
procedures: ProcedureInfo[];
|
|
9
|
+
}
|
|
10
|
+
interface TableInfo {
|
|
11
|
+
name: string;
|
|
12
|
+
schema: string;
|
|
13
|
+
type: 'table' | 'view';
|
|
14
|
+
columns: ColumnInfo[];
|
|
15
|
+
indexes: IndexInfo[];
|
|
16
|
+
foreignKeys: ForeignKeyInfo[];
|
|
17
|
+
rowCount?: number;
|
|
18
|
+
size?: string;
|
|
19
|
+
comment?: string;
|
|
20
|
+
createdAt?: Date;
|
|
21
|
+
updatedAt?: Date;
|
|
22
|
+
engine?: string;
|
|
23
|
+
collation?: string;
|
|
24
|
+
}
|
|
25
|
+
interface ColumnInfo {
|
|
26
|
+
name: string;
|
|
27
|
+
type: string;
|
|
28
|
+
nullable: boolean;
|
|
29
|
+
primaryKey: boolean;
|
|
30
|
+
defaultValue?: string | null;
|
|
31
|
+
autoIncrement?: boolean;
|
|
32
|
+
maxLength?: number;
|
|
33
|
+
precision?: number;
|
|
34
|
+
scale?: number;
|
|
35
|
+
comment?: string;
|
|
36
|
+
enumValues?: string[];
|
|
37
|
+
foreignKey?: {
|
|
38
|
+
table: string;
|
|
39
|
+
column: string;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
interface IndexInfo {
|
|
43
|
+
name: string;
|
|
44
|
+
columns: string[];
|
|
45
|
+
unique: boolean;
|
|
46
|
+
primary: boolean;
|
|
47
|
+
type: string;
|
|
48
|
+
method?: string;
|
|
49
|
+
}
|
|
50
|
+
interface ForeignKeyInfo {
|
|
51
|
+
name: string;
|
|
52
|
+
column: string;
|
|
53
|
+
referencedSchema: string;
|
|
54
|
+
referencedTable: string;
|
|
55
|
+
referencedColumn: string;
|
|
56
|
+
onDelete: string;
|
|
57
|
+
onUpdate: string;
|
|
58
|
+
}
|
|
59
|
+
interface ViewInfo {
|
|
60
|
+
name: string;
|
|
61
|
+
schema: string;
|
|
62
|
+
definition: string;
|
|
63
|
+
columns: ColumnInfo[];
|
|
64
|
+
}
|
|
65
|
+
interface ProcedureInfo {
|
|
66
|
+
name: string;
|
|
67
|
+
schema: string;
|
|
68
|
+
type: 'procedure' | 'function';
|
|
69
|
+
params: {
|
|
70
|
+
name: string;
|
|
71
|
+
type: string;
|
|
72
|
+
mode: 'IN' | 'OUT' | 'INOUT';
|
|
73
|
+
}[];
|
|
74
|
+
returnType?: string;
|
|
75
|
+
definition: string;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
declare abstract class BaseDriver {
|
|
79
|
+
abstract readonly type: DriverType;
|
|
80
|
+
protected connected: boolean;
|
|
81
|
+
protected config: Record<string, unknown>;
|
|
82
|
+
abstract connect(): Promise<void>;
|
|
83
|
+
abstract disconnect(): Promise<void>;
|
|
84
|
+
abstract executeQuery(sql: string, params?: unknown[]): Promise<QueryResult>;
|
|
85
|
+
abstract executeBatch(queries: string[]): Promise<QueryResult[]>;
|
|
86
|
+
abstract isConnected(): boolean;
|
|
87
|
+
protected createResult(query: string, rows: Record<string, unknown>[], duration: number, affectedRows?: number): QueryResult;
|
|
88
|
+
protected createErrorResult(query: string, error: Error, duration: number): QueryResult;
|
|
89
|
+
protected ensureConnected(): void;
|
|
90
|
+
abstract getSchema(): Promise<SchemaInfo>;
|
|
91
|
+
abstract getTables(): Promise<TableInfo[]>;
|
|
92
|
+
abstract getTableInfo(tableName: string): Promise<TableInfo>;
|
|
93
|
+
abstract getColumns(tableName: string): Promise<ColumnInfo[]>;
|
|
94
|
+
abstract getIndexes(tableName: string): Promise<IndexInfo[]>;
|
|
95
|
+
abstract getForeignKeys(tableName: string): Promise<ForeignKeyInfo[]>;
|
|
96
|
+
abstract getViews(): Promise<ViewInfo[]>;
|
|
97
|
+
abstract getTableRowCount(tableName: string): Promise<number>;
|
|
98
|
+
abstract getVersion(): Promise<string>;
|
|
99
|
+
abstract getDatabases(): Promise<string[]>;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export { BaseDriver as B, type ColumnInfo as C, type ForeignKeyInfo as F, type IndexInfo as I, type SchemaInfo as S, type TableInfo as T, type ViewInfo as V };
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { D as DriverType } from './connection-CzduPMhl.js';
|
|
2
|
+
import { Q as QueryResult } from './query-BFhJHNeb.js';
|
|
3
|
+
|
|
4
|
+
interface SchemaInfo {
|
|
5
|
+
name: string;
|
|
6
|
+
tables: TableInfo[];
|
|
7
|
+
views: ViewInfo[];
|
|
8
|
+
procedures: ProcedureInfo[];
|
|
9
|
+
}
|
|
10
|
+
interface TableInfo {
|
|
11
|
+
name: string;
|
|
12
|
+
schema: string;
|
|
13
|
+
type: 'table' | 'view';
|
|
14
|
+
columns: ColumnInfo[];
|
|
15
|
+
indexes: IndexInfo[];
|
|
16
|
+
foreignKeys: ForeignKeyInfo[];
|
|
17
|
+
rowCount?: number;
|
|
18
|
+
size?: string;
|
|
19
|
+
comment?: string;
|
|
20
|
+
createdAt?: Date;
|
|
21
|
+
updatedAt?: Date;
|
|
22
|
+
engine?: string;
|
|
23
|
+
collation?: string;
|
|
24
|
+
}
|
|
25
|
+
interface ColumnInfo {
|
|
26
|
+
name: string;
|
|
27
|
+
type: string;
|
|
28
|
+
nullable: boolean;
|
|
29
|
+
primaryKey: boolean;
|
|
30
|
+
defaultValue?: string | null;
|
|
31
|
+
autoIncrement?: boolean;
|
|
32
|
+
maxLength?: number;
|
|
33
|
+
precision?: number;
|
|
34
|
+
scale?: number;
|
|
35
|
+
comment?: string;
|
|
36
|
+
enumValues?: string[];
|
|
37
|
+
foreignKey?: {
|
|
38
|
+
table: string;
|
|
39
|
+
column: string;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
interface IndexInfo {
|
|
43
|
+
name: string;
|
|
44
|
+
columns: string[];
|
|
45
|
+
unique: boolean;
|
|
46
|
+
primary: boolean;
|
|
47
|
+
type: string;
|
|
48
|
+
method?: string;
|
|
49
|
+
}
|
|
50
|
+
interface ForeignKeyInfo {
|
|
51
|
+
name: string;
|
|
52
|
+
column: string;
|
|
53
|
+
referencedSchema: string;
|
|
54
|
+
referencedTable: string;
|
|
55
|
+
referencedColumn: string;
|
|
56
|
+
onDelete: string;
|
|
57
|
+
onUpdate: string;
|
|
58
|
+
}
|
|
59
|
+
interface ViewInfo {
|
|
60
|
+
name: string;
|
|
61
|
+
schema: string;
|
|
62
|
+
definition: string;
|
|
63
|
+
columns: ColumnInfo[];
|
|
64
|
+
}
|
|
65
|
+
interface ProcedureInfo {
|
|
66
|
+
name: string;
|
|
67
|
+
schema: string;
|
|
68
|
+
type: 'procedure' | 'function';
|
|
69
|
+
params: {
|
|
70
|
+
name: string;
|
|
71
|
+
type: string;
|
|
72
|
+
mode: 'IN' | 'OUT' | 'INOUT';
|
|
73
|
+
}[];
|
|
74
|
+
returnType?: string;
|
|
75
|
+
definition: string;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
declare abstract class BaseDriver {
|
|
79
|
+
abstract readonly type: DriverType;
|
|
80
|
+
protected connected: boolean;
|
|
81
|
+
protected config: Record<string, unknown>;
|
|
82
|
+
abstract connect(): Promise<void>;
|
|
83
|
+
abstract disconnect(): Promise<void>;
|
|
84
|
+
abstract executeQuery(sql: string, params?: unknown[]): Promise<QueryResult>;
|
|
85
|
+
abstract executeBatch(queries: string[]): Promise<QueryResult[]>;
|
|
86
|
+
abstract isConnected(): boolean;
|
|
87
|
+
protected createResult(query: string, rows: Record<string, unknown>[], duration: number, affectedRows?: number): QueryResult;
|
|
88
|
+
protected createErrorResult(query: string, error: Error, duration: number): QueryResult;
|
|
89
|
+
protected ensureConnected(): void;
|
|
90
|
+
abstract getSchema(): Promise<SchemaInfo>;
|
|
91
|
+
abstract getTables(): Promise<TableInfo[]>;
|
|
92
|
+
abstract getTableInfo(tableName: string): Promise<TableInfo>;
|
|
93
|
+
abstract getColumns(tableName: string): Promise<ColumnInfo[]>;
|
|
94
|
+
abstract getIndexes(tableName: string): Promise<IndexInfo[]>;
|
|
95
|
+
abstract getForeignKeys(tableName: string): Promise<ForeignKeyInfo[]>;
|
|
96
|
+
abstract getViews(): Promise<ViewInfo[]>;
|
|
97
|
+
abstract getTableRowCount(tableName: string): Promise<number>;
|
|
98
|
+
abstract getVersion(): Promise<string>;
|
|
99
|
+
abstract getDatabases(): Promise<string[]>;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export { BaseDriver as B, type ColumnInfo as C, type ForeignKeyInfo as F, type IndexInfo as I, type SchemaInfo as S, type TableInfo as T, type ViewInfo as V };
|