Skip to content

Instantly share code, notes, and snippets.

@bitgord
Last active December 9, 2016 01:00
Show Gist options
  • Save bitgord/bbc50d8ce317c185894072e60e46bbdd to your computer and use it in GitHub Desktop.
Save bitgord/bbc50d8ce317c185894072e60e46bbdd to your computer and use it in GitHub Desktop.
Quick Setup of SQLite
// 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