Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @desc setup database
- */
- const setupDB = (conf) => {
- const sequelize = new Sequelize(conf.database, conf.username, conf.password, {
- host: connectOptions.host,
- dialect: connectOptions.dialect,
- pool: connectOptions.pool
- });
- sequelize.authenticate()
- .then(() => console.log('Connected to database'))
- .catch((err) => console.error(err));
- return sequelize;
- };
- const UserModel = {
- _conn: null,
- _table: null,
- load(conn) {
- UserModel._conn = conn;
- UserModel._table = conn.define('users', {
- id: {
- type: Sequelize.UUID,
- primaryKey: true,
- defaultValue: SEQUELIZE.UUIDV4
- },
- username: Sequelize.STRING,
- password: Sequelize.STRING
- });
- }
- };
- const BaseObject = (name, x, y) => {
- return { name, x, y };
- };
- const Car = (speed, x, y) => {
- let _currentSpeed = 0;
- let _directionX = 0,
- // concatenative inheritance
- return Object.assign(BaseObject('car', x, y), {
- speed,
- accelerate() {
- _currentSpeed += 10;
- },
- brake() {
- _currentSpeed -= 10;
- },
- turnLeft() {
- _directionX += -0.2;
- },
- turnRight() {
- _directionX -= 0.2;
- },
- });
- };
- const car = Car(20, 5, 5),
- const action = compose(car.accelerate, car.turnLeft, car.turnLeft, car.turnRight, car.brake);
- const promise = UserModel.find({
- where: {
- name: 'Jean BON'
- }
- });
- promise.then((user) => console.log(user.username))
- .catch((err) => console.error(err));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement