Skip to content

add QMarks(num int) helper function #368

Open
@jmhodges

Description

@jmhodges

It's a common pattern to have to break up JOINs that are too expensive for the database into separate queries. But doing that naively causes the n+1 query problem. So, one gathers data in one query for the left side with whatever LIMITs or munging was needed, batches that data up with an IN operator in one or a few more queries, and goes home.

But using that IN operator means having to write this function (or similar) in every project that does so:

func QMarks(num int) string {
  if num == 0 {
    return "()"
  }
  return "(?" + strings.Repeat(",?", num-1) + ")"
}

This gets repetitive. It would be nice if, since slices are disallowed from being used in the driver, this function could live in the driver so folks can avoid having to reproduce this each time they need to solve a problem with the IN operator.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions