|
Named Query Support
GORM now supports defining named queries in a domain class. For example, given a domain class like this:
class Publication {
String title
Date datePublished
static namedQueries = {
recentPublications {
def now = new Date()
gt 'datePublished', now - 365
}
publicationsWithBookInTitle {
like 'title', '%Book%'
}
}
}
You can do:
// get all recent publications
def recentPubs = Publication.recentPublications.list()
// get up to 10 recent publications, skip the first 5…
def recentPubs = Publication.recentPublications.list(max: 10, offset: 5)
// get the number of recent publications…
def numberOfRecentPubs = Publication.recentPublications.count()
// get a recent publication with a specific id…
def pub = Publication.recentPublications.get(42)
// dynamic finders are supported
def pubs = Publication.recentPublications.findAllByTitle('Some Title') |
|