sequelize.define('timesheet_entry', { startDate: {type: Sequelize.DataTypes.DATE, allowNull: false}, endDate: {type: Sequelize.DataTypes.DATE, allowNull: false}, overtime: {type: Sequelize.DataTypes.INTEGER, defaultValue: 0}, jobTitle: {type: Sequelize.DataTypes.STRING, allowNull: false}, comments: {type: Sequelize.DataTypes.TEXT('long'), allowNull: false} }, { hooks: { beforeSave: (timesheetEntry, options) => { } } })
const ChannelMemberFactory = ( sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes ): Sequelize.Model<ChannelMemberInstance, ChannelMemberAttributes> => { const attributes: SequelizeAttributes<ChannelMemberAttributes> = { id: { type: DataTypes.STRING, defaultValue: getNewId, primaryKey: true } }; const ChannelMember = sequelize.define< ChannelMemberInstance, ChannelMemberAttributes >("channel_member", attributes); return ChannelMember; }
async function defineModel({keys, columns = ["email", "secret"], encryption = "aes-128-cbc", keyringIdColumn = "keyring_id", digestSalt = ""}) { const model = await sequelize.define("users", { id: { type: Sequelize.UUIDV4, primaryKey: true, allowNull: false, defaultValue: Sequelize.UUIDV4 }, encrypted_email: Sequelize.TEXT, email_digest: Sequelize.TEXT, email: Sequelize.VIRTUAL, encrypted_secret: Sequelize.TEXT, secret: Sequelize.VIRTUAL, keyring_id: Sequelize.INTEGER, custom_keyring_id: Sequelize.INTEGER }, {timestamps: false}); Keyring(model, {keys, columns, encryption, keyringIdColumn, digestSalt}); return model; }
async init() { if (Database.created) { return; } const UserGroup = sequelize.define("UserGroup", { warnsNumber: { type: Sequelize.INTEGER.UNSIGNED, defaultValue: 0 } }); User.belongsToMany(Group, { through: UserGroup }); Group.belongsToMany(User, { through: UserGroup }); Spam.belongsToMany(Group, { through: "SpamGroup" }); Group.belongsToMany(Spam, { through: "SpamGroup" }); Rule.belongsToMany(Group, { through: "GroupRule" }); Group.belongsToMany(Rule, { through: "GroupRule" }); Group.hasMany(ClearPeriod); await sequelize.sync(); _created = true; }
const getDB = async () => { const Op = SQL.Op; const operatorsAliases = { $in: Op.in, }; const db = new SQL('', '', '', { dialect: 'sqlite', storage: './db.sqlite', operatorsAliases, logging: false, }); const users = db.define('user', { id: { type: SQL.INTEGER, primaryKey: true, autoIncrement: true, }, name: SQL.STRING, createdAt: SQL.DATE, updatedAt: SQL.DATE, }); return { users }; }
async function createModelAsync (modelConfig, models, globals) { // initialize models const sequelize = new Sequelize(modelConfig.database, modelConfig.username, modelConfig.password, { host: modelConfig.host, dialect: modelConfig.dialect, pool: modelConfig.pool, timezone: modelConfig.timezone, define: { timestamps: false, freezeTableName: true }, logging: false }) _.forEach(models, (model, modelName) => { if (Array.isArray(model)) { model.unshift(modelName) } else { model = [modelName, model] } sequelize.define.apply(sequelize, model) }) globals.models = sequelize.models globals.query = sequelize.query.bind(sequelize) globals.transaction = sequelize.transaction.bind(sequelize) return globals }
sequelize.define('recipe', { name: { type: Sequelize.STRING(30) } }, { freezeTableName: true, paranoid: false, timestamps: false, classMethods: { findById: function(recipeId) { return Recipe.findOne({ where: { id: recipeId } }); } } })
router.post('/', function (req, res, next) { var report = sequelize.define('rdm_report', { reportId: Sequelize.STRING, formType: Sequelize.STRING, reportName: Sequelize.STRING, reportStatistics: Sequelize.STRING, reportStatisticsType: Sequelize.STRING, reportSecond: Sequelize.STRING, reportEnd: Sequelize.STRING, reportSort: Sequelize.STRING }); sequelize.sync().then(function () { return report.create({ reportId: req.body.reportId, formType: req.body.formType, reportName: req.body.reportName, reportStatistics: req.body.reportStatistics, reportStatisticsType: req.body.reportStatisticsType, reportSecond: req.body.reportSecond, reportEnd: req.body.reportEnd, reportSort: req.body.reportSort, }); }).then(function (jane) { console.log(jane.get({ plain: true })); // 跳转到首页 res.redirect('/reportRoutes'); }); });
return sequelize.define(name, attrs, options);
const TeamMemberFactory = ( sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes ): Sequelize.Model<TeamMemberInstance, TeamMemberAttributes> => { const attributes: SequelizeAttributes<TeamMemberAttributes> = { id: { type: DataTypes.STRING, defaultValue: getNewId, primaryKey: true }, admin: { type: DataTypes.BOOLEAN, defaultValue: false } }; const TeamMember = sequelize.define<TeamMemberInstance, TeamMemberAttributes>( "team_member", attributes ); return TeamMember; }
sequelize.define('user_account', { username: {type: Sequelize.DataTypes.STRING, allowNull: false, unique: true}, password: {type: Sequelize.DataTypes.STRING, allowNull: false}, emailAddress: {type: Sequelize.DataTypes.STRING, allowNull: false, validate: {isEmail: true}}, enabled: {type: Sequelize.DataTypes.BOOLEAN, allowNull: false, defaultValue: true}, authToken: {type: Sequelize.DataTypes.STRING, unique: true}, streetAddress: {type: Sequelize.DataTypes.STRING(200), allowNull: false}, phoneNumber: {type: Sequelize.DataTypes.STRING(12)} }, { hooks: { beforeCreate: async (userAccount, options) => { return userAccount.password = await ValidationHelpers.generatePasswordHash(userAccount.password); } } })
sequelize.define('user', { id: { type: Sequelize.BIGINT,
const Team = sequelize.define<TeamInstance, TeamAttributes>( "team", attributes
const Message = sequelize.define<MessageInstance, MessageAttributes>( "message", attributes
datasource.define('user', { email: { type: Sequelize.STRING, unique: true, validate: { isEmail: { msg: 'Not a valid email' } } }, password: { type: Sequelize.STRING, allowNull: false, validate: { isString: function (value) { if (!(typeof value === 'string' || value instanceof String)) { throw new Error('Password must be a string') } } } }, firstName: { type: Sequelize.STRING }, lastName: { type: Sequelize.STRING } })