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

bajtos opened this Issue Mar 8, 2019 · 0 comments


None yet
2 participants
Copy link

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

  • Variable substitution at boot time - see #2556
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.