Created
July 25, 2019 10:51
-
-
Save tuor4eg/dc09f0f5b00edd03744cd33c45bba2c7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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