Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CLI] Generate DataSource #1225

Closed
4 tasks
dhmlau opened this issue Apr 3, 2018 · 6 comments · Fixed by #1385
Closed
4 tasks

[CLI] Generate DataSource #1225

dhmlau opened this issue Apr 3, 2018 · 6 comments · Fixed by #1385
Assignees

Comments

@dhmlau
Copy link
Member

dhmlau commented Apr 3, 2018

Description / Feature proposal

CLI command to generate datasource. It generates either:

  • datasource.ts, or;
  • datasource.json with DataSource class that reads datasource.json

Sample for the first approach:

Sample for the latter approach:

User Experience

$lb datasource
? Enter the datasource name: testds
? Select the connector for testds: (selection of connectors) PostgreSQL (supported by StrongLoop)
? Connection String url to override other settings (eg: postgres://username:password@localhost/database): postgres://username:password@localhost/database
? host: localhost
? port: 5432
? user: username
? password: ****
? database: testdb
? Install loopback-connector-postgresql@^2.4 No

As a result, src/datasources/testds.datasource.ts will be generated.

Outstanding questions

  • What should we be generating? just the datasource.ts? or similar to what we have in example-todo?
  • For the list of connectors for selection, do we want to have the same list as in LB3?

Acceptance Criteria

  • Create lb4 datasource -- works like LB3 CLI with the following changes:
    • Each datasource config is stored in it's own .json file
    • An accompanying .ts file is created which injects the datasource config
  • Tests as usual
  • Not related but relevant: @loopback/boot will bind JSON config files to Context
    • Must provide a way to override from env ...
@dhmlau
Copy link
Member Author

dhmlau commented Apr 20, 2018

Things to consider:

  1. CLI to generate the datasource
  2. bootstrap any LB3 datasources.json and model definition.

@bajtos
Copy link
Member

bajtos commented Apr 24, 2018

What should we be generating? just the datasource.ts? or similar to what we have in example-todo?

IMO, we should also register the newly created datasource with the application, see e.g. https://github.com/strongloop/loopback-next/blob/c92603157ca7f08cf3748ca6bbd1e68da87d821e/examples/todo/src/application.ts#L48-L56

Simplified version that's probably good enough for DP3:

import {db} from './db.datasource.ts';
// ...
app.dataSource(db);

Ideally, this registration should provided by @loopback/boot, but I think we are not there yet. I guess we should create a new story to allow @loopback/boot to discover and register datasources and implement that story first, before working on this one.

For the list of connectors for selection, do we want to have the same list as in LB3?

Yes, let's start with the same list.

@bajtos bajtos removed their assignment Apr 24, 2018
@jannyHou
Copy link
Contributor

Ideally, this registration should provided by @loopback/boot

@bajtos see #1261, I think @virkt25 is already doing it :)

@dhmlau
Copy link
Member Author

dhmlau commented Apr 27, 2018

related to #441

@dhmlau
Copy link
Member Author

dhmlau commented May 24, 2018

@virkt25 , assigning this to you because I think you're already doing most of it as part of the spike #441

@dhmlau
Copy link
Member Author

dhmlau commented May 24, 2018

@virkt25 , if it's good for estimate, please move to the needs estimate column. thanks.

@jannyHou jannyHou added this to the June Milestone milestone Jun 5, 2018
@bajtos bajtos added the p1 label Aug 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants