go-sql-driver / go-sql-driver/mysql

add QMarks(num int) helper function

Open
#368 1 comment 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Go
Stars
15.3k
Forks
2.3k
Avg merge
2h 23m
Merged PRs (30d)
10

Description

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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.