Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Redux 如何枚举给定关系模式的所有可能关联?_Redux_Foreign Keys_Schema_Code Generation_Entity Relationship - Fatal编程技术网

Redux 如何枚举给定关系模式的所有可能关联?

Redux 如何枚举给定关系模式的所有可能关联?,redux,foreign-keys,schema,code-generation,entity-relationship,Redux,Foreign Keys,Schema,Code Generation,Entity Relationship,一些背景 我正在开发一个数据密集型UI,其中状态存储在Redux容器中。任何接触过Redux的人都知道,有很多重复的样板文件需要以减缩器、动作、动作创建者、选择器(类似于查询)等形式编写 写这些并没有什么乐趣,尤其是当涉及到很多实体类型和伴随关系时 因此,我们的想法是设计一个关系模式和一个代码生成器,繁重的工作可以外包给它 问题 给定一个(假设的)关系模式,如下所示: const schema = { book: { attributes: ["id", "name", "subGe

一些背景

我正在开发一个数据密集型UI,其中状态存储在Redux容器中。任何接触过Redux的人都知道,有很多重复的样板文件需要以减缩器、动作、动作创建者、选择器(类似于查询)等形式编写

写这些并没有什么乐趣,尤其是当涉及到很多实体类型和伴随关系时

因此,我们的想法是设计一个关系模式和一个代码生成器,繁重的工作可以外包给它

问题

给定一个(假设的)关系模式,如下所示:

const schema = {
  book: {
    attributes: ["id", "name", "subGenreId"],
    foreignKeys: [
      { fromAttribute: "subGenreId", toEntity: "subGenre", toAttribute: "id" }
    ]
  },

  mainGenre: {
    attributes: ["id", "name"]
  },

  subGenre: {
    attributes: ["id", "name", "mainGenreId"],
    foreignKeys: [
      { fromAttribute: "mainGenreId", toEntity: "mainGenre", toAttribute: "id" }
    ]
  },

  author: {
    attributes: ["id", "name"]
  },

  book_author: {
    attributes: ["bookId", "authorId"],
    foreignKeys: [
      { fromAttribute: "bookId", toEntity: "book", toAttribute: "id" },
      { fromAttribute: "authorId", toEntity: "author", toAttribute: "id" }
    ]
  },

  seller: {
    attributes: ["id", "name"]
  },

  seller_book: {
    attributes: ["sellerId", "bookId"],
    foreignKeys: [
      { fromAttribute: "sellerId", toEntity: "seller", toAttribute: "id" },
      { fromAttribute: "bookId", toEntity: "book", toAttribute: "id" }
    ]
  }
};
目标是(当然是通过计算)沿着以下几行生成选择器(可能忘记了一些):

“直接”关系:

  • 书籍
    子类型
    id
  • main流派
    by
    子流派
    id
  • 子类型
    by
    book
    id
  • 子体裁
    by
    main体裁
    id
多对多关系(省略连接表本身):

  • 作者
    by
    book
    id
  • 书籍
    作者id
  • 书籍
    卖家
    id
  • sellers
    by
    book
    id
“遥远”的关系(这就是它变得有趣的地方):

  • 作者
    by
    main流派
    id
  • 作者
    作者卖家id
  • 作者
    by
    子类型
    id
  • 书籍
    by
    main流派
    id
  • main流派
    by
    book
    id
  • mainGenres
    by
    author
    id
  • maingenders
    by
    seller
    id
  • 卖家
    作者id
  • 卖家
    by
    main流派
    id
  • 卖家
    by
    子类型
    id
  • 子体裁
    作者id
  • 子类型
    by
    卖家
    id
还有更复杂的(例如循环)关系,如合作作者,但我不介意在需要时手动编写代码

如何枚举实体之间的这些关联?是否存在预先存在的解决方案?我可以想象会涉及到图形遍历,但也许使用我还不知道的方法解决这个问题会更好