本文整理匯總了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;
}