MCPcopy
hub / github.com/sequelize/sequelize / run

Method run

src/dialects/postgres/query.js:49–309  ·  view source on GitHub ↗
(sql, parameters)

Source from the content-addressed store, hash-verified

47 }
48
49 async run(sql, parameters) {
50 const { connection } = this;
51
52 if (!_.isEmpty(this.options.searchPath)) {
53 sql = this.sequelize.getQueryInterface().queryGenerator.setSearchPath(this.options.searchPath) + sql;
54 }
55
56 if (this.sequelize.options.minifyAliases && this.options.includeAliases) {
57 _.toPairs(this.options.includeAliases)
58 // Sorting to replace the longest aliases first to prevent alias collision
59 .sort((a, b) => b[1].length - a[1].length)
60 .forEach(([alias, original]) => {
61 const reg = new RegExp(_.escapeRegExp(original), 'g');
62
63 sql = sql.replace(reg, alias);
64 });
65 }
66
67 this.sql = sql;
68
69 const query = parameters && parameters.length
70 ? new Promise((resolve, reject) => connection.query(sql, parameters, (error, result) => error ? reject(error) : resolve(result)))
71 : new Promise((resolve, reject) => connection.query(sql, (error, result) => error ? reject(error) : resolve(result)));
72
73 const complete = this._logQuery(sql, debug, parameters);
74
75 let queryResult;
76 const errForStack = new Error();
77
78 try {
79 queryResult = await query;
80 } catch (error) {
81 // set the client so that it will be reaped if the connection resets while executing
82 if (error.code === 'ECONNRESET'
83 // https://github.com/sequelize/sequelize/pull/14090
84 // pg-native throws custom exception or libpq formatted errors
85 || /Unable to set non-blocking to true/i.test(error)
86 || /SSL SYSCALL error: EOF detected/i.test(error)
87 || /Local: Authentication failure/i.test(error)
88 // https://github.com/sequelize/sequelize/pull/15144
89 || error.message === 'Query read timeout'
90 ) {
91 connection._invalid = true;
92 }
93
94 error.sql = sql;
95 error.parameters = parameters;
96 throw this.formatError(error, errForStack.stack);
97 }
98
99 complete();
100
101 let rows = Array.isArray(queryResult)
102 ? queryResult.reduce((allRows, r) => allRows.concat(r.rows || []), [])
103 : queryResult.rows;
104 const rowCount = Array.isArray(queryResult)
105 ? queryResult.reduce(
106 (count, r) => Number.isFinite(r.rowCount) ? count + r.rowCount : count,

Callers

nothing calls this directly

Calls 15

formatErrorMethod · 0.95
isShowIndexesQueryMethod · 0.95
isForeignKeysQueryMethod · 0.95
isShowOrDescribeQueryMethod · 0.95
setSearchPathMethod · 0.80
getQueryInterfaceMethod · 0.80
_logQueryMethod · 0.80
fromArrayMethod · 0.80
isSelectQueryMethod · 0.80
handleSelectQueryMethod · 0.80
isVersionQueryMethod · 0.80
isInsertQueryMethod · 0.80

Tested by

no test coverage detected