@@ -2,6 +2,9 @@ use crate::utils::macro_tokens::MacroTokens;
22use proc_macro2:: { Ident , TokenStream } ;
33use quote:: { ToTokens , quote} ;
44
5+ #[ cfg( feature = "mssql" ) ]
6+ const MSSQL_ENABLED : bool = true ;
7+
58/// Facade function that acts as the unique API for export to the real macro implementation
69/// of all the generated macros for the READ operations
710pub fn generate_read_operations_tokens (
@@ -144,7 +147,7 @@ mod __details {
144147 pub fn create_find_all_macro ( mapper_ty : & Ident , stmt : & str ) -> TokenStream {
145148 quote ! {
146149 async fn find_all( )
147- -> Result <Vec <#mapper_ty>, Box <dyn std:: error:: Error + Send + Sync >>
150+ -> Result <Vec <#mapper_ty>, Box <( dyn std:: error:: Error + Send + Sync ) >>
148151 {
149152 let default_db_conn = canyon_sql:: core:: Canyon :: instance( ) ?. get_default_connection( ) ?;
150153 default_db_conn. query( #stmt, & [ ] ) . await
@@ -155,7 +158,7 @@ mod __details {
155158 pub fn create_find_all_with_macro ( mapper_ty : & Ident , stmt : & str ) -> TokenStream {
156159 quote ! {
157160 async fn find_all_with<' a, I >( input: I )
158- -> Result <Vec <#mapper_ty>, Box <dyn std:: error:: Error + Send + Sync >>
161+ -> Result <Vec <#mapper_ty>, Box <( dyn std:: error:: Error + Send + Sync ) >>
159162 where
160163 I : canyon_sql:: connection:: DbConnection + Send + ' a
161164 {
@@ -166,24 +169,30 @@ mod __details {
166169 }
167170
168171 pub mod count_generators {
172+ use crate :: query_operations:: read:: MSSQL_ENABLED ;
173+
169174 use super :: * ;
170175 use proc_macro2:: TokenStream ;
171176
172177 pub fn create_count_macro ( stmt : & str ) -> TokenStream {
178+ let mssql_arm = if MSSQL_ENABLED {
179+ quote ! {
180+ canyon_sql:: connection:: DatabaseType :: SqlServer => {
181+ let count_i32: i32 = default_db_conn. query_one_for:: <i32 >( #stmt, & [ ] ) . await ?;
182+ Ok ( count_i32 as i64 )
183+ }
184+ }
185+ } else {
186+ quote ! { } // MSSQL disabled → no branch emitted
187+ } ;
188+
173189 quote ! {
174190 async fn count( ) -> Result <i64 , Box <dyn std:: error:: Error + Send + Sync >> {
175191 let default_db_conn = canyon_sql:: core:: Canyon :: instance( ) ?. get_default_connection( ) ?;
176- // Handle different database types for COUNT(*) operations
177192 let db_type = default_db_conn. get_database_type( ) ?;
178193 match db_type {
179- #[ cfg( feature = "mssql" ) ]
180- canyon_sql:: connection:: DatabaseType :: SqlServer => {
181- // SQL Server COUNT(*) returns i32, convert to i64
182- let count_i32: i32 = default_db_conn. query_one_for:: <i32 >( #stmt, & [ ] ) . await ?;
183- Ok ( count_i32 as i64 )
184- }
194+ #mssql_arm
185195 _ => {
186- // PostgreSQL and MySQL COUNT(*) return i64
187196 default_db_conn. query_one_for:: <i64 >( #stmt, & [ ] ) . await
188197 }
189198 }
@@ -192,19 +201,27 @@ mod __details {
192201 }
193202
194203 pub fn create_count_with_macro ( stmt : & str ) -> TokenStream {
204+ let mssql_arm = if MSSQL_ENABLED {
205+ quote ! {
206+ canyon_sql:: connection:: DatabaseType :: SqlServer => {
207+ // SQL Server COUNT(*) returns i32, convert to i64
208+ let count_i32: i32 = input. query_one_for:: <i32 >( #stmt, & [ ] ) . await ?;
209+ Ok ( count_i32 as i64 )
210+ }
211+ }
212+ } else {
213+ quote ! { } // No MSSQL support compiled → emit nothing
214+ } ;
215+
195216 quote ! {
196- async fn count_with<' a, I >( input: I ) -> Result <i64 , Box <dyn std:: error:: Error + Send + Sync + ' a>>
197- where I : canyon_sql:: connection:: DbConnection + Send + ' a
217+ async fn count_with<' a, I >( input: I )
218+ -> Result <i64 , Box <dyn std:: error:: Error + Send + Sync + ' a>>
219+ where
220+ I : canyon_sql:: connection:: DbConnection + Send + ' a
198221 {
199- // Handle different database types for COUNT(*) operations
200222 let db_type = input. get_database_type( ) ?;
201223 match db_type {
202- #[ cfg( feature = "mssql" ) ]
203- canyon_sql:: connection:: DatabaseType :: SqlServer => {
204- // SQL Server COUNT(*) returns i32, convert to i64
205- let count_i32: i32 = input. query_one_for:: <i32 >( #stmt, & [ ] ) . await ?;
206- Ok ( count_i32 as i64 )
207- }
224+ #mssql_arm
208225 _ => {
209226 // PostgreSQL and MySQL COUNT(*) return i64
210227 input. query_one_for:: <i64 >( #stmt, & [ ] ) . await
0 commit comments