// Security note: the database is saved to the file `database.sqlite` on the local filesystem. It's deliberately placed in the `.data` directory
// which doesn't get copied if someone remixes the project.
storage:'.data/database.sqlite'
});
varReadings;
// authenticate with the database
sequelize.authenticate()
.then(function(err){
console.log('Connection has been established successfully.');
// define a new table 'readings'
Readings=sequelize.define('readings',{
timestamp:{
type:Sequelize.DATE
},
reading:{
type:Sequelize.INTEGER
}
});
setup();
})
.catch(function(err){
console.log('Unable to connect to the database: ',err);
});
// populate table with default users
functionsetup(){
Readings.sync({force:true}).then(function(){
console.log(Readings);
});
User.sync({force:true})// We use 'force: true' in this example to drop the table users if it already exists, and create a new one. You'll most likely want to remove this setting in your own apps
.then(function(){
// Add the default users to the database
for(vari=0;i<users.length;i++){// loop through all users
User.create({firstName:users[i][0],lastName:users[i][1]});// create a new entry in the users table