diff --git a/README.md b/README.md index ae6fc00..3dac3e1 100644 --- a/README.md +++ b/README.md @@ -47,10 +47,38 @@ function approveDomains() { // TODO ``` -## Set Options +## Sequelize Options -You can send in options that set which database connector to use, as well as a -table prefix. +Without `config.dbOptions`, the baked-in sequelize object uses sqlite3 with +default options. If `config.dbOptions` is provided, you can configure the +database connection per the Sequelize documentation. + +```javascript +var store = require('le-store-sequelize')({ + dbConfig: { + username: 'mysqluser', + password: 'mysqlpassword', + database: 'mysqldatabase, + host: '127.0.0.1', + dialect: 'mysql' + } +}); + +greenlock.create({ + store + ... +}); +``` + +The database can also be configured using an env variable. + +```javascript +var store = require('le-store-sequelize')({ + dbConfig: { + use_env_variable: 'DB_URL' + } +}); +``` ## Provide Your Own Database Object diff --git a/db/index.js b/db/index.js index 0753f39..89495db 100644 --- a/db/index.js +++ b/db/index.js @@ -20,18 +20,17 @@ module.exports = function (config) { if (config.use_env_variable) { db.sequelize = new db.Sequelize(process.env[config.use_env_variable], config); - } else { + } + else { db.sequelize = new db.Sequelize(config.database, config.username, config.password, config); } - fs.readdirSync(__dirname) - .filter(function (file) { - return ('.' !== file[0]) && (file !== basename) && (file.slice(-3) === '.js'); - }) - .forEach(function (file) { - var model = db.sequelize['import'](path.join(__dirname, file)); - db[model.name] = model; - }); + fs.readdirSync(__dirname).filter(function (file) { + return ('.' !== file[0]) && (file !== basename) && (file.slice(-3) === '.js'); + }).forEach(function (file) { + var model = db.sequelize['import'](path.join(__dirname, file)); + db[model.name] = model; + }); Object.keys(db).forEach(function (modelName) { if (db[modelName].associate) {