( schemaName: string, cursor: CursorV2 )
| 416 | } |
| 417 | |
| 418 | function parseTableDefinition( |
| 419 | schemaName: string, |
| 420 | cursor: CursorV2 |
| 421 | ): { |
| 422 | columns: DatabaseTableColumn[]; |
| 423 | constraints: DatabaseTableColumnConstraint[]; |
| 424 | } { |
| 425 | let moveNext = true; |
| 426 | const columns: DatabaseTableColumn[] = []; |
| 427 | const constraints: DatabaseTableColumnConstraint[] = []; |
| 428 | |
| 429 | while (moveNext) { |
| 430 | moveNext = false; |
| 431 | |
| 432 | if ( |
| 433 | cursor.matchTokens([ |
| 434 | "CONSTRAINT", |
| 435 | "PRIMARY", |
| 436 | "UNIQUE", |
| 437 | "CHECK", |
| 438 | "FOREIGN", |
| 439 | ]) |
| 440 | ) { |
| 441 | const constraint = parseColumnConstraint(schemaName, cursor); |
| 442 | if (constraint) { |
| 443 | constraints.push(constraint); |
| 444 | moveNext = true; |
| 445 | } |
| 446 | } else { |
| 447 | const column = parseColumnDef(schemaName, cursor); |
| 448 | if (column) { |
| 449 | columns.push(column); |
| 450 | moveNext = true; |
| 451 | } |
| 452 | } |
| 453 | |
| 454 | while (cursor.read() !== "," && !cursor.end()) { |
| 455 | cursor.next(); |
| 456 | } |
| 457 | |
| 458 | if (cursor.end()) break; |
| 459 | cursor.next(); |
| 460 | } |
| 461 | |
| 462 | // console.log(columns, constraints); |
| 463 | |
| 464 | for (const constraint of constraints) { |
| 465 | if (constraint.primaryKey && constraint.primaryColumns) { |
| 466 | for (const pkColumn of constraint.primaryColumns) { |
| 467 | const column = columns.find( |
| 468 | (col) => pkColumn.toLowerCase() === col.name.toLowerCase() |
| 469 | ); |
| 470 | |
| 471 | if (column) { |
| 472 | column.pk = true; |
| 473 | } |
| 474 | } |
| 475 | } |
no test coverage detected
searching dependent graphs…