mickhansen/dataloader-sequelize

Support findOne

oney opened this issue · 2 comments

oney commented

I'm not sure if this package has supported findOne.
What I want is

Article.findOne({
  where: {
    id: 1001,
    isDeleted: false,
    status: "public"
  }
})
Article.findOne({
  where: {
    id: 1002,
    isDeleted: false,
    status: "public"
  }
})
Article.findOne({
  where: {
    id: 1003,
    isDeleted: false,
    status: "public"
  }
})
Article.findOne({
  where: {
    id: 1004,
    isDeleted: false,
    status: "draft"
  }
})
Article.findOne({
  where: {
    id: 1005,
    isDeleted: false,
    status: "draft"
  }
})
Article.findOne({
  where: {
    id: 1006,
    isDeleted: true,
    status: "private"
  }
})

these queries can be merged.
Basically, we should count distinct values of fields in where, and merge less distinct fields recursively.

For example, for above 6 queries,
distinct ids are 1001, 1002, 1003, 1004, 1005, 1006
distinct isDeleted are true and false
distinct status are public, draft, private.

Therefore, queries should be separated and collected by isDeleted first. That's

{
  isDeleted: false,
  queries: [
    {
      id: 1001,
      status: "public"
    },
    {
      id: 1002,
      status: "public"
    },
    {
      id: 1003,
      status: "private"
    },
    {
      id: 1004,
      status: "draft"
    },
    {
      id: 1005,
      status: "draft"
    },
  ]
}
// not show isDeleted: true

Then it can be merged again to be

{
  isDeleted: false,
  status: "public",
  id: [1001, 1002]
}

{
  isDeleted: false,
  status: "private",
  id: [1003]
}

{
  isDeleted: false,
  status: "draft",
  id: [1004,1005]
}

Where statements beyond primary key lookups are not currently supported

stale commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.