Skip to content
New issue

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

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

Already on GitHub? # to your account

Export SQL numeric operations from diesel::expression::ops::numeric , and auto-type them. #4462

Open
dessalines opened this issue Jan 29, 2025 · 2 comments

Comments

@dessalines
Copy link
Contributor

Discussed in #4461

Originally posted by dessalines January 28, 2025
I'd like to use a subtract operation be used as a select_expression.

This gets the number of unread comments in a post: post_aggregates::comments - post_actions::read_comments_amount

This unfortunately can't use auto_type, and I also can't strictly define the type, since the Sub numeric operation is in a private module : diesel::expression::ops::numeric::Sub

My output type should be something like:

diesel::expression::ops::numeric::Sub<
  post_aggregates::comments,
  post_actions::read_comments_amount
>

Is there any way to get the type from a numeric operation?

Thanks in advance.

@dessalines dessalines changed the title Export SQL numeric operations from diesel::expression::ops::numeric, and auto-type them. Export SQL numeric operations from diesel::expression::ops::numeric , and auto-type them. Jan 29, 2025
@weiznich
Copy link
Member

weiznich commented Jan 31, 2025

This requires us to add the following type definitions including documentation to diesel::expression::helper_types:

pub type Add<L, R> = <L as ::core::ops::Add<R>>::Output;
pub type Sub<L, R> = <L as ::core::ops::Sub<R>>::Output;
pub type Mul<L, R> = <L as ::core::ops::Mul<R>>::Output;
pub type Div<L, R> = <L as ::core::ops::Div<R>>::Output;

@dhirensr
Copy link
Contributor

I'm looking into adding this.

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

3 participants