We have MVC application written in go
lang
There are 2 endpoint that looks to query database to get all relevant users.
/get_paginate_users - > Query Database with paginate endpoint
/get_users -> [1, 2] -> Query Database with given ID.
To the sake of achieving generic functionality I'm passing the Driver options as the parameters to models function.
// controller.go
// # /get_paginate_users
models.FindUsers(bson.M{}, options.Find().SetLimit(limit))
// bson.M {} and options.Find() are driver specific argument (in our case mongodb).
// controller.go
// # /get_users
models.FindUsers(bson.M{user_ids: bson.M{"$in": user_ids}}, nil)
This where I'm having a discussion with my colleague, He is of the opinion that database related stuff like bson.M
should only the part model. (Since In future if the database is changes it would require change in multiple places)
But doing so result in non generic functions.
What is ideal thing to do over here?, Having to achieve generic function or have model deal with all the driver data type?