Created
July 24, 2015 09:23
-
-
Save loic-moriame/b321dcc38dba8a40a1f7 to your computer and use it in GitHub Desktop.
node.js + sequelize + sqlite
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
'use strict'; | |
var Sequelize = require('sequelize'); | |
var sequelize = new Sequelize('mainDB', null, null, { | |
dialect: "sqlite", | |
storage: './test.sqlite', | |
}); | |
sequelize | |
.authenticate() | |
.then(function(err) { | |
console.log('Connection has been established successfully.'); | |
}, function (err) { | |
console.log('Unable to connect to the database:', err); | |
}); | |
// MODELS | |
var User = sequelize.define('User', { | |
username: Sequelize.STRING, | |
password: Sequelize.STRING | |
}); | |
// SYNC SCHEMA | |
sequelize | |
.sync({ force: true }) | |
.then(function(err) { | |
console.log('It worked!'); | |
}, function (err) { | |
console.log('An error occurred while creating the table:', err); | |
}); |
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
{ | |
"main": "index.js", | |
"dependencies": { | |
"sequelize": "^3.4.1", | |
"sqlite3": "^3.0.9" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Honestly i can't believe am already falling in love with sequelize