Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add like, not_like and concat for PostgreSQL Bytea #3150

Merged
merged 2 commits into from
May 2, 2022

Conversation

Justice4Joffrey
Copy link
Contributor

I saw a couple of issues requestinhg support for this (e.g. #3127).

This is mostly a copy of TextExpressionMethods.

Would love to know if there's a more concise way of creating a Vec<u8> from a readable literal other than "S%".as_bytes().to_owned()).

@Mingun
Copy link
Contributor

Mingun commented Apr 28, 2022

I believe, the shortest way is b"S%".to_vec()

@Justice4Joffrey Justice4Joffrey force-pushed the oc-pg-byte-methods branch 2 times, most recently from 4acdafc to ae58d93 Compare April 28, 2022 11:25
@weiznich weiznich requested a review from a team April 28, 2022 11:30
Copy link
Member

@weiznich weiznich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for opening this PR 👍

The implementation itself looks good. I would like to see a compile test that demonstrates that code using like/concat/not_like with a binary column only compiles using a postgres connection.

@Justice4Joffrey
Copy link
Contributor Author

In the current implementation, all of these pg-specific expression methods will be available for all T's when the "postgres_backend" feature flag is set. Probably works in practice but is clearly incorrect.

E.g.

impl<T> PgTextExpressionMethods for T
where
    T: Expression,
    T::SqlType: TextOrNullableText,
{
}

@weiznich
Copy link
Member

That's what I assumed 😉.

So the correct way to fix this is to introduce postgres specific variants of the corresponding operators. It should be easy to define them via the diesel::infix_operation! macro.

@Justice4Joffrey
Copy link
Contributor Author

Justice4Joffrey commented May 1, 2022

Ok I see. I think the take-home here is you should never return a type other than those defined in pg/helper_types.rs, and those should only refer to pg specific operators.

IMO it would be good to make that slightly more obvious. All methods in that file specifically use helper_types through the crate-level dsl module, which is misleading.

@weiznich
Copy link
Member

weiznich commented May 2, 2022

Thanks for the update 👍

Yes that requirement could made more clear. I would definitively accept a PR adding corresponding comments. Otherwise I try to remember that and will add a comment there myself as soon as I touch that part of the code again.

@weiznich weiznich merged commit cfc0d42 into diesel-rs:master May 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants