Can you make one request to database passing n parameters?

So basically my problem is: Making request to database and I know that good practice is to make less request to database.

Here is some code, I’m using GORM library. I’m receiving an array with name’s and I need to get data about them. Straigforward solution is to make for each loop and call this query.

return r.DB. Model(&models.User{}).Where("name = ?", name).Find(&user).Error

But this solution is bad practice, so I wonder is there any good solution to this problem?

Nevermind found at documentation code sample:
db.Where("name IN ?", []string{"jinzhu", "jinzhu 2"}).Find(&users)

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.