【问题标题】:Complex Seed generator for NodeJSNodeJS 的复杂种子生成器
【发布时间】:2019-11-13 07:19:19
【问题描述】:

有人知道可以为相关实体生成种子的种子生成器吗?

让我们以博客为例。我想按以下顺序创建种子

  • 作者
  • 文章(基于之前创建的作者种子)

我显然可以自己写这个。但想知道是否没有一个通用包已经这样做了。

【问题讨论】:

    标签: node.js seed seeding


    【解决方案1】:

    例如,您可以使用 faker.js。查看文档here

    console.log(faker.fake("{{name.lastName}}, {{name.firstName} {{name.suffix}}"));
    // outputs: "Marks, Dean Sr."
    

    我认为您可以在文档中找到适合文章名称的名称(company.companyName 或 commerce.productName)

    【讨论】:

      【解决方案2】:

      我最初问这个问题是因为我打算为这种需要编写一个包。我想确保这样的东西不存在。

      The package can be found here

      示例使用

         // create new seeder
        const seeder = new Seeder();
        // add a seed job
        seeder.addJob('users', userGenerator, userSource, {count: 2})
          .addJob('articles', articleGenerator, articlSource, {count: 3})
          // seed top categories
          .addJob('categories', categoryGenerator, categorySource, {
            staticFieldData: [
              {
                name: 'Health',
                parentId: null
              },
              {
                name: 'Fashion',
                parentId: null
              }
            ]
          })
          // seed child categories (they would use the ID of already seeded top categories as parentId)
          // notice the addSeed here. addJob can be called only once per entity.
          .addSeed('categories', {count: 3});
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-10-08
        • 2012-09-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多