Skip to content

Instantly share code, notes, and snippets.

@paragtokopedia
Last active July 13, 2018 05:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paragtokopedia/1684c6429849ac3af91604d3e819ef6f to your computer and use it in GitHub Desktop.
Save paragtokopedia/1684c6429849ac3af91604d3e819ef6f to your computer and use it in GitHub Desktop.
Generating Dynamic Queries using DQB
func GenerateQuery(queryParams QueryParams) (string) {
var dqb DynamicQueryBuilder
query = dqb.And(
dqb.NewExp("status", "=", queryParams["status"]),
dqb.NewExp("phone_number", "=", queryParams["phone_number"]),
dqb.NewExp("email", "=", queryParams["email"]),
dqb.NewExp("created_at", ">=", queryParams["application_start_date"]), //if empty it will not be added in where clause
dqb.NewExp("created_at", "<=", queryParams["application_end_date"]),
).Limit(0,10).BindSql("select * from application")
return query
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment