Use the model of sequelize

/ * Jshint indent: 2 * / 
the let the MD5 = the require ( 'Crypto') createHash ( 'MD5'. ); 
Module.exports = function (sequelize, the DataTypes) {
   return sequelize.define ( 'the Account' , { 
    ID: { 
      type : DataTypes.INTEGER ( . 11 ), 
      the allowNull: to false , 
      primaryKey: to true , 
      autoIncrement: to true 
    }, 
    name: { 
      type: DataTypes.STRING ( 255 ), 
      the allowNull: to true ,
       // from the database query to the data, to the following processing after user
      GET () {
         return "Dear" + the this .getDataValue ( 'name' ); 
      } 
    }, 
    Age: { 
      type: DataTypes.INTEGER ( . 11 ), 
      the allowNull: to true , 

      // data verification returns a checksum custom exception customFunc 
      the validate: { 
        max: { 
          args: 100 , 
          MSG: "Age IS larger" 
        }, 
        min: { 
          args: . 1, 
          MSG: 'Small Age IS' 
        }, 
        customFunc (Val) { 
          IF (Val 50 === ) {
            the console.log ( 'dddd' );
             the throw  new new ( 'Only the even values are allowed!' Error ) 
          } 
        } 

      } 
    }, 
    the passwd: { 
      type: DataTypes.STRING ( 255 ), 
      : the allowNull to true ,
       // when inserting or modified , and then written to the database by the treatment 
      SET (Val) { 
        Val = MD5.update (Val) .digest ( 'hex' );
         the this .setDataValue ( "the passwd" , Val); 
      } 

    } 
  }, { 
    tableName: 'Account ' , 

    //setterMethods, getterMethods This is comparable to the access are added in a virtual field changeName 
    setterMethods: { 
      changeName (Val) { 
        return  the this .setDataValue ( 'name', val.slice (0, -1 )); 
      } 
    }, 
    getterMethods : { 
      the changeName () { 
        return  the this .name + 'the changeName' ; 
      } 
    } 
  }); 
};

Guess you like

Origin www.cnblogs.com/tinghaiku/p/12074618.html