Skip to content

Instantly share code, notes, and snippets.

@tuor4eg
Created July 25, 2019 10:51
Show Gist options
  • Save tuor4eg/dc09f0f5b00edd03744cd33c45bba2c7 to your computer and use it in GitHub Desktop.
Save tuor4eg/dc09f0f5b00edd03744cd33c45bba2c7 to your computer and use it in GitHub Desktop.
const Sequelize = require('sequelize');
class Orm {
constructor(dbname, user, password, tables) {
this.dbname = dbname;
this.user = user;
this.password = password;
this.tables = tables;
this.sequelize = new Sequelize(this.dbname, this.user, this.password, {
host: 'localhost',
dialect: 'mysql',
dialectOptions: {
multipleStatements: true
},
logging: console.log,
});
}
async init() {
const tableNames = Object.keys(this.tables);
tableNames.map(table => this.sequelize.define(table, this.tables[table]));
await this.sequelize.sync();
}
async getMarks() {
const result = await this.sequelize.models.map_marks.findAll({
attributes: ['id', 'posX', 'posY'],
});
return result;
}
async getMark(id) {
const result = await this.sequelize.models.map_marks.findAll({
where: { id },
});
return result;
}
}
module.exports = Orm;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment