MCPcopy
hub / github.com/sequelize/sequelize / query

Method query

lib/sequelize.js:528–650  ·  view source on GitHub ↗

* Execute a query on the DB, optionally bypassing all the Sequelize goodness. * * By default, the function will return two arguments: an array of results, and a metadata object, containing number of affected rows etc. * * If you are running a type of query where you don't need the metada

(sql, options)

Source from the content-addressed store, hash-verified

526 */
527
528 async query(sql, options) {
529 options = { ...this.options.query, ...options };
530
531 if (options.instance && !options.model) {
532 options.model = options.instance.constructor;
533 }
534
535 if (!options.instance && !options.model) {
536 options.raw = true;
537 }
538
539 // map raw fields to model attributes
540 if (options.mapToModel) {
541 options.fieldMap = _.get(options, 'model.fieldAttributeMap', {});
542 }
543
544 options = _.defaults(options, {
545 // eslint-disable-next-line no-console
546 logging: Object.prototype.hasOwnProperty.call(this.options, 'logging') ? this.options.logging : console.log,
547 searchPath: Object.prototype.hasOwnProperty.call(this.options, 'searchPath') ? this.options.searchPath : 'DEFAULT'
548 });
549
550 if (!options.type) {
551 if (options.model || options.nest || options.plain) {
552 options.type = QueryTypes.SELECT;
553 } else {
554 options.type = QueryTypes.RAW;
555 }
556 }
557
558 //if dialect doesn't support search_path or dialect option
559 //to prepend searchPath is not true delete the searchPath option
560 if (
561 !this.dialect.supports.searchPath ||
562 !this.options.dialectOptions ||
563 !this.options.dialectOptions.prependSearchPath ||
564 options.supportsSearchPath === false
565 ) {
566 delete options.searchPath;
567 } else if (!options.searchPath) {
568 //if user wants to always prepend searchPath (dialectOptions.preprendSearchPath = true)
569 //then set to DEFAULT if none is provided
570 options.searchPath = 'DEFAULT';
571 }
572
573 if (typeof sql === 'object') {
574 if (sql.values !== undefined) {
575 if (options.replacements !== undefined) {
576 throw new Error('Both `sql.values` and `options.replacements` cannot be set at the same time');
577 }
578 options.replacements = sql.values;
579 }
580
581 if (sql.bind !== undefined) {
582 if (options.bind !== undefined) {
583 throw new Error('Both `sql.bind` and `options.bind` cannot be set at the same time');
584 }
585 options.bind = sql.bind;

Callers 2

setMethod · 0.95
authenticateMethod · 0.95

Calls 6

runMethod · 0.95
formatMethod · 0.80
getMethod · 0.65
getConnectionMethod · 0.65
releaseConnectionMethod · 0.65
formatBindParametersMethod · 0.45

Tested by

no test coverage detected