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