Changes in view-database.js [69f2a41:81bc7da]
- File:
-
- 1 edited
-
view-database.js (modified) (40 diffs)
Legend:
- Unmodified
- Added
- Removed
-
view-database.js
r69f2a41 r81bc7da 3 3 4 4 const dbPath = path.join(__dirname, 'database', 'handcraft.db'); 5 const db = new sqlite3.Database(dbPath); 5 const db = new sqlite3.Database(dbPath, (err) => { 6 if (err) { 7 console.error('Error opening database:', err.message); 8 process.exit(1); 9 } 10 }); 6 11 7 12 console.log('\nšØ HANDCRAFT MARKETPLACE - DATABASE CONTENTS\n'); … … 25 30 } 26 31 32 // Main execution chain 33 function executeChecks() { 34 let currentCheck = 0; 35 36 const checks = [ 37 { name: 'clients', func: checkClients }, 38 { name: 'personal', func: checkPersonal }, 39 { name: 'store', func: checkStore }, 40 { name: 'product', func: checkProduct }, 41 { name: 'category', func: checkCategory }, 42 { name: 'works_in_store', func: checkWorksInStore }, 43 { name: 'permissions', func: checkPermissions }, 44 { name: 'employees', func: checkEmployees }, 45 { name: 'boss', func: checkBoss }, 46 { name: 'order', func: checkOrder }, 47 { name: 'report', func: checkReport }, 48 { name: 'refund', func: checkRefund }, 49 { name: 'image', func: checkImage }, 50 { name: 'color', func: checkColor } 51 ]; 52 53 function next() { 54 currentCheck++; 55 if (currentCheck < checks.length) { 56 checks[currentCheck].func(next); 57 } else { 58 finish(); 59 } 60 } 61 62 // Start with first check 63 checks[0].func(next); 64 } 65 27 66 // Display CLIENTS table 28 console.log('\nš¤ CLIENTS TABLE:'); 29 console.log('================================================================================'); 30 tableExists('client', (exists) => { 31 if (!exists) { 32 console.log('Table does not exist'); 33 checkNext(); 34 return; 35 } 36 37 db.all('SELECT * FROM client', [], (err, rows) => { 38 if (err) { 39 console.log(`Error: ${err.message}`); 40 checkNext(); 41 return; 42 } 43 44 if (!rows || rows.length === 0) { 45 console.log('No clients found'); 46 } else { 47 console.log(`Total: ${rows.length} clients\n`); 48 rows.forEach((client, index) => { 49 console.log(`ID: ${client.client_id} | Name: ${client.first_name || ''} ${client.last_name || ''}`); 50 console.log(`Email: ${client.email || 'N/A'}`); 51 if (index < rows.length - 1) console.log('-'.repeat(80)); 52 }); 53 } 54 checkNext(); 55 }); 56 }); 67 function checkClients(next) { 68 console.log('\nš¤ CLIENTS TABLE:'); 69 console.log('================================================================================'); 70 71 tableExists('client', (exists) => { 72 if (!exists) { 73 console.log('Table does not exist\n'); 74 if (next) next(); 75 return; 76 } 77 78 db.all('SELECT * FROM client', [], (err, rows) => { 79 if (err) { 80 console.log(`Error: ${err.message}\n`); 81 if (next) next(); 82 return; 83 } 84 85 if (!rows || rows.length === 0) { 86 console.log('No clients found\n'); 87 } else { 88 console.log(`Total: ${rows.length} clients\n`); 89 rows.forEach((client, index) => { 90 console.log(`ID: ${client.client_id} | Name: ${client.first_name || ''} ${client.last_name || ''}`); 91 console.log(`Email: ${client.email || 'N/A'}`); 92 if (index < rows.length - 1) console.log('-'.repeat(80)); 93 }); 94 console.log(); // Add blank line after table 95 } 96 if (next) next(); 97 }); 98 }); 99 } 57 100 58 101 // Display PERSONAL table 59 function checkPersonal( ) {102 function checkPersonal(next) { 60 103 console.log('\nš PERSONAL TABLE (STORE OWNERS/EMPLOYEES):'); 61 104 console.log('================================================================================'); 105 62 106 tableExists('personal', (exists) => { 63 107 if (!exists) { 64 console.log('Table does not exist ');65 checkStore();108 console.log('Table does not exist\n'); 109 if (next) next(); 66 110 return; 67 111 } … … 77 121 `, [], (err, rows) => { 78 122 if (err) { 79 console.log(`Error: ${err.message} `);80 checkStore();81 return; 82 } 83 84 if (!rows || rows.length === 0) { 85 console.log('No personal records found ');123 console.log(`Error: ${err.message}\n`); 124 if (next) next(); 125 return; 126 } 127 128 if (!rows || rows.length === 0) { 129 console.log('No personal records found\n'); 86 130 } else { 87 131 console.log(`Total: ${rows.length} personal records\n`); … … 91 135 if (index < rows.length - 1) console.log('-'.repeat(80)); 92 136 }); 93 } 94 checkStore(); 137 console.log(); 138 } 139 if (next) next(); 95 140 }); 96 141 }); … … 98 143 99 144 // Display STORE table 100 function checkStore( ) {145 function checkStore(next) { 101 146 console.log('\nšŖ STORE TABLE:'); 102 147 console.log('================================================================================'); 148 103 149 tableExists('store', (exists) => { 104 150 if (!exists) { 105 console.log('Table does not exist ');106 checkProduct();151 console.log('Table does not exist\n'); 152 if (next) next(); 107 153 return; 108 154 } … … 110 156 db.all('SELECT * FROM store', [], (err, rows) => { 111 157 if (err) { 112 console.log(`Error: ${err.message} `);113 checkProduct();114 return; 115 } 116 117 if (!rows || rows.length === 0) { 118 console.log('No stores found ');158 console.log(`Error: ${err.message}\n`); 159 if (next) next(); 160 return; 161 } 162 163 if (!rows || rows.length === 0) { 164 console.log('No stores found\n'); 119 165 } else { 120 166 console.log(`Total: ${rows.length} stores\n`); … … 126 172 if (index < rows.length - 1) console.log('-'.repeat(80)); 127 173 }); 128 } 129 checkProduct(); 174 console.log(); 175 } 176 if (next) next(); 130 177 }); 131 178 }); … … 133 180 134 181 // Display PRODUCT table 135 function checkProduct( ) {182 function checkProduct(next) { 136 183 console.log('\nšļø PRODUCT TABLE:'); 137 184 console.log('================================================================================'); 185 138 186 tableExists('product', (exists) => { 139 187 if (!exists) { 140 console.log('Table does not exist ');141 checkCategory();188 console.log('Table does not exist\n'); 189 if (next) next(); 142 190 return; 143 191 } … … 149 197 `, [], (err, rows) => { 150 198 if (err) { 151 console.log(`Error: ${err.message} `);152 checkCategory();153 return; 154 } 155 156 if (!rows || rows.length === 0) { 157 console.log('No products found ');199 console.log(`Error: ${err.message}\n`); 200 if (next) next(); 201 return; 202 } 203 204 if (!rows || rows.length === 0) { 205 console.log('No products found\n'); 158 206 } else { 159 207 console.log(`Total: ${rows.length} products\n`); … … 165 213 if (index < rows.length - 1) console.log('-'.repeat(80)); 166 214 }); 167 } 168 checkCategory(); 215 console.log(); 216 } 217 if (next) next(); 169 218 }); 170 219 }); … … 172 221 173 222 // Display CATEGORY table 174 function checkCategory( ) {223 function checkCategory(next) { 175 224 console.log('\nš CATEGORY TABLE:'); 176 225 console.log('================================================================================'); 226 177 227 tableExists('category', (exists) => { 178 228 if (!exists) { 179 console.log('Table does not exist ');180 checkWorksInStore();229 console.log('Table does not exist\n'); 230 if (next) next(); 181 231 return; 182 232 } … … 188 238 `, [], (err, rows) => { 189 239 if (err) { 190 console.log(`Error: ${err.message} `);191 checkWorksInStore();192 return; 193 } 194 195 if (!rows || rows.length === 0) { 196 console.log('No categories found ');240 console.log(`Error: ${err.message}\n`); 241 if (next) next(); 242 return; 243 } 244 245 if (!rows || rows.length === 0) { 246 console.log('No categories found\n'); 197 247 } else { 198 248 console.log(`Total: ${rows.length} categories\n`); … … 203 253 if (index < rows.length - 1) console.log('-'.repeat(80)); 204 254 }); 205 } 206 checkWorksInStore(); 255 console.log(); 256 } 257 if (next) next(); 207 258 }); 208 259 }); … … 210 261 211 262 // Display WORKS_IN_STORE table 212 function checkWorksInStore( ) {263 function checkWorksInStore(next) { 213 264 console.log('\nš WORKS_IN_STORE TABLE:'); 214 265 console.log('================================================================================'); 266 215 267 tableExists('works_in_store', (exists) => { 216 268 if (!exists) { 217 console.log('Table does not exist ');218 checkPermissions();269 console.log('Table does not exist\n'); 270 if (next) next(); 219 271 return; 220 272 } … … 227 279 `, [], (err, rows) => { 228 280 if (err) { 229 console.log(`Error: ${err.message} `);230 checkPermissions();231 return; 232 } 233 234 if (!rows || rows.length === 0) { 235 console.log('No assignments found ');281 console.log(`Error: ${err.message}\n`); 282 if (next) next(); 283 return; 284 } 285 286 if (!rows || rows.length === 0) { 287 console.log('No assignments found\n'); 236 288 } else { 237 289 console.log(`Total: ${rows.length} assignments\n`); … … 241 293 if (index < rows.length - 1) console.log('-'.repeat(80)); 242 294 }); 243 } 244 checkPermissions(); 295 console.log(); 296 } 297 if (next) next(); 245 298 }); 246 299 }); … … 248 301 249 302 // Display PERMISSIONS table 250 function checkPermissions( ) {303 function checkPermissions(next) { 251 304 console.log('\nš PERMISSIONS TABLE:'); 252 305 console.log('================================================================================'); 306 253 307 tableExists('permissions', (exists) => { 254 308 if (!exists) { 255 console.log('Table does not exist ');256 checkEmployees();309 console.log('Table does not exist\n'); 310 if (next) next(); 257 311 return; 258 312 } … … 264 318 `, [], (err, rows) => { 265 319 if (err) { 266 console.log(`Error: ${err.message} `);267 checkEmployees();268 return; 269 } 270 271 if (!rows || rows.length === 0) { 272 console.log('No permissions found ');320 console.log(`Error: ${err.message}\n`); 321 if (next) next(); 322 return; 323 } 324 325 if (!rows || rows.length === 0) { 326 console.log('No permissions found\n'); 273 327 } else { 274 328 console.log(`Total: ${rows.length} permissions\n`); … … 278 332 if (index < rows.length - 1) console.log('-'.repeat(80)); 279 333 }); 280 } 281 checkEmployees(); 334 console.log(); 335 } 336 if (next) next(); 282 337 }); 283 338 }); … … 285 340 286 341 // Display EMPLOYEES table 287 function checkEmployees( ) {342 function checkEmployees(next) { 288 343 console.log('\nš· EMPLOYEES TABLE:'); 289 344 console.log('================================================================================'); 345 290 346 tableExists('employees', (exists) => { 291 347 if (!exists) { 292 console.log('Table does not exist ');293 checkBoss();348 console.log('Table does not exist\n'); 349 if (next) next(); 294 350 return; 295 351 } … … 301 357 `, [], (err, rows) => { 302 358 if (err) { 303 console.log(`Error: ${err.message} `);304 checkBoss();305 return; 306 } 307 308 if (!rows || rows.length === 0) { 309 console.log('No employees found ');359 console.log(`Error: ${err.message}\n`); 360 if (next) next(); 361 return; 362 } 363 364 if (!rows || rows.length === 0) { 365 console.log('No employees found\n'); 310 366 } else { 311 367 console.log(`Total: ${rows.length} employees\n`); … … 315 371 if (index < rows.length - 1) console.log('-'.repeat(80)); 316 372 }); 317 } 318 checkBoss(); 373 console.log(); 374 } 375 if (next) next(); 319 376 }); 320 377 }); … … 322 379 323 380 // Display BOSS table 324 function checkBoss( ) {381 function checkBoss(next) { 325 382 console.log('\nš BOSS TABLE:'); 326 383 console.log('================================================================================'); 384 327 385 tableExists('boss', (exists) => { 328 386 if (!exists) { 329 console.log('Table does not exist ');330 checkOrder();387 console.log('Table does not exist\n'); 388 if (next) next(); 331 389 return; 332 390 } … … 338 396 `, [], (err, rows) => { 339 397 if (err) { 340 console.log(`Error: ${err.message} `);341 checkOrder();342 return; 343 } 344 345 if (!rows || rows.length === 0) { 346 console.log('No bosses found ');398 console.log(`Error: ${err.message}\n`); 399 if (next) next(); 400 return; 401 } 402 403 if (!rows || rows.length === 0) { 404 console.log('No bosses found\n'); 347 405 } else { 348 406 console.log(`Total: ${rows.length} bosses\n`); … … 352 410 if (index < rows.length - 1) console.log('-'.repeat(80)); 353 411 }); 354 } 355 checkOrder(); 412 console.log(); 413 } 414 if (next) next(); 356 415 }); 357 416 }); … … 359 418 360 419 // Display ORDER table 361 function checkOrder( ) {420 function checkOrder(next) { 362 421 console.log('\nš¦ ORDERS TABLE:'); 363 422 console.log('================================================================================'); 423 364 424 tableExists('order', (exists) => { 365 425 if (!exists) { 366 console.log('Table does not exist ');367 checkReport();426 console.log('Table does not exist\n'); 427 if (next) next(); 368 428 return; 369 429 } … … 376 436 `, [], (err, rows) => { 377 437 if (err) { 378 console.log(`Error: ${err.message} `);379 checkReport();380 return; 381 } 382 383 if (!rows || rows.length === 0) { 384 console.log('No orders found ');438 console.log(`Error: ${err.message}\n`); 439 if (next) next(); 440 return; 441 } 442 443 if (!rows || rows.length === 0) { 444 console.log('No orders found\n'); 385 445 } else { 386 446 console.log(`Total: ${rows.length} orders\n`); … … 392 452 if (index < rows.length - 1) console.log('-'.repeat(80)); 393 453 }); 394 } 395 checkReport(); 454 console.log(); 455 } 456 if (next) next(); 396 457 }); 397 458 }); … … 399 460 400 461 // Display REPORT table 401 function checkReport( ) {462 function checkReport(next) { 402 463 console.log('\nš REPORTS TABLE:'); 403 464 console.log('================================================================================'); 465 404 466 tableExists('report', (exists) => { 405 467 if (!exists) { 406 console.log('Table does not exist ');407 checkRefund();468 console.log('Table does not exist\n'); 469 if (next) next(); 408 470 return; 409 471 } … … 411 473 db.all('SELECT * FROM report', [], (err, rows) => { 412 474 if (err) { 413 console.log(`Error: ${err.message} `);414 checkRefund();415 return; 416 } 417 418 if (!rows || rows.length === 0) { 419 console.log('No reports found ');475 console.log(`Error: ${err.message}\n`); 476 if (next) next(); 477 return; 478 } 479 480 if (!rows || rows.length === 0) { 481 console.log('No reports found\n'); 420 482 } else { 421 483 console.log(`Total: ${rows.length} reports\n`); … … 425 487 if (index < rows.length - 1) console.log('-'.repeat(80)); 426 488 }); 427 } 428 checkRefund(); 489 console.log(); 490 } 491 if (next) next(); 429 492 }); 430 493 }); … … 432 495 433 496 // Display REFUND table 434 function checkRefund( ) {497 function checkRefund(next) { 435 498 console.log('\nš° REFUND TABLE:'); 436 499 console.log('================================================================================'); 500 437 501 tableExists('refund', (exists) => { 438 502 if (!exists) { 439 console.log('Table does not exist ');440 checkImage();503 console.log('Table does not exist\n'); 504 if (next) next(); 441 505 return; 442 506 } … … 444 508 db.all('SELECT * FROM refund', [], (err, rows) => { 445 509 if (err) { 446 console.log(`Error: ${err.message} `);447 checkImage();448 return; 449 } 450 451 if (!rows || rows.length === 0) { 452 console.log('No refunds found ');510 console.log(`Error: ${err.message}\n`); 511 if (next) next(); 512 return; 513 } 514 515 if (!rows || rows.length === 0) { 516 console.log('No refunds found\n'); 453 517 } else { 454 518 console.log(`Total: ${rows.length} refunds\n`); … … 459 523 if (index < rows.length - 1) console.log('-'.repeat(80)); 460 524 }); 461 } 462 checkImage(); 525 console.log(); 526 } 527 if (next) next(); 463 528 }); 464 529 }); … … 466 531 467 532 // Display IMAGE table 468 function checkImage( ) {533 function checkImage(next) { 469 534 console.log('\nš¼ļø IMAGE TABLE:'); 470 535 console.log('================================================================================'); 536 471 537 tableExists('image', (exists) => { 472 538 if (!exists) { 473 console.log('Table does not exist ');474 checkColor();539 console.log('Table does not exist\n'); 540 if (next) next(); 475 541 return; 476 542 } … … 478 544 db.all('SELECT * FROM image', [], (err, rows) => { 479 545 if (err) { 480 console.log(`Error: ${err.message} `);481 checkColor();482 return; 483 } 484 485 if (!rows || rows.length === 0) { 486 console.log('No images found ');546 console.log(`Error: ${err.message}\n`); 547 if (next) next(); 548 return; 549 } 550 551 if (!rows || rows.length === 0) { 552 console.log('No images found\n'); 487 553 } else { 488 554 console.log(`Total: ${rows.length} images\n`); … … 491 557 if (index < rows.length - 1) console.log('-'.repeat(80)); 492 558 }); 493 } 494 checkColor(); 559 console.log(); 560 } 561 if (next) next(); 495 562 }); 496 563 }); … … 498 565 499 566 // Display COLOR table 500 function checkColor( ) {567 function checkColor(next) { 501 568 console.log('\nšØ COLOR TABLE:'); 502 569 console.log('================================================================================'); 570 503 571 tableExists('color', (exists) => { 504 572 if (!exists) { 505 console.log('Table does not exist ');506 finish();573 console.log('Table does not exist\n'); 574 if (next) next(); 507 575 return; 508 576 } … … 510 578 db.all('SELECT * FROM color', [], (err, rows) => { 511 579 if (err) { 512 console.log(`Error: ${err.message} `);513 finish();514 return; 515 } 516 517 if (!rows || rows.length === 0) { 518 console.log('No colors found ');580 console.log(`Error: ${err.message}\n`); 581 if (next) next(); 582 return; 583 } 584 585 if (!rows || rows.length === 0) { 586 console.log('No colors found\n'); 519 587 } else { 520 588 console.log(`Total: ${rows.length} colors\n`); … … 523 591 if (index < rows.length - 1) console.log('-'.repeat(80)); 524 592 }); 525 } 526 finish(); 527 }); 528 }); 529 } 530 531 // Start the chain of checks 532 function checkNext() { 533 checkPersonal(); 534 } 535 593 console.log(); 594 } 595 if (next) next(); 596 }); 597 }); 598 } 599 600 // Finish and close database 536 601 function finish() { 537 console.log(' \n' + '='.repeat(80));602 console.log('='.repeat(80)); 538 603 console.log('ā Database inspection complete'); 539 604 console.log('='.repeat(80) + '\n'); 540 605 541 db.close(); 542 } 543 544 // Start with CLIENTS 545 checkNext(); 606 db.close((err) => { 607 if (err) { 608 console.error('Error closing database:', err.message); 609 } 610 }); 611 } 612 613 // Start the execution chain 614 executeChecks();
Note:
See TracChangeset
for help on using the changeset viewer.
