Skip to content

Conversation

@mcamara
Copy link
Contributor

@mcamara mcamara commented Nov 15, 2024

Description

This PR introduces functionality to support database-level casting for columns in filter nodes using sea-query. It allows users to specify a casting type for columns through the FilterNodeOptions and ensures proper integration with SeaQuery queries.

Key Changes

  1. New cast_column_as Option in FilterNodeOptions:

    • Added a new field, cast_column_as, to FilterNodeOptions for specifying the cast type of a column.
    • Updated the macro generation logic to allow this attribute to be set via cast_column_as in modql attributes.
  2. Column Casting Implementation in sea_utils:

    • Added into_node_column_expr to handle casting for ColumnRef instances.
    • Integrated this function into filter operations for generating proper SQL expressions with casting applied.
  3. Version Upgrades:

    • Updated dependencies:
      • sea-query: Bumped from 0.31 to 0.32.
      • rusqlite: Bumped from 0.31 to 0.32.
      • sea-query-rusqlite: Updated from 0.6 to 0.7.
  4. Macro Updates:

    • Modified derive_filter_nodes_inner to generate code for setting cast_column_as in filter node options.
    • Updated the attribute parsing logic in utils.rs to handle the new cast_column_as attribute.
  5. Filter Operation Updates:

    • Updated various filter operation modules (op_val_string.rs, op_val_value.rs) to use into_node_column_expr for consistent column handling with casting.

Example

Using the new feature in a filter:

struct PostFilter {
  #[modql(cast_column_as = "text")]
  title: String,
}

Generates SQL like:

CAST("posts"."title" AS text) ILIKE $1

@jeremychone let me know what you think of this addition and feel free to add any feedback to it! Thanks!

@jeremychone
Copy link
Owner

@mcamara First, thank you very much, this is very interesting.

However, I had to merge the previous PR regarding SeaQuery 3.2, and now your branch has a minor conflict.

Could you resolve it and merge all the commits in this PR into one, so I can easily review the code changes?

Thanks a lot!

@jeremychone jeremychone merged commit 9d50648 into jeremychone:main Dec 11, 2024
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