回送4从数据库中发现模型

时间:2019-03-22 16:58:17

标签: node.js database postgresql model loopback

我已经准备好使用postgresgl建立数据库,并且我使用回送4作为框架,并且我想通过从数据库中读取模型来自动创建模型。 我使用连接器在回送和postgresql之间创建了连接,但无法从数据库导入任何内容。我在数据库中创建一个表的每个时机都必须使用lopback来创建表,我想知道是否有一种方法可以将数据库模式转换为生成的模型。 这是我到目前为止所做的:

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

2 个答案:

答案 0 :(得分:1)

模型发现是一项正在积极开发中的功能,请参见拉取请求https://github.com/strongloop/loopback-next/pull/2245

您可以签出开发版本,并让我们知道它如何为您工作。

交叉发布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;

答案 1 :(得分:0)

只需在--schema键之后使用数据库名称

lb4 discover --schema [DB_NAME_HERE]