2020-04-13 15:49:56 +00:00
|
|
|
const Sequelize = require('sequelize')
|
2020-04-11 18:57:35 +00:00
|
|
|
const Op = Sequelize.Op
|
|
|
|
|
|
|
|
// Setup database, using credentials set in .env
|
|
|
|
const sequelize = new Sequelize('database', process.env.DB_USER, process.env.DB_PASS, {
|
|
|
|
dialect: 'sqlite',
|
2020-04-11 19:34:59 +00:00
|
|
|
logging: false,
|
2020-04-11 18:57:35 +00:00
|
|
|
storage: '.data/database.sqlite'
|
2020-04-13 15:49:56 +00:00
|
|
|
})
|
2020-04-11 18:57:35 +00:00
|
|
|
|
|
|
|
// Define 'readings' table structure
|
|
|
|
const Readings = sequelize.define('readings', {
|
|
|
|
timestamp: {
|
|
|
|
type: Sequelize.DATE
|
|
|
|
},
|
|
|
|
reading: {
|
|
|
|
type: Sequelize.INTEGER
|
|
|
|
}
|
2020-04-13 15:49:56 +00:00
|
|
|
})
|
2020-04-11 18:57:35 +00:00
|
|
|
|
2020-04-13 15:49:56 +00:00
|
|
|
// Define 'settings' table structure
|
|
|
|
const Settings = sequelize.define('settings', {
|
|
|
|
key: {
|
|
|
|
type: Sequelize.STRING,
|
|
|
|
unique: true
|
|
|
|
},
|
|
|
|
value: {
|
|
|
|
type: Sequelize.STRING
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
module.exports = {Op, Readings, Settings}
|