Rails 对 grails 的命名查询

Rails named queries to grails

我在 rails 中有这个:

default_scope { order('created_at DESC') }
  scope :by_source_name, ->(source_name) { where('source_name = ?', source_name) if source_name }
  scope :by_check_name,  ->(check_name)  { where('check_name = ?', check_name.upcase) if check_name }
  scope :by_status,      ->(status)      { where('status = ?', status.upcase) if status }
end

def index
    @alerts = Alert.by_source_name(params[:source_name])
                   .by_check_name(params[:check_name])
                   .by_status(params[:status])
    render json: @alerts, each_serializer: AlertSerializer
  end

如何转换为grails?

这是命名查询的示例 - https://www.google.com.sg/url?sa=t&rct=j&q=&esrc=s&source=web&cd=4&cad=rja&uact=8&ved=0CDIQFjAD&url=https%3A%2F%2Fspring.io%2Fblog%2F2010%2F05%2F24%2Fmore-grails-1-3-features&ei=wdFWVd2LAYiD8gXBmIGAAw&usg=AFQjCNG9nkkOhP3zR6CnwFm2n9EjUfOnmA&sig2=g-LwWYCjfK-U8gqydirRIg&bvm=bv.93564037,d.dGc