AhmAch
AhmAch

Reputation: 107

loopback 4 discover models from database

i have a database ready using postgresgl and i am using loopback 4 as framework and i want to create automatically my models by reading them from the database. i created a connection between loopback and postgresql using a connector but couldn't import anything from the database. Every timme i create a table in the database i have to create it using lopback and i am wondering if there is a way to convert the database schema to generated models. this is what i have done so far :

{
  "name": "testtest",
  "connector": "postgresql",
  "url": "postgres://postgres:root@localhost:5432/testtest",
  "host": "localhost",
  "port": 5432,
  "user": "postgres",
  "password": "root",
  "database": "testtest"
}

Upvotes: 2

Views: 2180

Answers (2)

B.Habibzadeh
B.Habibzadeh

Reputation: 538

just use database name after --schema key like this

lb4 discover --schema [DB_NAME_HERE]

Upvotes: 1

Miroslav Bajtoš
Miroslav Bajtoš

Reputation: 10795

Model discovery is a feature that's under active development right now, see the pull request https://github.com/strongloop/loopback-next/pull/2245

You can check out the development version and let us know how it works for you.

Cross-posting the instructions from https://github.com/strongloop/loopback-next/pull/2245#issuecomment-468863700:

# Clone the repo and install the dev version of `lb4` CLI
git clone -b pr-model-discovery --single-branch https://github.com/marvinirwin/loopback-next;
cd loopback-next/packages/cli;
npm install && npm run build && npm run link;

# Switch to your project
cd `LOOPBACK_4_PROJECT`;
npm run build;
# Run model discovery
lb4 discover;

Upvotes: 2

Related Questions