本文整理汇总了TypeScript中Sequelize.Sequelize.define方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Sequelize.define方法的具体用法?TypeScript Sequelize.define怎么用?TypeScript Sequelize.define使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sequelize.Sequelize
的用法示例。
在下文中一共展示了Sequelize.define方法的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: lockModel
private lockModel() {
return this.sequelize.define<LockInstance, LockAttribute>('Lock', {
workerName: {
type: this.sequelize.Sequelize.STRING,
allowNull: false,
validate: {
notEmpty: true,
},
},
}, {timestamps: true});
}
示例4: initCourseModel
export function initCourseModel(sequelize: Sequelize) {
return sequelize.define("Course", {
description: ORM.STRING,
url: ORM.STRING,
longDescription: ORM.TEXT,
iconUrl: ORM.STRING,
courseListIcon: ORM.STRING,
seqNo: ORM.STRING,
comingSoon: ORM.BOOLEAN,
isNew: ORM.BOOLEAN,
isOngoing: ORM.BOOLEAN,
});
}
示例5: function
export default function(sequelize: Sequelize, dataTypes: DataTypes):
SequelizeStatic.Model<ProductInstance, ProductAttributes> {
let Product = sequelize.define<ProductInstance, ProductAttributes>("Product", {
name: {type: dataTypes.STRING, allowNull: false, primaryKey: true},
description: {type: dataTypes.TEXT, allowNull: true}
}, {
indexes: [],
classMethods: {},
timestamps: false
});
return Product;
}
示例6: schema
static schema(sequelize: Sequelize, dataTypes: DataTypes): any {
let schemaUser: DefineAttributes = {
username: {
type: dataTypes.STRING,
unique: true
},
password: {
type: dataTypes.STRING
},
displayName: {
type: dataTypes.STRING
}
};
return sequelize.define("Users", schemaUser);
}
示例7: initLessonModel
export function initLessonModel(sequelize: Sequelize) {
return sequelize.define("Lesson", {
id: {
type: ORM.INTEGER,
autoIncrement: true,
primaryKey: true
},
url: ORM.STRING,
description: ORM.STRING,
duration: ORM.STRING,
seqNo: ORM.INTEGER,
courseId: ORM.INTEGER,
pro: ORM.BOOLEAN,
tags: ORM.STRING,
gitHubUrl: ORM.STRING,
});
}
示例8: function
export default function (sequelize: Sequelize, DataTypes: DataTypes) {
let Player = sequelize.define('Player', {
login: {
type: DataTypes.STRING,
allowNull: false
},
nickname: {
type: DataTypes.STRING,
allowNull: false
},
level: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: 0
}
}, {
tableName: 'core__player',
charset: 'utf8'
});
return Player;
}
示例9: taskModel
private taskModel() {
const Task = this.sequelize.define<TaskInstance, TaskAttribute>('Task', {
name: {
type: this.sequelize.Sequelize.STRING,
allowNull: false,
validate: {
notEmpty: true,
},
},
data: {
type: this.sequelize.Sequelize.JSONB,
defaultValue: {},
},
interval: {
type: this.sequelize.Sequelize.INTEGER,
},
nextRunAt: {
type: this.sequelize.Sequelize.DATE,
},
startAt: {
type: this.sequelize.Sequelize.DATE,
},
endAt: {
type: this.sequelize.Sequelize.DATE,
},
concurrency: {
type: this.sequelize.Sequelize.INTEGER,
defaultValue: 1,
},
priority: {
type: this.sequelize.Sequelize.INTEGER,
defaultValue: 0,
},
timeout: {
type: this.sequelize.Sequelize.INTEGER,
defaultValue: (1000 * 60 * 10), // 10 minutes
},
failsCount: {
type: this.sequelize.Sequelize.INTEGER,
defaultValue: 0,
},
runAtTime: {
type: this.sequelize.Sequelize.TIME,
},
repeatOnError: {
type: this.sequelize.Sequelize.BOOLEAN,
defaultValue: false,
},
}, {
timestamps: true,
});
(Task as any).prototype.checkEmitter = function(this: TaskInstance) {
if (!this.emitter) {
this.emitter = new EventEmitter();
}
};
(Task as any).prototype.on = function(this: TaskInstance, ...args: any[]) {
this.checkEmitter();
(this.emitter.on as any)(...args);
};
(Task as any).prototype.removeListener = function(this: TaskInstance, ...args: any[]) {
this.checkEmitter();
(this.emitter.removeListener as any)(...args);
};
(Task as any).prototype.emit = function(this: TaskInstance, ...args: any[]) {
this.checkEmitter();
(this.emitter.emit as any)(...args);
};
(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,
});
};
return Task;
}