MCPcopy
hub / github.com/sequelize/sequelize / addIndexQuery

Method addIndexQuery

src/dialects/abstract/query-generator.js:625–733  ·  view source on GitHub ↗
(tableName, attributes, options, rawTablename)

Source from the content-addressed store, hash-verified

623 @private
624 */
625 addIndexQuery(tableName, attributes, options, rawTablename) {
626 options = options || {};
627
628 if (!Array.isArray(attributes)) {
629 options = attributes;
630 attributes = undefined;
631 } else {
632 options.fields = attributes;
633 }
634
635 options.prefix = options.prefix || rawTablename || tableName;
636 if (options.prefix && typeof options.prefix === 'string') {
637 options.prefix = options.prefix.replace(/\./g, '_');
638 options.prefix = options.prefix.replace(/("|')/g, '');
639 }
640
641 const fieldsSql = options.fields.map(field => {
642 if (field instanceof Utils.SequelizeMethod) {
643 return this.handleSequelizeMethod(field);
644 }
645 if (typeof field === 'string') {
646 field = {
647 name: field
648 };
649 }
650 let result = '';
651
652 if (field.attribute) {
653 field.name = field.attribute;
654 }
655
656 if (!field.name) {
657 throw new Error(`The following index field has no name: ${util.inspect(field)}`);
658 }
659
660 result += this.quoteIdentifier(field.name);
661
662 if (this._dialect.supports.index.collate && field.collate) {
663 result += ` COLLATE ${this.quoteIdentifier(field.collate)}`;
664 }
665
666 if (this._dialect.supports.index.operator) {
667 const operator = field.operator || options.operator;
668 if (operator) {
669 result += ` ${operator}`;
670 }
671 }
672
673 if (this._dialect.supports.index.length && field.length) {
674 result += `(${field.length})`;
675 }
676
677 if (field.order) {
678 result += ` ${field.order}`;
679 }
680
681 return result;
682 });

Callers 2

index.test.jsFile · 0.45
addIndexMethod · 0.45

Calls 7

handleSequelizeMethodMethod · 0.95
quoteIdentifierMethod · 0.95
whereQueryMethod · 0.95
quoteIdentifiersMethod · 0.95
quoteTableMethod · 0.95
inspectMethod · 0.80
_conformIndexMethod · 0.80

Tested by

no test coverage detected