| 606 | } |
| 607 | |
| 608 | handleShowIndexesQuery(data) { |
| 609 | const acc = []; |
| 610 | |
| 611 | // We first treat the datas |
| 612 | data.forEach(indexRecord => { |
| 613 | // We create the object |
| 614 | if (!acc[indexRecord.INDEX_NAME]) { |
| 615 | acc[indexRecord.INDEX_NAME] = { |
| 616 | unique: indexRecord.UNIQUENESS === 'UNIQUE' ? true : false, |
| 617 | primary: indexRecord.CONSTRAINT_TYPE === 'P', |
| 618 | name: indexRecord.INDEX_NAME.toLowerCase(), |
| 619 | tableName: indexRecord.TABLE_NAME.toLowerCase(), |
| 620 | type: undefined |
| 621 | }; |
| 622 | acc[indexRecord.INDEX_NAME].fields = []; |
| 623 | } |
| 624 | |
| 625 | // We create the fields |
| 626 | acc[indexRecord.INDEX_NAME].fields.push({ |
| 627 | attribute: indexRecord.COLUMN_NAME, |
| 628 | length: undefined, |
| 629 | order: indexRecord.DESCEND, |
| 630 | collate: undefined |
| 631 | }); |
| 632 | }); |
| 633 | |
| 634 | const returnIndexes = []; |
| 635 | const accKeys = Object.keys(acc); |
| 636 | for (const accKey of accKeys) { |
| 637 | const columns = {}; |
| 638 | columns.fields = acc[accKey].fields; |
| 639 | // We are generating index field name in the format sequelize expects |
| 640 | // to avoid creating a unique index on auto-generated index name |
| 641 | if (acc[accKey].name.match(/sys_c[0-9]*/)) { |
| 642 | acc[accKey].name = Utils.nameIndex(columns, acc[accKey].tableName).name; |
| 643 | } |
| 644 | returnIndexes.push(acc[accKey]); |
| 645 | } |
| 646 | return returnIndexes; |
| 647 | } |
| 648 | |
| 649 | handleInsertQuery(results, metaData) { |
| 650 | if (this.instance && results.length > 0) { |