本文整理匯總了TypeScript中Sequelize.Sequelize類的典型用法代碼示例。如果您正苦於以下問題:TypeScript Sequelize類的具體用法?TypeScript Sequelize怎麽用?TypeScript Sequelize使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Sequelize類的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: function
export default function (sequelize: Sequelize, DataTypes: DataTypes) {
let Map = sequelize.define('Map', {
uid: {
type: DataTypes.STRING,
allowNull: false
},
name: {
type: DataTypes.STRING,
allowNull: false
},
author: {
type: DataTypes.STRING,
allowNull: false
},
environment: {
type: DataTypes.STRING,
allowNull: false
}
}, {
tableName: 'core__map',
charset: 'utf8'
});
return Map;
}
示例2: function
export default function (sequelize: Sequelize, DataTypes: DataTypes) {
let Setting = sequelize.define('Setting', {
context: {
type: DataTypes.STRING,
allowNull: false
},
key: {
type: DataTypes.STRING,
allowNull: false
},
name: {
type: DataTypes.STRING,
allowNull: false
},
type: {
type: DataTypes.STRING,
allowNull: false
},
enumeration: {
type: DataTypes.TEXT,
allowNull: true
},
description: {
type: DataTypes.TEXT,
allowNull: true
},
value: {
type: DataTypes.TEXT,
allowNull: true
},
category: {
type: DataTypes.STRING,
allowNull: true
},
visible: {
type: DataTypes.BOOLEAN,
defaultValue: true
}
}, {
tableName: 'core__setting',
charset: 'utf8',
indexes: [
{
unique: true,
fields: ['context', 'key']
}
],
hooks: {
beforeValidate (setting: any, options) {
if (setting.value && typeof setting.value !== 'string')
setting.value = JSON.stringify({value: setting.value});
if (setting.enumeration && Array.isArray(setting.enumeration))
setting.enumeration = JSON.stringify(setting.enumeration);
}
}
});
return Setting;
}
示例3: Promise
return new Promise((resolve, reject) => {
this._db.close().then(() => {
resolve();
}).catch((ex: Error) => {
reject(ex);
});
});
示例4:
list.forEach((file) => {
// Import sequelize model.
let model:any = this.sequelize.import(file);
// Save to model storage of app.
this.app.models[model.name] = model;
});
示例5: handleDelete
public handleDelete(deleteOp: DBRemoveOp<any>) {
return this.sequelize.getQueryInterface().QueryGenerator.deleteQuery(
deleteOp.model.getTableName(),
deleteOp.options.where,
{ ...deleteOp.options, limit: null },
deleteOp.model
);
}
示例6: handleUpdate
public handleUpdate(updateOp: DBUpdateOp<any>) {
return this.sequelize.getQueryInterface().QueryGenerator.updateQuery(
updateOp.model.getTableName(),
updateOp.values,
updateOp.options.where,
updateOp.options
);
}
示例7: handleInsert
public handleInsert(insertOp: DBCreateOp<any>) {
return this.sequelize.getQueryInterface().QueryGenerator.insertQuery(
insertOp.model.getTableName(),
insertOp.values,
insertOp.model.rawAttributes,
{}
);
}
示例8: transact
async function transact() {
const t = await sequelize.transaction({
deferrable: Deferrable.SET_DEFERRED(['test']),
isolationLevel: Transaction.ISOLATION_LEVELS.READ_COMMITTED,
type: Transaction.TYPES.DEFERRED,
});
await t.commit();
await t.rollback();
}
示例9:
sequelize.transaction<void>(async transaction => {
const rows = await sequelize
.query('SELECT * FROM `user`', {
retry: {
max: 123,
},
model: User,
transaction,
logging: true,
})
});