-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(docs): update docs with datasource cli and booter content
Signed-off-by: Taranveer Virk <[email protected]>
- Loading branch information
Showing
9 changed files
with
178 additions
and
45 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
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,55 @@ | ||
--- | ||
lang: en | ||
title: 'DataSource generator' | ||
keywords: LoopBack 4.0, LoopBack 4 | ||
tags: | ||
sidebar: lb4_sidebar | ||
permalink: /doc/en/lb4/DataSource-generator.html | ||
summary: | ||
--- | ||
|
||
{% include content/generator-create-app.html lang=page.lang %} | ||
|
||
### Synopsis | ||
|
||
Adds new [DataSource] class and config files to a LoopBack application. | ||
|
||
```sh | ||
lb4 datasource [options] [<name>] | ||
``` | ||
|
||
### Options | ||
|
||
`--connector` : Name of datasource connector | ||
|
||
This can be a connector supported by LoopBack / Community / Custom. | ||
|
||
{% include_relative includes/CLI-std-options.md %} | ||
|
||
### Arguments | ||
|
||
`<name>` - Required name of the datasource to create as an argiment to the command. If provided, the tool will use that as the default when it prompts for the name. | ||
|
||
### Interactive Prompts | ||
|
||
The tool will prompt you for: | ||
|
||
- **Name of the datasource.** If the name had been supplied from the command line, | ||
the prompt is skipped and the datasource is built with the name from the | ||
command-line argument. | ||
- **Name of connector.** If not supplied via command line, you will be presented | ||
with a list of connector to select from (including an `other` option for | ||
custom connector). | ||
- **Connector configuration.** If the connector is not a custom connector, the | ||
CLI will prompt for the connector configuration information. | ||
|
||
### Output | ||
|
||
Once all the prompts have been answered, the CLI will do the following: | ||
- Install `@loopback/repository` and the connector package (if it's not a custom | ||
connector). | ||
- Create a file with the connector configuration as follows: | ||
`/datasources/${connector.name}.datasource.json` | ||
- Create a DataSource class which recieves the connector config using [Dependency Injection](Dependency-injection.html) as follows: | ||
`/datasources/${connector.name}.datasource.ts` | ||
- Update `index.ts` to export the newly created DataSource class. |
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,41 @@ | ||
--- | ||
lang: en | ||
title: 'DataSources' | ||
keywords: LoopBack 4.0, LoopBack 4 | ||
tags: | ||
sidebar: lb4_sidebar | ||
permalink: /doc/en/lb4/DataSources.html | ||
summary: | ||
--- | ||
|
||
## Overview | ||
|
||
A `DataSource` in LoopBack 4 is a named configuration for a Connector instance | ||
that represents data in an external system. The Connector is used by | ||
`legacy-juggler-bridge` to power LoopBack 4 Repositories for Data operations. | ||
|
||
### Creating a DataSource | ||
|
||
It is recommended to use the `lb4 datasource` [command](DataSource-generator.html) | ||
provided by the CLI to generate a DataSource. The CLI will prompt for all necessary connector information and create the following files: | ||
|
||
- `${connector.name}.datasource.json` containing the connector configuration | ||
- `${connector.name}.datasource.ts` containing a class extending `juggler.DataSource`. This class can be used to override the default DataSource | ||
behaviour programaticaly. Note: The connector configuration stored in the `.json` | ||
file is injected into this class using [Dependency Injection](Dependency-inecjtion.html). | ||
|
||
Both the above files are generated in `src/datasources/` directory by the CLI. It | ||
will also update `src/datasources/index.ts` to export the new DataSource class. | ||
|
||
Example DataSource Class: | ||
|
||
```ts | ||
import {inject} from '@loopback/core'; | ||
import {juggler, DataSource} from '@loopback/repository'; | ||
|
||
export class DbDataSource extends juggler.DataSource { | ||
constructor(@inject('datasources.config.db') dsConfig: DataSource) { | ||
super(dsConfig); | ||
} | ||
} | ||
``` |
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
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