|
6 | 6 | /// |
7 | 7 | use canyon_sql::{ |
8 | 8 | crud::CrudOperations, |
9 | | - query::{operators::Comp, ops::QueryBuilder}, |
| 9 | + query::{operators::Comp, operators::Like, ops::QueryBuilder}, |
10 | 10 | }; |
11 | 11 |
|
12 | 12 | #[cfg(feature = "mssql")] |
@@ -59,6 +59,96 @@ fn test_crud_find_with_querybuilder() { |
59 | 59 | assert_eq!(league_idx_0.region, "KOREA"); |
60 | 60 | } |
61 | 61 |
|
| 62 | +/// Builds a new SQL statement for retrieves entities of the `T` type, filtered |
| 63 | +/// with the parameters that modifies the base SQL to SELECT * FROM <entity> |
| 64 | +#[cfg(feature = "postgres")] |
| 65 | +#[canyon_sql::macros::canyon_tokio_test] |
| 66 | +fn test_crud_find_with_querybuilder_and_fulllike() { |
| 67 | + // Find all the leagues with "LC" in their name |
| 68 | + let mut filtered_leagues_result = League::select_query(); |
| 69 | + filtered_leagues_result.r#where(LeagueFieldValue::name(&"LC"), Like::Full); |
| 70 | + |
| 71 | + assert_eq!( |
| 72 | + filtered_leagues_result.read_sql(), |
| 73 | + "SELECT * FROM league WHERE name LIKE CONCAT('%', CAST($1 AS VARCHAR) ,'%')" |
| 74 | + ) |
| 75 | +} |
| 76 | + |
| 77 | +/// Builds a new SQL statement for retrieves entities of the `T` type, filtered |
| 78 | +/// with the parameters that modifies the base SQL to SELECT * FROM <entity> |
| 79 | +#[cfg(feature = "mssql")] |
| 80 | +#[canyon_sql::macros::canyon_tokio_test] |
| 81 | +fn test_crud_find_with_querybuilder_and_fulllike_datasource() { |
| 82 | + // Find all the leagues with "LC" in their name |
| 83 | + let mut filtered_leagues_result = League::select_query_datasource(SQL_SERVER_DS); |
| 84 | + filtered_leagues_result.r#where(LeagueFieldValue::name(&"LC"), Like::Full); |
| 85 | + |
| 86 | + assert_eq!( |
| 87 | + filtered_leagues_result.read_sql(), |
| 88 | + "SELECT * FROM league WHERE name LIKE CONCAT('%', CAST($1 AS VARCHAR) ,'%')" |
| 89 | + ) |
| 90 | +} |
| 91 | + |
| 92 | +/// Builds a new SQL statement for retrieves entities of the `T` type, filtered |
| 93 | +/// with the parameters that modifies the base SQL to SELECT * FROM <entity> |
| 94 | +#[cfg(feature = "postgres")] |
| 95 | +#[canyon_sql::macros::canyon_tokio_test] |
| 96 | +fn test_crud_find_with_querybuilder_and_leftlike() { |
| 97 | + // Find all the leagues whose name ends with "CK" |
| 98 | + let mut filtered_leagues_result = League::select_query(); |
| 99 | + filtered_leagues_result.r#where(LeagueFieldValue::name(&"CK"), Like::Left); |
| 100 | + |
| 101 | + assert_eq!( |
| 102 | + filtered_leagues_result.read_sql(), |
| 103 | + "SELECT * FROM league WHERE name LIKE CONCAT('%', CAST($1 AS VARCHAR))" |
| 104 | + ) |
| 105 | +} |
| 106 | + |
| 107 | +/// Builds a new SQL statement for retrieves entities of the `T` type, filtered |
| 108 | +/// with the parameters that modifies the base SQL to SELECT * FROM <entity> |
| 109 | +#[cfg(feature = "mssql")] |
| 110 | +#[canyon_sql::macros::canyon_tokio_test] |
| 111 | +fn test_crud_find_with_querybuilder_and_leftlike_datasource() { |
| 112 | + // Find all the leagues whose name ends with "CK" |
| 113 | + let mut filtered_leagues_result = League::select_query(); |
| 114 | + filtered_leagues_result.r#where(LeagueFieldValue::name(&"CK"), Like::Left); |
| 115 | + |
| 116 | + assert_eq!( |
| 117 | + filtered_leagues_result.read_sql(), |
| 118 | + "SELECT * FROM league WHERE name LIKE CONCAT('%', CAST($1 AS VARCHAR))" |
| 119 | + ) |
| 120 | +} |
| 121 | + |
| 122 | +/// Builds a new SQL statement for retrieves entities of the `T` type, filtered |
| 123 | +/// with the parameters that modifies the base SQL to SELECT * FROM <entity> |
| 124 | +#[cfg(feature = "postgres")] |
| 125 | +#[canyon_sql::macros::canyon_tokio_test] |
| 126 | +fn test_crud_find_with_querybuilder_and_rightlike() { |
| 127 | + // Find all the leagues whose name starts with "LC" |
| 128 | + let mut filtered_leagues_result = League::select_query(); |
| 129 | + filtered_leagues_result.r#where(LeagueFieldValue::name(&"LC"), Like::Right); |
| 130 | + |
| 131 | + assert_eq!( |
| 132 | + filtered_leagues_result.read_sql(), |
| 133 | + "SELECT * FROM league WHERE name LIKE CONCAT(CAST($1 AS VARCHAR) ,'%')" |
| 134 | + ) |
| 135 | +} |
| 136 | + |
| 137 | +/// Builds a new SQL statement for retrieves entities of the `T` type, filtered |
| 138 | +/// with the parameters that modifies the base SQL to SELECT * FROM <entity> |
| 139 | +#[cfg(feature = "mssql")] |
| 140 | +#[canyon_sql::macros::canyon_tokio_test] |
| 141 | +fn test_crud_find_with_querybuilder_and_rightlike_datasource() { |
| 142 | + // Find all the leagues whose name starts with "LC" |
| 143 | + let mut filtered_leagues_result = League::select_query_datasource(SQL_SERVER_DS); |
| 144 | + filtered_leagues_result.r#where(LeagueFieldValue::name(&"LC"), Like::Right); |
| 145 | + |
| 146 | + assert_eq!( |
| 147 | + filtered_leagues_result.read_sql(), |
| 148 | + "SELECT * FROM league WHERE name LIKE CONCAT(CAST($1 AS VARCHAR) ,'%')" |
| 149 | + ) |
| 150 | +} |
| 151 | + |
62 | 152 | /// Same than the above but with the specified datasource |
63 | 153 | #[cfg(feature = "mssql")] |
64 | 154 | #[canyon_sql::macros::canyon_tokio_test] |
|
0 commit comments