configure db
This commit is contained in:
		
							parent
							
								
									1e6c35151f
								
							
						
					
					
						commit
						e41de293d4
					
				
							
								
								
									
										34
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										34
									
								
								README.md
									
									
									
									
									
								
							@ -47,10 +47,38 @@ function approveDomains() {
 | 
				
			|||||||
// TODO
 | 
					// TODO
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Set Options
 | 
					## Sequelize Options
 | 
				
			||||||
 | 
					
 | 
				
			||||||
You can send in options that set which database connector to use, as well as a
 | 
					Without `config.dbOptions`, the baked-in sequelize object uses sqlite3 with
 | 
				
			||||||
table prefix.
 | 
					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
 | 
					## Provide Your Own Database Object
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -20,15 +20,14 @@ module.exports = function (config) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  if (config.use_env_variable) {
 | 
					  if (config.use_env_variable) {
 | 
				
			||||||
    db.sequelize = new db.Sequelize(process.env[config.use_env_variable], config);
 | 
					    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);
 | 
					    db.sequelize = new db.Sequelize(config.database, config.username, config.password, config);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  fs.readdirSync(__dirname)
 | 
					  fs.readdirSync(__dirname).filter(function (file) {
 | 
				
			||||||
    .filter(function (file) {
 | 
					 | 
				
			||||||
    return ('.' !== file[0]) && (file !== basename) && (file.slice(-3) === '.js');
 | 
					    return ('.' !== file[0]) && (file !== basename) && (file.slice(-3) === '.js');
 | 
				
			||||||
    })
 | 
					  }).forEach(function (file) {
 | 
				
			||||||
    .forEach(function (file) {
 | 
					 | 
				
			||||||
    var model = db.sequelize['import'](path.join(__dirname, file));
 | 
					    var model = db.sequelize['import'](path.join(__dirname, file));
 | 
				
			||||||
    db[model.name] = model;
 | 
					    db[model.name] = model;
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user