2 ms·
Sounds like you want a query builder. A quick search for "query builder golang" (We are on HN after all) provides the following library: https://github.com/fr
by reificator 7y ago
Sounds like you want a query builder.
A quick search for "query builder golang" (We are on HN after all) provides the following library:
https://github.com/fragmenta/query https://github.com/fragmenta/query
An example from the README:
// In your handlers, construct queries and ask your models for the data
// Find a simple model by id
page, err := pages.Find(1)
// Start querying the database using chained finders
q := page.Query().Where("id IN (?,?)",4,5).Order("id desc").Limit(30)
// Build up chains depending on other app logic, still no db requests
if shouldRestrict {
q.Where("id > ?",3).OrWhere("keywords ~* ?","Page")
}