Skip to content

Commit

Permalink
feat(instructions): add instructions file
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Aug 1, 2017
1 parent 0671c56 commit a1086d9
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 0 deletions.
20 changes: 20 additions & 0 deletions instructions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'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')

module.exports = async function (cli) {
try {
await cli.makeConfig('database.js', path.join(__dirname, './templates/config.mustache'))
} catch (error) {
// ignore errors
}
}
35 changes: 35 additions & 0 deletions instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
## Registering provider

Make sure to register the lucid provider to make use of `Database` and `Lucid` models. The providers are registered inside `start/app.js`

```js
const providers = [
'@adonisjs/lucid/providers/LucidProvider'
]
```


## Usage

Once done you can access `Database` provider and run mysql queries as follows.

```js
const Database = use('Database')

await Database.table('users').select('*')
await Database.table('users').paginate()
```

## Migrations Provider

This repo also comes with a migrations and seeds provider to run to migrate your database using incremental migrations.

Make sure to register migrations provider under `aceProviders` array.

```js
const aceProviders = [
'@adonisjs/lucid/providers/MigrationsProvider'
]
```

After this running `adonis --help` will list a set of commands under `migration` namespace.
78 changes: 78 additions & 0 deletions templates/config.mustache
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', 'sqlite'),
/*
|--------------------------------------------------------------------------
| 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')
}
}
}

0 comments on commit a1086d9

Please sign in to comment.