configure db

This commit is contained in:
Ryan Burnette 2019-04-10 14:11:38 +00:00
parent 1e6c35151f
commit e41de293d4
2 changed files with 39 additions and 12 deletions

View File

@ -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

View File

@ -20,15 +20,14 @@ 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) {
fs.readdirSync(__dirname).filter(function (file) {
return ('.' !== file[0]) && (file !== basename) && (file.slice(-3) === '.js');
})
.forEach(function (file) {
}).forEach(function (file) {
var model = db.sequelize['import'](path.join(__dirname, file));
db[model.name] = model;
});