I am staring at Fluent code but I am somehow unable to find what I am looking for, so maybe someone here can point me into the right direction?
Basically I want to implement my own filter expression over remote objects. So I looked at Fluent for inspiration and saw this in the documentation:
// An example of Fluent's query API.
let planets = try await Planet.query(on: database)
.filter(\.$type == .gasGiant)
.sort(\.$name)
.with(\.$star)
.all()
Specifically .filter(\.$type == .gasGiant): what would the function signature of filter be? And what kind of syntax is \.$type? I think I read most of the Swift Language Book by now, but I don't think I've seen this? What kind of language features would I need to familiarize myself if I want to implement something similar?
public struct ModelValueFilter<Model> where Model: Fields {
public init<Field>(
_ lhs: KeyPath<Model, Field>,
_ method: DatabaseQuery.Filter.Method,
_ rhs: DatabaseQuery.Value
)
where Field: QueryableProperty
{
self.path = Model.path(for: lhs)
self.method = method
self.value = rhs
}
let path: [FieldKey]
let method: DatabaseQuery.Filter.Method
let value: DatabaseQuery.Value
}
In \.$type, the \. means it is a KeyPath literal. The $ means it is referring to the projectedValue of a property wrapper. The type field of Planet is presumably annotated @FieldProperty, and FieldProperty conforms to QueryableProperty, as required by those == operators.