Important:Before running this generator, you must create an application using the application generator.Then you must run the command from the root directory of the application.
Synopsis
Adds a new DataSource class and config files to a LoopBackapplication.
lb4 datasource [options] [<name>]
Options
—connector
: Name of datasource connector
This can be a connector supported by LoopBack / Community / Custom.Standard options
-h, —help
- Print the generator’s options and usage.
—skip-cache
- Do not remember prompt answers. Default is false.
—skip-install
- Do not automatically install dependencies. Default is false.
-c, —config
- JSON file name or value to configure options
—format
- Format generated code using
npm run lint:fix
For example,
lb4 app --config config.json
lb4 app --config '{"name":"my-app"}'
cat config.json | lb4 app --config stdin
lb4 app --config stdin < config.json
lb4 app --config stdin << EOF
> {"name":"my-app"}
> EOF
-y, —yes
- Skip all confirmation prompts with default or provided value
Arguments
<name>
- Required name of the datasource to create as an argument to thecommand. If provided, the tool will use that as the default when it prompts forthe name.
Interactive Prompts
The tool will prompt you for:
- Name of the datasource.(dataSourceName) If the name had been suppliedfrom the command line, the prompt is skipped and the datasource is built withthe name from the command-line argument.
- Name of connector. If not supplied via command line, you will be presentedwith a list of connector to select from (including an
other
option forcustom connector). - Connector configuration. If the connector is not a custom connector, theCLI 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 customconnector). - Create a file with the connector configuration as follows:
/src/datasources/${dataSource.dataSourceName}.datasource.json
- Create a DataSource class which recieves the connector config usingDependency Injection as follows:
/src/datasources/${dataSource.dataSourceName}.datasource.ts
- Update
/src/datasources/index.ts
to export the newly created DataSourceclass.