db-ai 1.0.2 → 2.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.
@@ -0,0 +1,30 @@
1
+ # Configuration Notes
2
+
3
+ ## Database Provider
4
+
5
+ The `provider` field in dbConfig.json specifies your database type:
6
+ - `postgresql` - PostgreSQL
7
+ - `mysql` - MySQL
8
+ - `sqlite` - SQLite
9
+ - `sqlserver` - SQL Server
10
+
11
+ **Important**: Make sure to install the required Prisma driver for your database provider.
12
+ For example, if using PostgreSQL, ensure `@prisma/client` is installed.
13
+
14
+ ## OPERATIONS_ALLOWED
15
+
16
+ This array specifies which SQL operations are allowed:
17
+ - `SELECT` - Read queries
18
+ - `INSERT` - Insert operations
19
+ - `UPDATE` - Update operations
20
+ - `DELETE` - Delete operations
21
+ - `CREATE` - Create table/index operations
22
+ - `DROP` - Drop operations
23
+ - `ALTER` - Alter table operations
24
+
25
+ Default is `["SELECT"]` for safety.
26
+
27
+ ## outputFileName
28
+
29
+ If specified, all query results will be appended to this file with timestamps.
30
+ Leave empty or remove this field to disable file logging.
@@ -0,0 +1,12 @@
1
+ {
2
+ "provider": "postgresql",
3
+ "host": "localhost",
4
+ "port": 5432,
5
+ "user": "world",
6
+ "password": "world123",
7
+ "database": "world-db",
8
+ "OPERATIONS_ALLOWED": [
9
+ "SELECT"
10
+ ],
11
+ "outputFileName": "output.txt"
12
+ }
@@ -0,0 +1,77 @@
1
+ # db-ai Instructions for AI
2
+
3
+ This document outlines the available functions and resources for interacting with the database.
4
+
5
+ ## Quick Start - Running SQL Queries
6
+
7
+ The easiest way to run SQL queries is using the CLI command:
8
+
9
+ ```bash
10
+ db-ai run --sql "SELECT * FROM users LIMIT 10"
11
+ ```
12
+
13
+ This will:
14
+ - Execute the SQL query against the database
15
+ - Return and display the output
16
+ - Automatically log the query and results to the output file (if `outputFileName` is configured in `dbConfig.json`)
17
+
18
+ **Important**: All SQL queries that run (whether via CLI or programmatically) are automatically logged to the output file specified in `dbConfig.json` (e.g., `output.txt`) with timestamps, if that configuration exists.
19
+
20
+ ## Available Functions
21
+
22
+ ### 1. `executeQuery(sql: string)`
23
+ Executes a SQL query and returns the result.
24
+ - **Parameters**: `sql` - SQL query string
25
+ - **Returns**: `QueryResult` object with `data`, `timestamp`, and `query` fields
26
+ - **Example**:
27
+ ```typescript
28
+ const result = await executeQuery("SELECT * FROM users LIMIT 10");
29
+ console.log(result.data);
30
+ ```
31
+
32
+ ### 2. `executeAndPrint(sql: string)`
33
+ Executes a SQL query, returns the result, and prints it to the console.
34
+ - **Parameters**: `sql` - SQL query string
35
+ - **Returns**: `QueryResult` object with `data`, `timestamp`, and `query` fields
36
+ - **Example**:
37
+ ```typescript
38
+ await executeAndPrint("SELECT COUNT(*) FROM users");
39
+ ```
40
+
41
+ ## Schema File
42
+
43
+ The database schema is stored in `.db-ai/schema.prisma`. This file contains the up-to-date database structure including:
44
+ - Tables and their columns
45
+ - Data types
46
+ - Relationships
47
+ - Constraints
48
+
49
+ Refer to this file to understand the database structure before writing queries.
50
+
51
+ ## Configuration
52
+
53
+ The configuration file `.db-ai/dbConfig.json` contains:
54
+ - Database connection details
55
+ - `OPERATIONS_ALLOWED`: Array of allowed SQL operations (default: `["SELECT"]`)
56
+ - `outputFileName`: Optional file name for logging query results with timestamps
57
+
58
+ ## Usage in Scripts
59
+
60
+ You can create TypeScript files (like `Script1.ts`) to run SQL queries. Import the functions from the query executor:
61
+
62
+ ```typescript
63
+ import { executeQuery, executeAndPrint } from 'db-ai/dist/core/queryExecutor';
64
+
65
+ // Your queries here
66
+ const result = await executeQuery("SELECT * FROM table_name");
67
+ ```
68
+
69
+ **Note**: Make sure db-ai is installed in your project: `npm install db-ai`
70
+
71
+ ## Important Notes
72
+
73
+ - **CLI Usage**: You can use `db-ai run --sql "your SQL query"` to execute SQL directly from the command line
74
+ - **Output Logging**: All SQL queries that run (via CLI or programmatically) are automatically logged to the output file specified in `dbConfig.json` (e.g., `output.txt`) with timestamps, if `outputFileName` is configured
75
+ - **Security**: Only operations listed in `OPERATIONS_ALLOWED` can be executed
76
+ - **Schema Reference**: Always check the schema file (`.db-ai/schema.prisma`) before writing queries to ensure table and column names are correct
77
+
@@ -0,0 +1,657 @@
1
+
2
+ === Query Execution ===
3
+ Timestamp: 2025-12-29T05:28:29.447Z
4
+ Query: SELECT COUNT(*) as total_cities FROM city
5
+ Result: [
6
+ {
7
+ "total_cities": "4079"
8
+ }
9
+ ]
10
+ ===========================================
11
+
12
+ === Query Execution ===
13
+ Timestamp: 2025-12-29T05:28:29.497Z
14
+ Query:
15
+ SELECT
16
+ c.continent,
17
+ COUNT(ci.id) as city_count
18
+ FROM country c
19
+ LEFT JOIN city ci ON ci.country_code = c.code
20
+ GROUP BY c.continent
21
+ ORDER BY city_count DESC
22
+
23
+ Result: [
24
+ {
25
+ "continent": "Asia",
26
+ "city_count": "1766"
27
+ },
28
+ {
29
+ "continent": "Europe",
30
+ "city_count": "841"
31
+ },
32
+ {
33
+ "continent": "North America",
34
+ "city_count": "581"
35
+ },
36
+ {
37
+ "continent": "South America",
38
+ "city_count": "470"
39
+ },
40
+ {
41
+ "continent": "Africa",
42
+ "city_count": "366"
43
+ },
44
+ {
45
+ "continent": "Oceania",
46
+ "city_count": "55"
47
+ },
48
+ {
49
+ "continent": "Antarctica",
50
+ "city_count": "0"
51
+ }
52
+ ]
53
+ ===========================================
54
+
55
+ === Query Execution ===
56
+ Timestamp: 2025-12-29T05:28:29.504Z
57
+ Query:
58
+ SELECT
59
+ name,
60
+ country_code,
61
+ district,
62
+ population
63
+ FROM city
64
+ ORDER BY population DESC
65
+ LIMIT 10
66
+
67
+ Result: [
68
+ {
69
+ "name": "Mumbai (Bombay)",
70
+ "country_code": "IND",
71
+ "district": "Maharashtra",
72
+ "population": 10500000
73
+ },
74
+ {
75
+ "name": "Seoul",
76
+ "country_code": "KOR",
77
+ "district": "Seoul",
78
+ "population": 9981619
79
+ },
80
+ {
81
+ "name": "São Paulo",
82
+ "country_code": "BRA",
83
+ "district": "São Paulo",
84
+ "population": 9968485
85
+ },
86
+ {
87
+ "name": "Shanghai",
88
+ "country_code": "CHN",
89
+ "district": "Shanghai",
90
+ "population": 9696300
91
+ },
92
+ {
93
+ "name": "Jakarta",
94
+ "country_code": "IDN",
95
+ "district": "Jakarta Raya",
96
+ "population": 9604900
97
+ },
98
+ {
99
+ "name": "Karachi",
100
+ "country_code": "PAK",
101
+ "district": "Sindh",
102
+ "population": 9269265
103
+ },
104
+ {
105
+ "name": "Istanbul",
106
+ "country_code": "TUR",
107
+ "district": "Istanbul",
108
+ "population": 8787958
109
+ },
110
+ {
111
+ "name": "Ciudad de México",
112
+ "country_code": "MEX",
113
+ "district": "Distrito Federal",
114
+ "population": 8591309
115
+ },
116
+ {
117
+ "name": "Moscow",
118
+ "country_code": "RUS",
119
+ "district": "Moscow (City)",
120
+ "population": 8389200
121
+ },
122
+ {
123
+ "name": "New York",
124
+ "country_code": "USA",
125
+ "district": "New York",
126
+ "population": 8008278
127
+ }
128
+ ]
129
+ ===========================================
130
+
131
+ === Query Execution ===
132
+ Timestamp: 2025-12-29T05:28:29.510Z
133
+ Query:
134
+ SELECT
135
+ c.name as country_name,
136
+ c.code as country_code,
137
+ COUNT(ci.id) as city_count,
138
+ SUM(ci.population) as total_city_population
139
+ FROM country c
140
+ LEFT JOIN city ci ON ci.country_code = c.code
141
+ GROUP BY c.code, c.name
142
+ ORDER BY city_count DESC
143
+ LIMIT 10
144
+
145
+ Result: [
146
+ {
147
+ "country_name": "China",
148
+ "country_code": "CHN",
149
+ "city_count": "363",
150
+ "total_city_population": "175953614"
151
+ },
152
+ {
153
+ "country_name": "India",
154
+ "country_code": "IND",
155
+ "city_count": "341",
156
+ "total_city_population": "123298526"
157
+ },
158
+ {
159
+ "country_name": "United States",
160
+ "country_code": "USA",
161
+ "city_count": "274",
162
+ "total_city_population": "78625774"
163
+ },
164
+ {
165
+ "country_name": "Brazil",
166
+ "country_code": "BRA",
167
+ "city_count": "250",
168
+ "total_city_population": "85876862"
169
+ },
170
+ {
171
+ "country_name": "Japan",
172
+ "country_code": "JPN",
173
+ "city_count": "248",
174
+ "total_city_population": "77965107"
175
+ },
176
+ {
177
+ "country_name": "Russian Federation",
178
+ "country_code": "RUS",
179
+ "city_count": "189",
180
+ "total_city_population": "69150700"
181
+ },
182
+ {
183
+ "country_name": "Mexico",
184
+ "country_code": "MEX",
185
+ "city_count": "173",
186
+ "total_city_population": "59752521"
187
+ },
188
+ {
189
+ "country_name": "Philippines",
190
+ "country_code": "PHL",
191
+ "city_count": "136",
192
+ "total_city_population": "30934791"
193
+ },
194
+ {
195
+ "country_name": "Germany",
196
+ "country_code": "DEU",
197
+ "city_count": "93",
198
+ "total_city_population": "26245483"
199
+ },
200
+ {
201
+ "country_name": "Indonesia",
202
+ "country_code": "IDN",
203
+ "city_count": "85",
204
+ "total_city_population": "37485695"
205
+ }
206
+ ]
207
+ ===========================================
208
+
209
+ === Query Execution ===
210
+ Timestamp: 2025-12-29T05:30:23.136Z
211
+ Query: SELECT COUNT(*) as total_cities FROM city
212
+ Result: [
213
+ {
214
+ "total_cities": "4079"
215
+ }
216
+ ]
217
+ ===========================================
218
+
219
+ === Query Execution ===
220
+ Timestamp: 2025-12-29T05:31:18.755Z
221
+ Query: SELECT COUNT(*) as total_cities FROM city
222
+ Result: [
223
+ {
224
+ "total_cities": "4079"
225
+ }
226
+ ]
227
+ ===========================================
228
+
229
+ === Query Execution ===
230
+ Timestamp: 2025-12-29T05:31:18.797Z
231
+ Query:
232
+ SELECT
233
+ c.continent,
234
+ COUNT(ci.id) as city_count
235
+ FROM country c
236
+ LEFT JOIN city ci ON ci.country_code = c.code
237
+ GROUP BY c.continent
238
+ ORDER BY city_count DESC
239
+
240
+ Result: [
241
+ {
242
+ "continent": "Asia",
243
+ "city_count": "1766"
244
+ },
245
+ {
246
+ "continent": "Europe",
247
+ "city_count": "841"
248
+ },
249
+ {
250
+ "continent": "North America",
251
+ "city_count": "581"
252
+ },
253
+ {
254
+ "continent": "South America",
255
+ "city_count": "470"
256
+ },
257
+ {
258
+ "continent": "Africa",
259
+ "city_count": "366"
260
+ },
261
+ {
262
+ "continent": "Oceania",
263
+ "city_count": "55"
264
+ },
265
+ {
266
+ "continent": "Antarctica",
267
+ "city_count": "0"
268
+ }
269
+ ]
270
+ ===========================================
271
+
272
+ === Query Execution ===
273
+ Timestamp: 2025-12-29T05:31:18.804Z
274
+ Query:
275
+ SELECT
276
+ name,
277
+ country_code,
278
+ district,
279
+ population
280
+ FROM city
281
+ ORDER BY population DESC
282
+ LIMIT 10
283
+
284
+ Result: [
285
+ {
286
+ "name": "Mumbai (Bombay)",
287
+ "country_code": "IND",
288
+ "district": "Maharashtra",
289
+ "population": 10500000
290
+ },
291
+ {
292
+ "name": "Seoul",
293
+ "country_code": "KOR",
294
+ "district": "Seoul",
295
+ "population": 9981619
296
+ },
297
+ {
298
+ "name": "São Paulo",
299
+ "country_code": "BRA",
300
+ "district": "São Paulo",
301
+ "population": 9968485
302
+ },
303
+ {
304
+ "name": "Shanghai",
305
+ "country_code": "CHN",
306
+ "district": "Shanghai",
307
+ "population": 9696300
308
+ },
309
+ {
310
+ "name": "Jakarta",
311
+ "country_code": "IDN",
312
+ "district": "Jakarta Raya",
313
+ "population": 9604900
314
+ },
315
+ {
316
+ "name": "Karachi",
317
+ "country_code": "PAK",
318
+ "district": "Sindh",
319
+ "population": 9269265
320
+ },
321
+ {
322
+ "name": "Istanbul",
323
+ "country_code": "TUR",
324
+ "district": "Istanbul",
325
+ "population": 8787958
326
+ },
327
+ {
328
+ "name": "Ciudad de México",
329
+ "country_code": "MEX",
330
+ "district": "Distrito Federal",
331
+ "population": 8591309
332
+ },
333
+ {
334
+ "name": "Moscow",
335
+ "country_code": "RUS",
336
+ "district": "Moscow (City)",
337
+ "population": 8389200
338
+ },
339
+ {
340
+ "name": "New York",
341
+ "country_code": "USA",
342
+ "district": "New York",
343
+ "population": 8008278
344
+ }
345
+ ]
346
+ ===========================================
347
+
348
+ === Query Execution ===
349
+ Timestamp: 2025-12-29T05:31:18.807Z
350
+ Query:
351
+ SELECT
352
+ c.name as country_name,
353
+ c.code as country_code,
354
+ COUNT(ci.id) as city_count,
355
+ SUM(ci.population) as total_city_population
356
+ FROM country c
357
+ LEFT JOIN city ci ON ci.country_code = c.code
358
+ GROUP BY c.code, c.name
359
+ ORDER BY city_count DESC
360
+ LIMIT 10
361
+
362
+ Result: [
363
+ {
364
+ "country_name": "China",
365
+ "country_code": "CHN",
366
+ "city_count": "363",
367
+ "total_city_population": "175953614"
368
+ },
369
+ {
370
+ "country_name": "India",
371
+ "country_code": "IND",
372
+ "city_count": "341",
373
+ "total_city_population": "123298526"
374
+ },
375
+ {
376
+ "country_name": "United States",
377
+ "country_code": "USA",
378
+ "city_count": "274",
379
+ "total_city_population": "78625774"
380
+ },
381
+ {
382
+ "country_name": "Brazil",
383
+ "country_code": "BRA",
384
+ "city_count": "250",
385
+ "total_city_population": "85876862"
386
+ },
387
+ {
388
+ "country_name": "Japan",
389
+ "country_code": "JPN",
390
+ "city_count": "248",
391
+ "total_city_population": "77965107"
392
+ },
393
+ {
394
+ "country_name": "Russian Federation",
395
+ "country_code": "RUS",
396
+ "city_count": "189",
397
+ "total_city_population": "69150700"
398
+ },
399
+ {
400
+ "country_name": "Mexico",
401
+ "country_code": "MEX",
402
+ "city_count": "173",
403
+ "total_city_population": "59752521"
404
+ },
405
+ {
406
+ "country_name": "Philippines",
407
+ "country_code": "PHL",
408
+ "city_count": "136",
409
+ "total_city_population": "30934791"
410
+ },
411
+ {
412
+ "country_name": "Germany",
413
+ "country_code": "DEU",
414
+ "city_count": "93",
415
+ "total_city_population": "26245483"
416
+ },
417
+ {
418
+ "country_name": "Indonesia",
419
+ "country_code": "IDN",
420
+ "city_count": "85",
421
+ "total_city_population": "37485695"
422
+ }
423
+ ]
424
+ ===========================================
425
+
426
+ === Query Execution ===
427
+ Timestamp: 2025-12-29T05:31:18.810Z
428
+ Query:
429
+ SELECT
430
+ c.continent,
431
+ COUNT(ci.id) as city_count,
432
+ AVG(ci.population) as avg_city_population,
433
+ MIN(ci.population) as min_city_population,
434
+ MAX(ci.population) as max_city_population
435
+ FROM country c
436
+ LEFT JOIN city ci ON ci.country_code = c.code
437
+ WHERE ci.population IS NOT NULL
438
+ GROUP BY c.continent
439
+ ORDER BY avg_city_population DESC
440
+
441
+ Result: [
442
+ {
443
+ "continent": "Asia",
444
+ "city_count": "1766",
445
+ "avg_city_population": "395019.31087202718",
446
+ "min_city_population": 21484,
447
+ "max_city_population": 10500000
448
+ },
449
+ {
450
+ "continent": "Africa",
451
+ "city_count": "366",
452
+ "avg_city_population": "371143.658469945355",
453
+ "min_city_population": 1500,
454
+ "max_city_population": 6789479
455
+ },
456
+ {
457
+ "continent": "South America",
458
+ "city_count": "470",
459
+ "avg_city_population": "366037.997872340426",
460
+ "min_city_population": 1636,
461
+ "max_city_population": 9968485
462
+ },
463
+ {
464
+ "continent": "North America",
465
+ "city_count": "581",
466
+ "avg_city_population": "289587.57487091222",
467
+ "min_city_population": 595,
468
+ "max_city_population": 8591309
469
+ },
470
+ {
471
+ "continent": "Europe",
472
+ "city_count": "841",
473
+ "avg_city_population": "287684.676575505351",
474
+ "min_city_population": 455,
475
+ "max_city_population": 8389200
476
+ },
477
+ {
478
+ "continent": "Oceania",
479
+ "city_count": "55",
480
+ "avg_city_population": "252475.436363636364",
481
+ "min_city_population": 42,
482
+ "max_city_population": 3276207
483
+ }
484
+ ]
485
+ ===========================================
486
+
487
+ === Query Execution ===
488
+ Timestamp: 2025-12-29T05:31:18.814Z
489
+ Query:
490
+ SELECT AVG(population) as avg_population FROM city
491
+
492
+ Result: [
493
+ {
494
+ "avg_population": "350468.223584211817"
495
+ }
496
+ ]
497
+ ===========================================
498
+
499
+ === Query Execution ===
500
+ Timestamp: 2025-12-29T05:31:18.838Z
501
+ Query:
502
+ SELECT
503
+ name,
504
+ country_code,
505
+ population,
506
+ ROUND(population - 350468.22358421184) as above_avg_by
507
+ FROM city
508
+ WHERE population > 350468.22358421184
509
+ ORDER BY population DESC
510
+ LIMIT 20
511
+
512
+ Result: [
513
+ {
514
+ "name": "Mumbai (Bombay)",
515
+ "country_code": "IND",
516
+ "population": 10500000,
517
+ "above_avg_by": "10149532"
518
+ },
519
+ {
520
+ "name": "Seoul",
521
+ "country_code": "KOR",
522
+ "population": 9981619,
523
+ "above_avg_by": "9631151"
524
+ },
525
+ {
526
+ "name": "São Paulo",
527
+ "country_code": "BRA",
528
+ "population": 9968485,
529
+ "above_avg_by": "9618017"
530
+ },
531
+ {
532
+ "name": "Shanghai",
533
+ "country_code": "CHN",
534
+ "population": 9696300,
535
+ "above_avg_by": "9345832"
536
+ },
537
+ {
538
+ "name": "Jakarta",
539
+ "country_code": "IDN",
540
+ "population": 9604900,
541
+ "above_avg_by": "9254432"
542
+ },
543
+ {
544
+ "name": "Karachi",
545
+ "country_code": "PAK",
546
+ "population": 9269265,
547
+ "above_avg_by": "8918797"
548
+ },
549
+ {
550
+ "name": "Istanbul",
551
+ "country_code": "TUR",
552
+ "population": 8787958,
553
+ "above_avg_by": "8437490"
554
+ },
555
+ {
556
+ "name": "Ciudad de México",
557
+ "country_code": "MEX",
558
+ "population": 8591309,
559
+ "above_avg_by": "8240841"
560
+ },
561
+ {
562
+ "name": "Moscow",
563
+ "country_code": "RUS",
564
+ "population": 8389200,
565
+ "above_avg_by": "8038732"
566
+ },
567
+ {
568
+ "name": "New York",
569
+ "country_code": "USA",
570
+ "population": 8008278,
571
+ "above_avg_by": "7657810"
572
+ },
573
+ {
574
+ "name": "Tokyo",
575
+ "country_code": "JPN",
576
+ "population": 7980230,
577
+ "above_avg_by": "7629762"
578
+ },
579
+ {
580
+ "name": "Peking",
581
+ "country_code": "CHN",
582
+ "population": 7472000,
583
+ "above_avg_by": "7121532"
584
+ },
585
+ {
586
+ "name": "London",
587
+ "country_code": "GBR",
588
+ "population": 7285000,
589
+ "above_avg_by": "6934532"
590
+ },
591
+ {
592
+ "name": "Delhi",
593
+ "country_code": "IND",
594
+ "population": 7206704,
595
+ "above_avg_by": "6856236"
596
+ },
597
+ {
598
+ "name": "Cairo",
599
+ "country_code": "EGY",
600
+ "population": 6789479,
601
+ "above_avg_by": "6439011"
602
+ },
603
+ {
604
+ "name": "Teheran",
605
+ "country_code": "IRN",
606
+ "population": 6758845,
607
+ "above_avg_by": "6408377"
608
+ },
609
+ {
610
+ "name": "Lima",
611
+ "country_code": "PER",
612
+ "population": 6464693,
613
+ "above_avg_by": "6114225"
614
+ },
615
+ {
616
+ "name": "Chongqing",
617
+ "country_code": "CHN",
618
+ "population": 6351600,
619
+ "above_avg_by": "6001132"
620
+ },
621
+ {
622
+ "name": "Bangkok",
623
+ "country_code": "THA",
624
+ "population": 6320174,
625
+ "above_avg_by": "5969706"
626
+ },
627
+ {
628
+ "name": "Santafé de Bogotá",
629
+ "country_code": "COL",
630
+ "population": 6260862,
631
+ "above_avg_by": "5910394"
632
+ }
633
+ ]
634
+ ===========================================
635
+
636
+ === Query Execution ===
637
+ Timestamp: 2025-12-29T05:31:18.842Z
638
+ Query:
639
+ SELECT
640
+ COUNT(DISTINCT ci.id) as total_cities,
641
+ COUNT(DISTINCT c.code) as total_countries,
642
+ COUNT(DISTINCT c.continent) as total_continents,
643
+ SUM(ci.population) as total_city_population,
644
+ AVG(ci.population) as avg_city_population
645
+ FROM country c
646
+ LEFT JOIN city ci ON ci.country_code = c.code
647
+
648
+ Result: [
649
+ {
650
+ "total_cities": "4079",
651
+ "total_countries": "239",
652
+ "total_continents": "7",
653
+ "total_city_population": "1429559884",
654
+ "avg_city_population": "350468.223584211817"
655
+ }
656
+ ]
657
+ ===========================================
@@ -0,0 +1,69 @@
1
+ generator client {
2
+ provider = "prisma-client-js"
3
+ output = "../node_modules/.prisma/client"
4
+ }
5
+
6
+ datasource db {
7
+ provider = "postgresql"
8
+ }
9
+
10
+ /// This model or at least one of its fields has comments in the database, and requires an additional setup for migrations: Read more: https://pris.ly/d/database-comments
11
+ model city {
12
+ id Int @id @default(autoincrement())
13
+ name String
14
+ country_code String @db.Char(3)
15
+ district String
16
+ population Int
17
+ local_name String?
18
+ country_city_country_codeTocountry country @relation("city_country_codeTocountry", fields: [country_code], references: [code], onDelete: NoAction, onUpdate: NoAction, map: "country_fk")
19
+ country_country_capitalTocity country[] @relation("country_capitalTocity")
20
+ }
21
+
22
+ /// This model or at least one of its fields has comments in the database, and requires an additional setup for migrations: Read more: https://pris.ly/d/database-comments
23
+ model country {
24
+ code String @id @db.Char(3)
25
+ name String
26
+ continent continent_enum
27
+ region String
28
+ surface_area Float @db.Real
29
+ indep_year Int? @db.SmallInt
30
+ population Int
31
+ life_expectancy Float? @db.Real
32
+ gnp Decimal? @db.Decimal(10, 2)
33
+ gnp_old Decimal? @db.Decimal(10, 2)
34
+ local_name String
35
+ government_form String
36
+ head_of_state String?
37
+ capital Int?
38
+ code2 String @db.Char(2)
39
+ city_city_country_codeTocountry city[] @relation("city_country_codeTocountry")
40
+ city_country_capitalTocity city? @relation("country_capitalTocity", fields: [capital], references: [id], onDelete: NoAction, onUpdate: NoAction)
41
+ country_language country_language[]
42
+ }
43
+
44
+ /// This model or at least one of its fields has comments in the database, and requires an additional setup for migrations: Read more: https://pris.ly/d/database-comments
45
+ model country_flag {
46
+ code2 String @id @db.Char(2)
47
+ emoji String
48
+ unicode String?
49
+ }
50
+
51
+ model country_language {
52
+ country_code String @db.Char(3)
53
+ language String
54
+ is_official Boolean
55
+ percentage Float @db.Real
56
+ country country @relation(fields: [country_code], references: [code], onDelete: NoAction, onUpdate: NoAction)
57
+
58
+ @@id([country_code, language])
59
+ }
60
+
61
+ enum continent_enum {
62
+ Asia
63
+ Europe
64
+ North_America @map("North America")
65
+ Africa
66
+ Oceania
67
+ Antarctica
68
+ South_America @map("South America")
69
+ }
package/README.md CHANGED
@@ -28,36 +28,37 @@ db-ai init
28
28
  ```
29
29
 
30
30
  This creates a `.db-ai` folder with:
31
- - `dbConfig.json` - Database configuration file
31
+ - `prisma.config.ts` - Database configuration file (Prisma 7 format)
32
32
  - `instructions.md` - Reference guide for AI
33
33
  - `Script1.ts` - Template script for running queries
34
34
 
35
35
  ### 2. Configure Database
36
36
 
37
- Edit `.db-ai/dbConfig.json` with your database credentials:
38
-
39
- ```json
40
- {
41
- "provider": "postgresql",
42
- "host": "localhost",
43
- "port": 5432,
44
- "user": "your_username",
45
- "password": "your_password",
46
- "database": "your_database",
47
- "schema": "public",
48
- "OPERATIONS_ALLOWED": ["SELECT"],
49
- "outputFileName": "output.txt"
50
- }
37
+ Edit `.db-ai/prisma.config.ts` with your database credentials:
38
+
39
+ ```typescript
40
+ import { defineConfig } from 'prisma/config';
41
+
42
+ // Prisma configuration (for Prisma 7)
43
+ export default defineConfig({
44
+ datasource: {
45
+ url: "postgresql://your_username:your_password@localhost:5432/your_database?schema=public",
46
+ },
47
+ });
48
+
49
+ // db-ai specific configuration
50
+ export const dbAiConfig = {
51
+ OPERATIONS_ALLOWED: ["SELECT"], // Allowed SQL operations: SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, ALTER
52
+ outputFileName: "output.txt", // Optional: file to log query results
53
+ };
51
54
  ```
52
55
 
53
56
  **Configuration Fields:**
54
- - `provider`: Database type (postgresql, mysql, sqlite, sqlserver, etc.)
55
- - `host`: Database host
56
- - `port`: Database port
57
- - `user`: Database username
58
- - `password`: Database password
59
- - `database`: Database name
60
- - `schema`: (Optional) Database schema name. Useful for PostgreSQL (default: `public`) and SQL Server. Can be omitted for MySQL/SQLite.
57
+
58
+ **Prisma Config (default export):**
59
+ - `datasource.url`: Database connection URL (required by Prisma 7)
60
+
61
+ **db-ai Config (dbAiConfig export):**
61
62
  - `OPERATIONS_ALLOWED`: Array of allowed SQL operations (default: `["SELECT"]`)
62
63
  - `outputFileName`: Optional file name for logging query results with timestamps
63
64
 
@@ -135,17 +136,15 @@ Executes a SQL query, returns the result, and prints it to the console.
135
136
 
136
137
  ## Security
137
138
 
138
- The package validates SQL operations against the `OPERATIONS_ALLOWED` array in the configuration. By default, only `SELECT` operations are allowed. To allow other operations, update `OPERATIONS_ALLOWED` in `dbConfig.json`:
139
+ The package validates SQL operations against the `OPERATIONS_ALLOWED` array in the configuration. By default, only `SELECT` operations are allowed. To allow other operations, update `OPERATIONS_ALLOWED` in `prisma.config.ts`:
139
140
 
140
- ```json
141
- {
142
- "OPERATIONS_ALLOWED": ["SELECT", "INSERT", "UPDATE"]
143
- }
141
+ ```typescript
142
+ OPERATIONS_ALLOWED: ["SELECT", "INSERT", "UPDATE"]
144
143
  ```
145
144
 
146
145
  ## Output Logging
147
146
 
148
- If `outputFileName` is specified in `dbConfig.json`, all query results are automatically appended to that file with timestamps. The file is created in the `.db-ai/` folder.
147
+ If `outputFileName` is specified in `prisma.config.ts`, all query results are automatically appended to that file with timestamps. The file is created in the `.db-ai/` folder.
149
148
 
150
149
  ## Schema File
151
150
 
@@ -1 +1 @@
1
- {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"AAOA,wBAAsB,WAAW,kBAgHhC"}
1
+ {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"AAOA,wBAAsB,WAAW,kBAmEhC"}
@@ -53,71 +53,28 @@ async function initCommand() {
53
53
  else {
54
54
  console.log(chalk_1.default.yellow(`⚠ Directory already exists: ${configDir}`));
55
55
  }
56
- // Create dbConfig.json
57
- const configPath = path.join(configDir, 'dbConfig.json');
56
+ // Create prisma.config.ts
57
+ const configPath = path.join(configDir, 'prisma.config.ts');
58
58
  if (!fs.existsSync(configPath)) {
59
- const configTemplate = {
60
- provider: "postgresql",
61
- host: "localhost",
62
- port: 5432,
63
- user: "your_username",
64
- password: "your_password",
65
- database: "your_database",
66
- schema: "public",
67
- OPERATIONS_ALLOWED: ["SELECT"],
68
- outputFileName: "output.txt"
69
- };
70
- const configContent = JSON.stringify(configTemplate, null, 2);
71
- // Since JSON doesn't support comments, we'll write a note file instead
72
- fs.writeFileSync(configPath, configContent, 'utf-8');
73
- // Create a note file about provider
74
- const notePath = path.join(configDir, 'CONFIG_NOTES.md');
75
- const noteContent = `# Configuration Notes
76
-
77
- ## Database Provider
78
-
79
- The \`provider\` field in dbConfig.json specifies your database type:
80
- - \`postgresql\` - PostgreSQL
81
- - \`mysql\` - MySQL
82
- - \`sqlite\` - SQLite
83
- - \`sqlserver\` - SQL Server
84
-
85
- **Important**: Make sure to install the required database driver package for your database provider:
86
- - PostgreSQL: \`npm install pg\`
87
- - MySQL: \`npm install mysql2\`
88
- - SQLite: \`npm install better-sqlite3\`
89
- - SQL Server: \`npm install @prisma/adapter-sqlserver\`
90
-
91
- Note: \`@prisma/client\` is already included and works with all database providers.
92
-
93
- ## Schema
94
-
95
- The \`schema\` field (optional) specifies the database schema to use. This is particularly useful for PostgreSQL and SQL Server:
96
- - **PostgreSQL**: Default is \`public\`. You can specify other schemas like \`myschema\`.
97
- - **SQL Server**: Specify the schema name (e.g., \`dbo\`, \`sales\`).
98
- - **MySQL/SQLite**: Schema is typically not used, but can be left empty or omitted.
59
+ const configContent = `// Prisma 7 configuration file for db-ai
60
+ // Update this file with your database credentials
99
61
 
100
- If not specified, the default schema for your database provider will be used.
62
+ import { defineConfig } from 'prisma/config';
101
63
 
102
- ## OPERATIONS_ALLOWED
103
-
104
- This array specifies which SQL operations are allowed:
105
- - \`SELECT\` - Read queries
106
- - \`INSERT\` - Insert operations
107
- - \`UPDATE\` - Update operations
108
- - \`DELETE\` - Delete operations
109
- - \`CREATE\` - Create table/index operations
110
- - \`DROP\` - Drop operations
111
- - \`ALTER\` - Alter table operations
112
-
113
- Default is \`["SELECT"]\` for safety.
114
-
115
- ## outputFileName
64
+ // Prisma configuration (for Prisma 7)
65
+ export default defineConfig({
66
+ datasource: {
67
+ url: "postgresql://your_username:your_password@localhost:5432/your_database?schema=public",
68
+ },
69
+ });
116
70
 
117
- If specified, all query results will be appended to this file with timestamps.
118
- Leave empty or remove this field to disable file logging.
71
+ // db-ai specific configuration
72
+ export const dbAiConfig = {
73
+ OPERATIONS_ALLOWED: ["SELECT"], // Allowed SQL operations: SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, ALTER
74
+ outputFileName: "output.txt", // Optional: file to log query results
75
+ };
119
76
  `;
120
- fs.writeFileSync(notePath, noteContent, 'utf-8');
77
+ fs.writeFileSync(configPath, configContent, 'utf-8');
121
78
  console.log(chalk_1.default.green(`✓ Created configuration file: ${configPath}`));
122
79
  console.log(chalk_1.default.yellow(`⚠ Please update ${configPath} with your database credentials`));
123
80
  }
@@ -140,7 +97,7 @@ Leave empty or remove this field to disable file logging.
140
97
  }
141
98
  console.log(chalk_1.default.green('\n✓ Initialization complete!'));
142
99
  console.log(chalk_1.default.cyan('\nNext steps:'));
143
- console.log(chalk_1.default.cyan('1. Update .db-ai/dbConfig.json with your database credentials'));
100
+ console.log(chalk_1.default.cyan('1. Update .db-ai/prisma.config.ts with your database credentials'));
144
101
  console.log(chalk_1.default.cyan('2. Run "db-ai start" to pull your database schema'));
145
102
  }
146
103
  catch (error) {
@@ -1 +1 @@
1
- {"version":3,"file":"init.js","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,kCAgHC;AAvHD,kDAA0B;AAC1B,uCAAyB;AACzB,2CAA6B;AAC7B,2CAA8C;AAE9C,MAAM,aAAa,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC;AAEpD,KAAK,UAAU,WAAW;IAC/B,MAAM,SAAS,GAAG,IAAA,qBAAY,GAAE,CAAC;IAEjC,IAAI,CAAC;QACH,0BAA0B;QAC1B,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;YAC9B,EAAE,CAAC,SAAS,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;YAC7C,OAAO,CAAC,GAAG,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,CAAC,CAAC;QACzD,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC;QACzC,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,kEAAkE,CAAC,CAAC,CAAC;QAC5F,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,mDAAmD,CAAC,CAAC,CAAC;IAE/E,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QACpB,OAAO,CAAC,KAAK,CAAC,eAAK,CAAC,GAAG,CAAC,8BAA8B,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;QACxE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"start.d.ts","sourceRoot":"","sources":["../../src/commands/start.ts"],"names":[],"mappings":"AAMA,wBAAsB,YAAY,kBAgFjC"}
1
+ {"version":3,"file":"start.d.ts","sourceRoot":"","sources":["../../src/commands/start.ts"],"names":[],"mappings":"AAMA,wBAAsB,YAAY,kBAqEjC"}
@@ -48,9 +48,6 @@ async function startCommand() {
48
48
  // Load configuration
49
49
  const config = (0, config_1.loadConfig)();
50
50
  const configDir = (0, config_1.getConfigDir)();
51
- // Set DATABASE_URL environment variable
52
- const connectionString = (0, config_1.getConnectionString)(config);
53
- process.env.DATABASE_URL = connectionString;
54
51
  // Create Prisma schema file
55
52
  const schemaPath = path.join(configDir, 'schema.prisma');
56
53
  let schemaContent = `// This file was auto-generated by db-ai
@@ -62,8 +59,7 @@ generator client {
62
59
  }
63
60
 
64
61
  datasource db {
65
- provider = "${config.provider}"
66
- url = env("DATABASE_URL")`;
62
+ provider = "${config.provider}"`;
67
63
  // Add schema configuration for PostgreSQL and SQL Server if provided
68
64
  if (config.schema && (config.provider.toLowerCase() === 'postgresql' || config.provider.toLowerCase() === 'postgres' || config.provider.toLowerCase() === 'sqlserver' || config.provider.toLowerCase() === 'mssql')) {
69
65
  schemaContent += `\n schemas = ["${config.schema}"]`;
@@ -72,33 +68,27 @@ datasource db {
72
68
  fs.writeFileSync(schemaPath, schemaContent, 'utf-8');
73
69
  console.log(chalk_1.default.green(`✓ Created schema.prisma at ${schemaPath}`));
74
70
  // Run prisma db pull to introspect the database
71
+ // Prisma 7 reads datasource.url from prisma.config.ts automatically
75
72
  console.log(chalk_1.default.blue('Pulling database schema...'));
76
73
  try {
77
74
  (0, child_process_1.execSync)('npx prisma db pull', {
78
75
  cwd: configDir,
79
76
  stdio: 'inherit',
80
- env: {
81
- ...process.env,
82
- DATABASE_URL: connectionString,
83
- },
84
77
  });
85
78
  console.log(chalk_1.default.green('✓ Database schema pulled successfully'));
86
79
  }
87
80
  catch (error) {
88
81
  console.error(chalk_1.default.red('Error pulling database schema:'), error.message);
89
- console.log(chalk_1.default.yellow('Make sure you have the correct database credentials and the database is accessible.'));
82
+ console.log(chalk_1.default.yellow('Make sure you have the correct database credentials in prisma.config.ts and the database is accessible.'));
90
83
  throw error;
91
84
  }
92
85
  // Generate Prisma Client
86
+ // Prisma 7 reads datasource.url from prisma.config.ts automatically
93
87
  console.log(chalk_1.default.blue('Generating Prisma Client...'));
94
88
  try {
95
89
  (0, child_process_1.execSync)('npx prisma generate', {
96
90
  cwd: configDir,
97
91
  stdio: 'inherit',
98
- env: {
99
- ...process.env,
100
- DATABASE_URL: connectionString,
101
- },
102
92
  });
103
93
  console.log(chalk_1.default.green('✓ Prisma Client generated successfully'));
104
94
  }
@@ -1 +1 @@
1
- {"version":3,"file":"start.js","sourceRoot":"","sources":["../../src/commands/start.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,oCAgFC;AAtFD,kDAA0B;AAC1B,iDAAyC;AACzC,uCAAyB;AACzB,2CAA6B;AAC7B,2CAA+E;AAExE,KAAK,UAAU,YAAY;IAChC,IAAI,CAAC;QACH,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,I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,CAAC;QAED,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,KAAK,CAAC,sCAAsC,CAAC,CAAC,CAAC;QACjE,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,kBAAkB,UAAU,EAAE,CAAC,CAAC,CAAC;QACxD,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,iDAAiD,CAAC,CAAC,CAAC;IAE7E,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QACpB,OAAO,CAAC,KAAK,CAAC,eAAK,CAAC,GAAG,CAAC,sCAAsC,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;QAChF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC"}
@@ -13,7 +13,6 @@ export interface DatabaseConfig {
13
13
  export declare function getConfigPath(): string;
14
14
  export declare function loadConfig(): DatabaseConfig;
15
15
  export declare function validateConfig(config: DatabaseConfig): void;
16
- export declare function getConnectionString(config: DatabaseConfig): string;
17
16
  export declare function getPrismaClient(): PrismaClient;
18
17
  export declare function getConfigDir(): string;
19
18
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/core/config.ts"],"names":[],"mappings":"AAIA,KAAK,YAAY,GAAG,GAAG,CAAC;AAExB,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,kBAAkB,EAAE,MAAM,EAAE,CAAC;IAC7B,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAKD,wBAAgB,aAAa,IAAI,MAAM,CAEtC;AAED,wBAAgB,UAAU,IAAI,cAAc,CAc3C;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,cAAc,GAAG,IAAI,CAoB3D;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,cAAc,GAAG,MAAM,CAiClE;AAID,wBAAgB,eAAe,IAAI,YAAY,CAgC9C;AAED,wBAAgB,YAAY,IAAI,MAAM,CAErC"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/core/config.ts"],"names":[],"mappings":"AAIA,KAAK,YAAY,GAAG,GAAG,CAAC;AAExB,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,kBAAkB,EAAE,MAAM,EAAE,CAAC;IAC7B,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAKD,wBAAgB,aAAa,IAAI,MAAM,CAEtC;AAED,wBAAgB,UAAU,IAAI,cAAc,CAkC3C;AAWD,wBAAgB,cAAc,CAAC,MAAM,EAAE,cAAc,GAAG,IAAI,CAS3D;AAKD,wBAAgB,eAAe,IAAI,YAAY,CA0B9C;AAED,wBAAgB,YAAY,IAAI,MAAM,CAErC"}
@@ -36,13 +36,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.getConfigPath = getConfigPath;
37
37
  exports.loadConfig = loadConfig;
38
38
  exports.validateConfig = validateConfig;
39
- exports.getConnectionString = getConnectionString;
40
39
  exports.getPrismaClient = getPrismaClient;
41
40
  exports.getConfigDir = getConfigDir;
42
41
  const fs = __importStar(require("fs"));
43
42
  const path = __importStar(require("path"));
44
43
  const CONFIG_DIR = '.db-ai';
45
- const CONFIG_FILE = 'dbConfig.json';
44
+ const CONFIG_FILE = 'prisma.config.ts';
46
45
  function getConfigPath() {
47
46
  return path.join(process.cwd(), CONFIG_DIR, CONFIG_FILE);
48
47
  }
@@ -51,72 +50,56 @@ function loadConfig() {
51
50
  if (!fs.existsSync(configPath)) {
52
51
  throw new Error(`Configuration file not found at ${configPath}. Please run 'db-ai init' first.`);
53
52
  }
54
- const configContent = fs.readFileSync(configPath, 'utf-8');
55
- const config = JSON.parse(configContent);
53
+ // Dynamically require the prisma.config.ts file
54
+ // Delete from cache to ensure fresh load
55
+ delete require.cache[require.resolve(configPath)];
56
+ const configModule = require(configPath);
57
+ // Get Prisma config (default export) and db-ai config (named export)
58
+ const prismaConfig = configModule.default || configModule;
59
+ const dbAiConfig = configModule.dbAiConfig || {};
60
+ // Extract database config from prisma.config.ts
61
+ // datasource.url is handled by Prisma 7 automatically
62
+ const config = {
63
+ provider: extractProviderFromUrl(prismaConfig.datasource?.url),
64
+ host: '', // Not needed - Prisma reads from datasource.url
65
+ port: 0, // Not needed - Prisma reads from datasource.url
66
+ user: '', // Not needed - Prisma reads from datasource.url
67
+ password: '', // Not needed - Prisma reads from datasource.url
68
+ database: '', // Not needed - Prisma reads from datasource.url
69
+ schema: undefined, // Not needed - Prisma reads from datasource.url
70
+ OPERATIONS_ALLOWED: dbAiConfig.OPERATIONS_ALLOWED || ['SELECT'],
71
+ outputFileName: dbAiConfig.outputFileName,
72
+ };
56
73
  validateConfig(config);
57
74
  return config;
58
75
  }
76
+ function extractProviderFromUrl(url) {
77
+ if (!url)
78
+ return 'postgresql';
79
+ if (url.startsWith('postgresql://') || url.startsWith('postgres://'))
80
+ return 'postgresql';
81
+ if (url.startsWith('mysql://'))
82
+ return 'mysql';
83
+ if (url.startsWith('sqlite://') || url.startsWith('file:'))
84
+ return 'sqlite';
85
+ if (url.startsWith('sqlserver://') || url.startsWith('mssql://'))
86
+ return 'sqlserver';
87
+ return 'postgresql';
88
+ }
59
89
  function validateConfig(config) {
60
- const requiredFields = [
61
- 'provider',
62
- 'host',
63
- 'port',
64
- 'user',
65
- 'password',
66
- 'database',
67
- 'OPERATIONS_ALLOWED',
68
- ];
69
- for (const field of requiredFields) {
70
- if (config[field] === undefined || config[field] === null || config[field] === '') {
71
- throw new Error(`Missing required field in config: ${field}`);
72
- }
90
+ // Only validate fields that are actually needed
91
+ if (!config.provider) {
92
+ throw new Error('Missing required field in config: provider');
73
93
  }
74
94
  if (!Array.isArray(config.OPERATIONS_ALLOWED)) {
75
95
  throw new Error('OPERATIONS_ALLOWED must be an array');
76
96
  }
77
97
  }
78
- function getConnectionString(config) {
79
- const { provider, host, port, user, password, database, schema } = config;
80
- switch (provider.toLowerCase()) {
81
- case 'postgresql':
82
- case 'postgres':
83
- let postgresUrl = `postgresql://${user}:${password}@${host}:${port}/${database}`;
84
- if (schema) {
85
- postgresUrl += `?schema=${encodeURIComponent(schema)}`;
86
- }
87
- return postgresUrl;
88
- case 'mysql':
89
- let mysqlUrl = `mysql://${user}:${password}@${host}:${port}/${database}`;
90
- if (schema) {
91
- mysqlUrl += `?schema=${encodeURIComponent(schema)}`;
92
- }
93
- return mysqlUrl;
94
- case 'sqlite':
95
- return `file:${database}`;
96
- case 'sqlserver':
97
- case 'mssql':
98
- let sqlserverUrl = `sqlserver://${host}:${port};database=${database};user=${user};password=${password}`;
99
- if (schema) {
100
- sqlserverUrl += `;schema=${encodeURIComponent(schema)}`;
101
- }
102
- return sqlserverUrl;
103
- default:
104
- let defaultUrl = `${provider}://${user}:${password}@${host}:${port}/${database}`;
105
- if (schema) {
106
- defaultUrl += `?schema=${encodeURIComponent(schema)}`;
107
- }
108
- return defaultUrl;
109
- }
110
- }
111
98
  let prismaClient = null;
112
99
  function getPrismaClient() {
113
100
  if (prismaClient) {
114
101
  return prismaClient;
115
102
  }
116
- const config = loadConfig();
117
- const connectionString = getConnectionString(config);
118
- // Set DATABASE_URL for Prisma 7 (required - can't pass url in constructor)
119
- process.env.DATABASE_URL = connectionString;
120
103
  // Try to load Prisma Client from the user's project directory
121
104
  // This allows the generated client to be used
122
105
  const projectRoot = process.cwd();
@@ -132,8 +115,8 @@ function getPrismaClient() {
132
115
  // eslint-disable-next-line @typescript-eslint/no-var-requires
133
116
  PrismaClientClass = require('@prisma/client').PrismaClient;
134
117
  }
135
- // Prisma 7: URL must be set via DATABASE_URL environment variable
136
- // The constructor no longer accepts datasources.url
118
+ // Prisma 7: Reads datasource.url from prisma.config.ts automatically
119
+ // No need to pass it explicitly
137
120
  prismaClient = new PrismaClientClass();
138
121
  return prismaClient;
139
122
  }
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/core/config.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqBA,sCAEC;AAED,gCAcC;AAED,wCAoBC;AAED,kDAiCC;AAID,0CAgCC;AAED,oCAEC;AAxID,uCAAyB;AACzB,2CAA6B;AAiB7B,MAAM,UAAU,GAAG,QAAQ,CAAC;AAC5B,MAAM,WAAW,GAAG,eAAe,CAAC;AAEpC,SAAgB,aAAa;IAC3B,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC;AAC3D,CAAC;AAED,SAAgB,UAAU;IACxB,MAAM,UAAU,GAAG,aAAa,EAAE,CAAC;IAEnC,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;QAC/B,MAAM,IAAI,KAAK,CACb,mCAAmC,UAAU,kCAAkC,CAChF,CAAC;IACJ,CAAC;IAED,MAAM,aAAa,GAAG,EAAE,CAAC,YAAY,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IAC3D,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,aAAa,CAAmB,CAAC;IAE3D,cAAc,CAAC,MAAM,CAAC,CAAC;IACvB,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAgB,cAAc,CAAC,MAAsB;IACnD,MAAM,cAAc,GAA6B;QAC/C,UAAU;QACV,MAAM;QACN,MAAM;QACN,MA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AC,4CAA4C,CAAC,CAAC;IAChE,CAAC;IAED,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,kBAAkB,CAAC,EAAE,CAAC;QAC9C,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;IACzD,CAAC;AACH,CAAC;AAGD,IAAI,YAAY,GAAwB,IAAI,CAAC;AAE7C,SAAgB,eAAe;IAC7B,IAAI,YAAY,EAAE,CAAC;QACjB,OAAO,YAAY,CAAC;IACtB,CAAC;IAED,8DAA8D;IAC9D,8CAA8C;IAC9C,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IAClC,IAAI,iBAAsB,CAAC;IAE3B,IAAI,CAAC;QACH,qDAAqD;QACrD,MAAM,cAAc,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,cAAc,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;QACnF,8DAA8D;QAC9D,iBAAiB,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC,YAAY,CAAC;IAC3D,CAAC;IAAC,MAAM,CAAC;QACP,uCAAuC;QACvC,8DAA8D;QAC9D,iBAAiB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC,YAAY,CAAC;IAC7D,CAAC;IAED,qEAAqE;IACrE,gCAAgC;IAChC,YAAY,GAAG,IAAI,iBAAiB,EAAE,CAAC;IAEvC,OAAO,YAAY,CAAC;AACtB,CAAC;AAED,SAAgB,YAAY;IAC1B,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,UAAU,CAAC,CAAC;AAC9C,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "db-ai",
3
- "version": "1.0.2",
3
+ "version": "2.0.0",
4
4
  "description": "A package to allow AI to access databases with ease using Prisma",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -31,14 +31,14 @@
31
31
  "url": "https://github.com/umang25011/db-ai/issues"
32
32
  },
33
33
  "dependencies": {
34
- "@prisma/client": "^6.18.0",
34
+ "@prisma/client": "^7.2.0",
35
35
  "chalk": "^4.1.2",
36
36
  "commander": "^11.1.0",
37
37
  "json-stringify-safe": "^5.0.1"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@types/node": "^20.10.5",
41
- "prisma": "^6.18.0",
41
+ "prisma": "^7.2.0",
42
42
  "ts-node": "^10.9.2",
43
43
  "typescript": "^5.3.3"
44
44
  },