Skip to content

Instantly share code, notes, and snippets.

@shanev
Created January 21, 2019 19:44
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 shanev/c6d742f63e639aa722db95f1dd658974 to your computer and use it in GitHub Desktop.
Save shanev/c6d742f63e639aa722db95f1dd658974 to your computer and use it in GitHub Desktop.
// GenericQueries are generic reads for models
type GenericQueries interface {
Count(model interface{}) (int, error)
Find(model interface{}) error
FindAll(models interface{}) error
}
// Count returns the count of the model
func (c *Client) Count(model interface{}) (count int, err error) {
count, err = c.Model(model).Count()
return
}
// Find selects a single model by primary key
func (c *Client) Find(model interface{}) error {
return c.Select(model)
}
// FindAll selects all models
func (c *Client) FindAll(models interface{}) error {
return c.Model(models).Select()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment