Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
197 additions
and
8 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
'use strict' | ||
|
||
/* | ||
* adonis-lucid | ||
* | ||
* (c) Harminder Virk <virk@adonisjs.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
const path = require('path') | ||
const { Command } = require('@adonisjs/ace') | ||
|
||
class MakeConfig extends Command { | ||
constructor (Helpers) { | ||
super() | ||
this.Helpers = Helpers | ||
} | ||
|
||
/** | ||
* Ioc container injections | ||
* | ||
* @method inject | ||
* | ||
* @return {Array} | ||
*/ | ||
static get inject () { | ||
return ['Adonis/Src/Helpers'] | ||
} | ||
|
||
/** | ||
* Command signature required by ace | ||
* | ||
* @method signature | ||
* | ||
* @return {String} | ||
*/ | ||
static get signature () { | ||
return ` | ||
config:database | ||
{ -c, --connection=@value: The database connection to use } | ||
{ -e, --echo=@value: Write config to console } | ||
` | ||
} | ||
|
||
/** | ||
* Command description | ||
* | ||
* @method description | ||
* | ||
* @return {String} | ||
*/ | ||
static get description () { | ||
return 'Setup configuration for database provider' | ||
} | ||
|
||
async handle (args, { connection, echo }) { | ||
connection = connection || 'sqlite' | ||
const template = await this.readFile(path.join(__dirname, './templates/config.mustache'), 'utf-8') | ||
|
||
/** | ||
* Echo template over creating the config file | ||
*/ | ||
if (echo) { | ||
return this.viaAce ? console.log(template) : 'echoed' | ||
} | ||
|
||
/** | ||
* Create config file | ||
*/ | ||
const configPath = `${path.join(this.Helpers.configPath(), 'database.js')}` | ||
await this.generateFile(configPath, template, { connection }) | ||
|
||
if (!this.viaAce) { | ||
return configPath | ||
} | ||
this.completed('created', configPath.replace(this.Helpers.appRoot(), '').replace(path.sep, '')) | ||
} | ||
} | ||
|
||
module.exports = MakeConfig |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
'use strict' | ||
|
||
const Env = use('Env') | ||
const Helpers = use('Helpers') | ||
|
||
module.exports = { | ||
/* | ||
|-------------------------------------------------------------------------- | ||
| Default Connection | ||
|-------------------------------------------------------------------------- | ||
| | ||
| Connection defines the default connection settings to be used while | ||
| interacting with SQL databases. | ||
| | ||
*/ | ||
connection: Env.get('DB_CONNECTION', '{{ connection }}'), | ||
/* | ||
|-------------------------------------------------------------------------- | ||
| Sqlite | ||
|-------------------------------------------------------------------------- | ||
| | ||
| Sqlite is a flat file database and can be good choice under development | ||
| environment. | ||
| | ||
| npm i --save sqlite3 | ||
| | ||
*/ | ||
sqlite: { | ||
client: 'sqlite3', | ||
connection: { | ||
filename: Helpers.databasePath('development.sqlite') | ||
}, | ||
useNullAsDefault: true | ||
}, | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| MySQL | ||
|-------------------------------------------------------------------------- | ||
| | ||
| Here we define connection settings for MySQL database. | ||
| | ||
| npm i --save mysql | ||
| | ||
*/ | ||
mysql: { | ||
client: 'mysql', | ||
connection: { | ||
host: Env.get('DB_HOST', 'localhost'), | ||
port: Env.get('DB_PORT', ''), | ||
user: Env.get('DB_USER', 'root'), | ||
password: Env.get('DB_PASSWORD', ''), | ||
database: Env.get('DB_DATABASE', 'adonis') | ||
} | ||
}, | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| PostgreSQL | ||
|-------------------------------------------------------------------------- | ||
| | ||
| Here we define connection settings for PostgreSQL database. | ||
| | ||
| npm i --save pg | ||
| | ||
*/ | ||
pg: { | ||
client: 'pg', | ||
connection: { | ||
host: Env.get('DB_HOST', 'localhost'), | ||
port: Env.get('DB_PORT', ''), | ||
user: Env.get('DB_USER', 'root'), | ||
password: Env.get('DB_PASSWORD', ''), | ||
database: Env.get('DB_DATABASE', 'adonis') | ||
} | ||
} | ||
} |
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
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
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