fluent-kit
fluent-kit copied to clipboard
Computed fields
A property similar to @Field for computed columns could be useful for things like case-insensitive text search.
Related: https://github.com/vapor/fluent-postgres-driver/issues/62
From https://github.com/vapor/fluent-postgres-driver/issues/62:
try User.query(on: db)
.filter(\User.$email.lowercased() == emailAddress.lowercased())
.first()
I'm eager to have this feature: I can't seem to match the the capabilities of Hibernate's Formula using custom sql. Maybe it could take a form similar to Hibernate's...
final class Person : Content, Model {
static let schema = "person"
@ID(custom: "id", generatedBy: .database)
var id: Int?
@Field(key: "first_name") var firstName: String
@Field(key: "last_name") var lastName: String
@Field(key: "date_of_birth") var dateOfBirth: Date
@Computed(value: "year(current_date()) - year(date_of_birth)") var age: Int
@Computed(value: "first_name || ' ' || last_name") var fullName: String
init() {}
}
I'll assign this to @gwynne - this isn't something that will likely get implemented for Fluent 4 but could be something to consider for Fluent 5