-
-
Save wgwz/999d97d923a78b99dbeb668a1df1a047 to your computer and use it in GitHub Desktop.
node.js + sequelize + sqlite
This file contains hidden or 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 hidden or 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