query(query, values) { const queryWithParams = applyParams(query, values); const cancelObj = {}; const promise = this.queryPromised(queryWithParams, cancelObj, this.prepareConnectionQueries()); promise.cancel = () => cancelObj.cancel && cancelObj.cancel() || Promise.reject(new Error('Statement is not ready')); return promise; }
test('priority', async () => { delayCount = 0; const result = await Promise.all([ queue.executeInQueue('delay', `11`, { delay: 600, result: '1' }, 1), queue.executeInQueue('delay', `12`, { delay: 100, result: '2' }, 0), queue.executeInQueue('delay', `13`, { delay: 100, result: '3' }, 10) ]); expect(parseInt(result.find(f => f[0] === '3'), 10) % 10).toBeLessThan(2); });
async tablesSchema() { const tables = await this.query(`show tables in ${this.config.dbName}`); return { [this.config.dbName]: (await Promise.all(tables.map(async table => { const tableName = table.tab_name || table.tableName; const columns = await this.query(`describe ${this.config.dbName}.${tableName}`); return { [tableName]: columns.map(c => ({ name: c.col_name, type: c.data_type })) }; }))).reduce((a, b) => ({ ...a, ...b }), {}) }; }
async renderChoices() { if (this.state.submitted) return ''; let choices = this.visible.map(async(ch, i) => await this.renderChoice(ch, i)); let visible = await Promise.all(choices); if (!visible.length) visible.push(this.styles.danger('No matching choices')); return visible.join('\n'); }
async process() { try { let issues = await Promise.all(this.repositories.map(async repository => await this.getIssues(repository))); issues = issues.filter(issueArray => issueArray.length > 0).flat().flat(); const groupedIssues = this.groupIssues(issues); const bot = new BotService(this.context); await bot.sendData(groupedIssues); } catch ({ message }) { this.context.error(message) } }
getAllClasses() { if (!this.ttl) { return Promise.resolve(null); } return this.cache.get(this.prefix + MAIN_SCHEMA); }
this.config.database.find('_User', { objectId: this.objectId() }).then(results => { if (results.length != 1) { throw undefined; } if (this.data.password.indexOf(results[0].username) >= 0) return Promise.reject(new Parse.Error(Parse.Error.VALIDATION_ERROR, containsUsernameError)); return Promise.resolve(); })
async _initializeSchemaAndConfig() { const [schemaController, parseGraphQLConfig] = await Promise.all([this.databaseController.loadSchema(), this.parseGraphQLController.getGraphQLConfig()]); this.schemaController = schemaController; return { parseGraphQLConfig }; }
query(query) { this.executedQueries.push(query); let promise = Promise.resolve([query]); if (query.match(`orders_too_big`)) { promise = promise.then((res) => new Promise(resolve => setTimeout(() => resolve(res), 3000))); } promise.cancel = async () => { this.cancelledQueries.push(query); }; return promise; }
// Sets the Class-level permissions for a given className, which must exist. setPermissions(className, perms, newSchema) { if (typeof perms === 'undefined') { return Promise.resolve(); } validateCLP(perms, newSchema, this.userIdRegEx); return this._dbAdapter.setClassLevelPermissions(className, perms); }
updateDisks() { if (!PLATFORMS_SUPPORTED.includes(process.platform)) { return Promise.resolve([]); } return diskUsage[process.platform]().then(disks => { if (disks.length !== this.disks.length || disks.some((d, i) => d.used !== this.disks[i].used)) { this.tLastChange = Date.now(); this.disks = disks; this.emit(diskUsageServiceEvents.DISK_USAGE_CHANGE, this.getDiskUsage()); } }); }
setAllClasses(schema) { if (!this.ttl) { return Promise.resolve(null); } return this.cache.put(this.prefix + MAIN_SCHEMA, schema); }