feat(orm): string matching in Query#605
Conversation
|
| Project | cot |
| Branch | elijah/like-query |
| Testbed | github-ubuntu-latest |
Click to view all benchmark results
| Benchmark | Latency | Benchmark Result microseconds (µs) (Result Δ%) | Upper Boundary microseconds (µs) (Limit %) |
|---|---|---|---|
| empty_router/empty_router | 📈 view plot 🚷 view threshold | 9,714.70 µs(+33.97%)Baseline: 7,251.66 µs | 12,548.18 µs (77.42%) |
| json_api/json_api | 📈 view plot 🚷 view threshold | 759.06 µs(-29.74%)Baseline: 1,080.30 µs | 1,366.69 µs (55.54%) |
| nested_routers/nested_routers | 📈 view plot 🚷 view threshold | 721.94 µs(-28.26%)Baseline: 1,006.29 µs | 1,243.37 µs (58.06%) |
| single_root_route/single_root_route | 📈 view plot 🚷 view threshold | 676.34 µs(-30.25%)Baseline: 969.60 µs | 1,206.40 µs (56.06%) |
| single_root_route_burst/single_root_route_burst | 📈 view plot 🚷 view threshold | 11,825.00 µs(-31.93%)Baseline: 17,371.55 µs | 21,686.46 µs (54.53%) |
Codecov Report❌ Patch coverage is
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
.contains, .starts_with, .ends_with` proof of concept.contains, .starts_with, .ends_with proof of concept
- improve code quality - Add docs - refactor/move expr into a module since db/query file has grown bigger now
.contains, .starts_with, .ends_with proof of concept.contains, .starts_with, .ends_with, .raw_like
.contains, .starts_with, .ends_with, .raw_likeThere was a problem hiding this comment.
We should have some docs added to the guide about this cool new feature 😉
There was a problem hiding this comment.
Ah yes, extracting Expr to a separate module is probably a good idea, given how much code it is.
| fn iraw_like<V: Into<String>>(self, other: V) -> Expr; | ||
| } | ||
|
|
||
| impl<T: ToDbFieldValue + 'static> ExprLike<T> for FieldRef<T> { |
There was a problem hiding this comment.
I'm wondering - should we implement this for any T: ToDbFieldValue, or maybe we should somehow restrict this to String-only columns? (similarly to how we implement ExprMul, for instance) What do you think?
There was a problem hiding this comment.
Ah yeah, I think we definitely need to restrict this to String-only columns. We need a way to tell that a current Field is a Text/String Field. I see we implement DatabaseField for every DB type where we specify the ColumnType, but I'm not sure how we can use that trait as bounds here. My intuition here is to define a TextField marker trait and implement that for all DbFieldValue types that turn into text:
pub trait TextField: DbFieldValue {}
impl TextField for String {}
impl TextField for common_types::Email {}
impl TextField for common_types::Url {}
impl <const LIMIT: u32> TextField for LimitedString<LIMIT>{}
impl <T: TextField + 'static> ExprLike <T> for FieldRef<T> {
...
}Query
Description
This PR adds basic string pattern matching to queries. This is equivalent to
LIKE,ILIKE(postgres specific) andGLOB(sqlite specific) variants on database enginesThe expressions supported are:
containsstarts_withends_withraw_likeand with an i-prefixed case-insensitive counterpart of each:
icontainsistarts_withiends_withiraw_likeUsage:
raw_like/iraw_likeare escape hatches that accept a raw glob pattern (* for zero-or-more characters, ? for exactly one, \ to escape a wildcard) rather than a plain literal, for shapes the other four methods can't express, such as a fixed-width or middle-of-string match:These methods can be combined with Boolean and comparison operators like any other expression:
Type of change