66///
77use canyon_sql:: {
88 crud:: CrudOperations ,
9- query:: { operators:: Comp , ops:: QueryBuilder } ,
9+ query:: { operators:: Comp , operators :: Like , ops:: QueryBuilder } ,
1010} ;
1111
1212#[ cfg( feature = "mssql" ) ]
@@ -34,7 +34,7 @@ fn test_generated_sql_by_the_select_querybuilder() {
3434 // generated SQL by the SelectQueryBuilder<T> is the spected
3535 assert_eq ! (
3636 select_with_joins. read_sql( ) ,
37- "SELECT * FROM league INNER JOIN tournament ON league.id = tournament.league_id LEFT JOIN team ON tournament.id = player.tournament_id WHERE id > $1 AND name = $2 AND name IN ($2, $3) "
37+ "SELECT * FROM league INNER JOIN tournament ON league.id = tournament.league_id LEFT JOIN team ON tournament.id = player.tournament_id WHERE id > $1 AND name = $2 AND name IN ($2, $3)"
3838 )
3939}
4040
@@ -59,6 +59,96 @@ fn test_crud_find_with_querybuilder() {
5959 assert_eq ! ( league_idx_0. region, "KOREA" ) ;
6060}
6161
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+
62152/// Same than the above but with the specified datasource
63153#[ cfg( feature = "mssql" ) ]
64154#[ canyon_sql:: macros:: canyon_tokio_test]
@@ -239,7 +329,7 @@ fn test_or_clause_with_in_constraint() {
239329
240330 assert_eq ! (
241331 l. read_sql( ) ,
242- "SELECT * FROM league WHERE name = $1 OR id IN ($1, $2, $3) "
332+ "SELECT * FROM league WHERE name = $1 OR id IN ($1, $2, $3)"
243333 )
244334}
245335
0 commit comments