Last active
December 9, 2016 01:00
-
-
Save bitgord/bbc50d8ce317c185894072e60e46bbdd to your computer and use it in GitHub Desktop.
Quick Setup of 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
// First you need to install the dependencies - insert this to your package.json and run npm install | |
"sequelize": "^3.5.1", | |
"sqlite3": "^3.1.4" | |
// Require Sequelize | |
// (new Sequelize dependencies can be (undefined, undefined, undefined) for quick setup | |
// set dialect to a 'sqlite' db | |
// set storage to the file you want the db to be with a .sqlite at the end | |
var Sequelize = require('Sequelize'); | |
var sequelize = new Sequelize(database, username, password, { | |
'dialect': 'sqlite', | |
'storage': __dirname + '/[[add-file-name]].sqlite' | |
}); | |
// Create model that will be stored in database | |
var Item = sequelize.define('item', { | |
string: { | |
type: Sequelize.STRING | |
}, | |
boolean: { | |
type: Sequelize.BOOLEAN | |
} | |
}) | |
// Check that sequelize has synced | |
sequelize.sync().then(function () { | |
console.log('Everything is synced'); | |
// Push a new item to the db and check that it logs the item to the console | |
item.create({ | |
"string": "", | |
"boolean": true | |
}).then(function (item) { | |
console.log('Finished'); | |
console.log(item); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment