本文整理汇总了TypeScript中Sequelize.Sequelize.query方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Sequelize.query方法的具体用法?TypeScript Sequelize.query怎么用?TypeScript Sequelize.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sequelize.Sequelize
的用法示例。
在下文中一共展示了Sequelize.query方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
sequelize.transaction<void>(async transaction => {
const rows = await sequelize
.query('SELECT * FROM `user`', {
retry: {
max: 123,
},
model: User,
transaction,
logging: true,
})
});
示例2: function
(Task as any).prototype.touch = async function(this: TaskInstance) {
debug(`${process.pid} '.touch()' called for task ${this.name} (${this.id})`);
this.emit('touch');
await this.sequelize.query(`UPDATE "Locks" SET "updatedAt" = NOW() WHERE "TaskId" = :task_id`, {
replacements: {
task_id: this.id,
},
type: QueryTypes.UPDATE,
});
};
示例3: performOps
/**
* Batches operations together and performs them parallelly (eventually in a transaction)
* @param {Array<IDBOp<any>>} what
* @param {sequelize.Transaction} transaction
* @returns {Promise<[Model<string>[] , any]>}
*/
public async performOps(what: Array<DBOp<any>>, transaction?: sequelize.Transaction) {
const baseOptions: any = { raw: true };
if (transaction) {
baseOptions.transaction = transaction;
}
const opsToDoIterator = this.splitOps(what, 1010);
let chunk = opsToDoIterator.next();
while (!chunk.done) {
chunk = await (async () => {
const p = this.sequelize.query(chunk.value, baseOptions);
const nextChunk = await wait(1).then(() => opsToDoIterator.next());
return p.then(() => nextChunk);
})();
}
await this.sequelize.query(chunk.value, baseOptions);
}
示例4: merge
return new Promise<Object | Object[]>((resolve, reject) => {
var replacements = merge(defaults, params),
merged_sql = sql({ auth, query: replacements }),
required_params = get_params(merged_sql);
try {
check_params(required_params, replacements);
conn.query(merged_sql, { replacements })
.then(one_row ? head : pass)
.then(head)
.then(processor)
.then(resolve)
.catch(reject);
} catch (err) {
reject(err);
}
});
示例5: await
chunk = await (async () => {
const p = this.sequelize.query(chunk.value, baseOptions);
const nextChunk = await wait(1).then(() => opsToDoIterator.next());
return p.then(() => nextChunk);
})();
示例6: Sequelize
import { QueryTypes, Sequelize, SyncOptions } from 'sequelize';
import { User } from 'models/User';
export const sequelize = new Sequelize('uri');
sequelize.afterBulkSync((options: SyncOptions) => {
console.log('synced');
});
sequelize
.query('SELECT * FROM `test`', {
type: QueryTypes.SELECT,
})
.then(rows => {
rows.forEach(row => {
console.log(row);
});
});
sequelize
.query('INSERT into test set test=1', {
type: QueryTypes.INSERT,
})
.then(([aiId, affected]) => {
console.log(aiId, affected);
});
sequelize.transaction<void>(async transaction => {
const rows = await sequelize
.query('SELECT * FROM `user`', {
retry: {
示例7: Sequelize
import { QueryTypes, Sequelize, SyncOptions } from 'sequelize';
export const sequelize = new Sequelize('uri');
sequelize.afterBulkSync((options: SyncOptions) => {
console.log('synced');
});
sequelize
.query('SELECT * FROM `test`', {
type: QueryTypes.SELECT,
})
.then(rows => {
rows.forEach(row => {
console.log(row);
});
});
sequelize
.query('INSERT into test set test=1', {
type: QueryTypes.INSERT,
})
.then(([aiId, affected]) => {
console.log(aiId, affected);
});
示例8: select
export function select(sql: string) {
return sequelize.query(sql, { type: QueryTypes.SELECT })
}