Advertisement
Guest User

Untitled

a guest
Jul 15th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. /**
  3.  * @desc setup database
  4.  */
  5. const setupDB = (conf) => {
  6.     const sequelize = new Sequelize(conf.database, conf.username, conf.password, {
  7.         host: connectOptions.host,
  8.         dialect: connectOptions.dialect,
  9.         pool: connectOptions.pool
  10.     });
  11.  
  12.     sequelize.authenticate()
  13.         .then(() => console.log('Connected to database'))
  14.         .catch((err) => console.error(err));
  15.     return sequelize;
  16. };
  17.  
  18. const UserModel = {
  19.     _conn: null,
  20.     _table: null,
  21.  
  22.     load(conn) {
  23.         UserModel._conn = conn;
  24.         UserModel._table = conn.define('users', {
  25.             id: {
  26.                 type: Sequelize.UUID,
  27.                 primaryKey: true,
  28.                 defaultValue: SEQUELIZE.UUIDV4
  29.             },
  30.             username: Sequelize.STRING,
  31.             password: Sequelize.STRING
  32.         });
  33.     }
  34. };
  35.  
  36. const BaseObject = (name, x, y) => {
  37.     return { name, x, y };
  38. };
  39.  
  40. const Car = (speed, x, y) => {
  41.     let _currentSpeed = 0;
  42.     let _directionX = 0,
  43.  
  44.     // concatenative inheritance
  45.    return Object.assign(BaseObject('car', x, y), {
  46.        speed,
  47.        accelerate() {
  48.            _currentSpeed += 10;
  49.        },
  50.        brake() {
  51.            _currentSpeed -= 10;
  52.        },
  53.        turnLeft() {
  54.            _directionX += -0.2;
  55.        },
  56.        turnRight() {
  57.            _directionX -= 0.2;
  58.        },
  59.    });
  60. };
  61.  
  62. const car = Car(20, 5, 5),
  63.  
  64. const action = compose(car.accelerate, car.turnLeft, car.turnLeft, car.turnRight, car.brake);
  65.  
  66. const promise = UserModel.find({
  67.     where: {
  68.         name: 'Jean BON'
  69.     }
  70. });
  71.  
  72. promise.then((user) => console.log(user.username))
  73.        .catch((err) => console.error(err));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement