0

我想为@feathers/cli 编写一个自定义方法,用一些初始数据为数据库播种。有人可以指点我方便地扩展@feathers/cli的方向吗?基本上,该方法应该连接到羽毛应用程序并尝试通过service.create({data})调用将记录添加到模型中。

或者有没有更好的方法来为 Feathers 模型播种和验证数据?我使用 Feathers-mongoose 适配器。

4

1 回答 1

2

您可以通过要求您的app.js. 例如在seed.js

const app = require('../src/app');

(async () => {
  app.setup();
  // If you are using Sequelize:
  // await app.get('sequelizeSync');
  
  const user = await app.service('users').create({
    email: 'test@user.com',
    password: 'supersecret'
  });
  // Do other things here
})();

然后你可以运行它node seed

于 2021-07-01T21:48:40.890 回答