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

From datasource config to DataSource instance with no custom classes #2557

Closed
4 tasks
bajtos opened this issue Mar 8, 2019 · 3 comments
Closed
4 tasks

From datasource config to DataSource instance with no custom classes #2557

bajtos opened this issue Mar 8, 2019 · 3 comments

Comments

@bajtos
Copy link
Member

bajtos commented Mar 8, 2019

In LoopBack 3, it is very easy to configure datasources with no code: just create a new entry in server/datasources.json and the bootstrapper + the runtime will automatically parse the configuration, replace placeholders like ${MYSQL_URL} with values from the environment variables and finally create & register a datasource instance.

Let's implement similar functionality in LB4 too.

// src/datasources/db.json
{
  "name": "db",
  "connector": "mysql",
  "url": "${ENV.MYSQL_URL}"
  "database": "dbname-used-at-dev-time"
}

Note: having config for multiple datasources in a single JSON file can become a maintenance nightmare in larger applications, see strongloop/loopback#1316. It's better to have one config file per datasource, as we already do in TypeScript-based LB4 apps.

Acceptance criteria

  • JS & TS API for declarative registration of datasources.

    We need to revisit app.dataSource API (IIRC, it's contributed by @loopback/repository) and ensure that it supports declarative usage from both TypeScript and JavaScript.

    app.dataSource('datasource-name', {
      // configuration object
      // no variable substitution is performed!
      connector: 'mysql',
      url: process.env.MYSQL_URL,
      database: 'dbname-used-at-dev-time'
    });
  • Support in @loopback/boot.

    Modify datasource booter to support the case where there is only datasource JSON file without any accompanying TS/JS file that would define a custom DataSource class.

  • Documentation

  • Blog post

Out of scope

@bajtos
Copy link
Member Author

bajtos commented May 10, 2019

Let's put this on hold for now, I would like to rethink the way how datasources are configured. I think the JSON-based config is not optimal for Cloud Native environments, where most configuration is handled by environmental variables (see https://12factor.net/).

@bajtos bajtos added 2019Q3 and removed 2019Q2 labels May 10, 2019
@dhmlau dhmlau added 2019Q4 and removed 2019Q3 labels Jun 25, 2019
@dhmlau dhmlau removed the 2019Q4 label Oct 8, 2019
@stale
Copy link

stale bot commented Oct 4, 2020

This issue has been marked stale because it has not seen activity within six months. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository. This issue will be closed within 30 days of being stale.

@stale stale bot added the stale label Oct 4, 2020
@stale
Copy link

stale bot commented Dec 25, 2020

This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository.

@stale stale bot closed this as completed Dec 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants