1 year ago
#217412
Axeler4t0r
How to use regexp in Vapor Fluent sqlite?
I have a simple model that has a string field, like this:
final class Record: Model, Content {
@ID(key: .id)
var id: UUID?
@Field(key: "name")
var name: String
...
}
And I want to query and filter this name
field using a regexp pattern.
My current solution is using .all()
to get all rows, then use normal NSRegularExpression
way to filter every row in Swift.
However this is REALLY SLOW. On my machine I can do around 400 requests per second using the ORM framework provided .filter()
functions. While only 4 request per second with my own regex filter.
I know that sqlite does provide a REGEXP
function, and it's significantly faster. But it requires loading an external module to run.
So how can I import this module using FluentSQL or is there any workaround?
swift
sqlite
vapor
vapor-fluent
server-side-swift
0 Answers
Your Answer