Reputation: 695
I have a case class Employee
case class Employee(id: Int,
name: String,
age: Int, is_permanent: Boolean,
company_name: String)
I am filtering on this Employee case class using Quill SQL like this:
quote {
query[Employee]
.filter(e => e.age > 100)
.filter(e => liftQuery(List("Robin, Peter")).contains(e.name))
}
It compiles fine.
Now I want to put the second filter
into a function and reuse it.
Like
val employeeQueryFunc: (Employee => Boolean) = e => {
liftQuery(List("Robin, Peter")).contains(e.name)
}
and then apply this function at multiple locations wherever I need. If I put this to the employee query like this
quote {
query[Employee]
.filter(e => e.age > 100)
.filter(employeeQueryFunc)
}
It does not compile. I get the error
this.Employee]).filter(((e: FindAllIssuesRepoQuery.this.Employee) => e.age.> .
(100))).filter(employeeQueryFunc)' can't be parsed to 'Ast'
Ideally it should have compiled as the filter block also contains a function that returns a boolean and employeeQueryFunc
also returns a boolean. Does anyone know how it can be reused as a function ??
Upvotes: 1
Views: 997
Reputation: 11
had a similar issue - have experimented with Daniel's suggestion and in my case it was enough to rewrite
quote {
query[Employee]
.filter(e => e.age > 100)
.filter(employeeQueryFunc)
}
into:
quote {
query[Employee]
.filter(e => e.age > 100)
.filter(e => employeeQueryFunc(e))
}
(no idea why)
Upvotes: 1
Reputation: 1
I had a similar problem when trying to extract a common logic to a private method. update the employeeQueryFunc to:
private def employeeQueryFunc = quote {
(e: Employee) => liftQuery(List("Robin, Peter")).contains(e.Name)
}
and call this method the following way:
quote {
query[Employee]
.filter(e => e.age > 100)
.filter(e => employeeQueryFunc(e))
}
Upvotes: 0