MCPcopy Index your code
hub / github.com/sequelize/sequelize / run

Method run

src/dialects/sqlite/query.js:228–303  ·  view source on GitHub ↗
(sql, parameters)

Source from the content-addressed store, hash-verified

226 }
227
228 async run(sql, parameters) {
229 const conn = this.connection;
230 this.sql = sql;
231 const method = this.getDatabaseMethod();
232 const complete = this._logQuery(sql, debug, parameters);
233
234 return new Promise((resolve, reject) => conn.serialize(async () => {
235 const columnTypes = {};
236 const errForStack = new Error();
237 const executeSql = () => {
238 if (sql.startsWith('-- ')) {
239 return resolve();
240 }
241 const query = this;
242 // cannot use arrow function here because the function is bound to the statement
243 function afterExecute(executionError, results) {
244 try {
245 complete();
246 // `this` is passed from sqlite, we have no control over this.
247 // eslint-disable-next-line no-invalid-this
248 resolve(query._handleQueryResponse(this, columnTypes, executionError, results, errForStack.stack));
249 return;
250 } catch (error) {
251 reject(error);
252 }
253 }
254
255 if (!parameters) parameters = [];
256
257 if (_.isPlainObject(parameters)) {
258 const newParameters = Object.create(null);
259 for (const key of Object.keys(parameters)) {
260 newParameters[`${key}`] = stringifyIfBigint(parameters[key]);
261 }
262 parameters = newParameters;
263 } else {
264 parameters = parameters.map(stringifyIfBigint);
265 }
266
267 conn[method](sql, parameters, afterExecute);
268
269 return null;
270 };
271
272 if (this.getDatabaseMethod() === 'all') {
273 let tableNames = [];
274 if (this.options && this.options.tableNames) {
275 tableNames = this.options.tableNames;
276 } else if (/FROM `(.*?)`/i.exec(this.sql)) {
277 tableNames.push(/FROM `(.*?)`/i.exec(this.sql)[1]);
278 }
279
280 // If we already have the metadata for the table, there's no need to ask for it again
281 tableNames = tableNames.filter(tableName => !(tableName in columnTypes) && tableName !== 'sqlite_master');
282
283 if (!tableNames.length) {
284 return executeSql();
285 }

Callers 2

getConnectionMethod · 0.45

Calls 3

getDatabaseMethodMethod · 0.95
_logQueryMethod · 0.80
allMethod · 0.80

Tested by

no test coverage detected