-
-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(instructions): add instructions file
- Loading branch information
1 parent
0671c56
commit a1086d9
Showing
3 changed files
with
133 additions
and
0 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
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 | ||
} | ||
} |
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,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. |
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', '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') | ||
} | ||
} | ||
} |