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

implement array_fill #4203

Merged
merged 3 commits into from
Aug 28, 2024
Merged

Conversation

valkrypton
Copy link
Contributor

implemented array_fill under #4153

@weiznich weiznich requested a review from a team August 26, 2024 09:27
@valkrypton
Copy link
Contributor Author

not sure what arguments should i pass in auto_type.rs function call

@valkrypton valkrypton force-pushed the feat/add/array_fill branch 2 times, most recently from 6b7a83a to 67df9a6 Compare August 26, 2024 11:06

/// Return type of [`array_fill_with_lower_bound(value,array,array)`](super::functions::array_fill_with_lower_bound())
#[allow(non_camel_case_types)]
#[cfg(feature = "postgres_backend")]
pub type array_fill_with_lower_bound<E> =
super::functions::array_fill_with_lower_bound<SqlTypeOf<E>, E, Array<Integer>, Array<Integer>>;
pub type array_fill_with_lower_bound<E, A1, A2> =
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure why i have to write generics here for arguments that have concrete types, but this works. An explanation would be appreciated!

Copy link
Member

Choose a reason for hiding this comment

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

define_sql_function! generates a function signature as follows for the array_fill function:

fn array_fill<E: SingleValue, value: T1, dim: T2>(value: T1, dim: T2) -> _
where T1: AsExpression<E>, 
            T2: AsExpression<Array<Integer>>

The additional AsExpression bounds enable diesel to accept a typed SQL expression (like for example a column) or a rust side value (for example 5) as argument in this position.

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.

Looks good for me beside the minor stylistic request. (I will just apply the suggestions, no need to change anything here).

diesel/src/pg/expression/functions.rs Outdated Show resolved Hide resolved
diesel/src/pg/expression/functions.rs Outdated Show resolved Hide resolved

/// Return type of [`array_fill_with_lower_bound(value,array,array)`](super::functions::array_fill_with_lower_bound())
#[allow(non_camel_case_types)]
#[cfg(feature = "postgres_backend")]
pub type array_fill_with_lower_bound<E> =
super::functions::array_fill_with_lower_bound<SqlTypeOf<E>, E, Array<Integer>, Array<Integer>>;
pub type array_fill_with_lower_bound<E, A1, A2> =
Copy link
Member

Choose a reason for hiding this comment

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

define_sql_function! generates a function signature as follows for the array_fill function:

fn array_fill<E: SingleValue, value: T1, dim: T2>(value: T1, dim: T2) -> _
where T1: AsExpression<E>, 
            T2: AsExpression<Array<Integer>>

The additional AsExpression bounds enable diesel to accept a typed SQL expression (like for example a column) or a rust side value (for example 5) as argument in this position.

@weiznich weiznich enabled auto-merge August 26, 2024 12:20
@weiznich weiznich force-pushed the feat/add/array_fill branch from dbec4d3 to 6e423d3 Compare August 28, 2024 08:19
@weiznich weiznich added this pull request to the merge queue Aug 28, 2024
Merged via the queue into diesel-rs:master with commit 7c62c58 Aug 28, 2024
48 checks passed
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.

2 participants