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

Method addIndexQuery

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

Source from the content-addressed store, hash-verified

515 @private
516 */
517 addIndexQuery(tableName, attributes, options, rawTablename) {
518 options = options || {};
519
520 if (!Array.isArray(attributes)) {
521 options = attributes;
522 attributes = undefined;
523 } else {
524 options.fields = attributes;
525 }
526
527 options.prefix = options.prefix || rawTablename || tableName;
528 if (options.prefix && typeof options.prefix === 'string') {
529 options.prefix = options.prefix.replace(/\./g, '_');
530 options.prefix = options.prefix.replace(/("|')/g, '');
531 }
532
533 const fieldsSql = options.fields.map(field => {
534 if (field instanceof Utils.SequelizeMethod) {
535 return this.handleSequelizeMethod(field);
536 }
537 if (typeof field === 'string') {
538 field = {
539 name: field
540 };
541 }
542 let result = '';
543
544 if (field.attribute) {
545 field.name = field.attribute;
546 }
547
548 if (!field.name) {
549 throw new Error(`The following index field has no name: ${util.inspect(field)}`);
550 }
551
552 result += this.quoteIdentifier(field.name);
553
554 if (this._dialect.supports.index.collate && field.collate) {
555 result += ` COLLATE ${this.quoteIdentifier(field.collate)}`;
556 }
557
558 if (this._dialect.supports.index.operator) {
559 const operator = field.operator || options.operator;
560 if (operator) {
561 result += ` ${operator}`;
562 }
563 }
564
565 if (this._dialect.supports.index.length && field.length) {
566 result += `(${field.length})`;
567 }
568
569 if (field.order) {
570 result += ` ${field.order}`;
571 }
572
573 return result;
574 });

Callers 2

addIndexMethod · 0.80
index.test.jsFile · 0.80

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