include_oracle_sql/
blocking.rs1#[macro_export]
2macro_rules! impl_sql {
3 ( $sql_name:ident = $( { $kind:tt $name:ident ($($variant:tt $param:ident $ptype:tt)*) $doc:literal $s:tt $( $text:tt )+ } ),+ ) => {
4 trait $sql_name {
5 $( $crate::decl_method!{ $kind $name $doc () () $($param $variant $ptype)* } )+
6 }
7 impl $sql_name for ::sibyl::Session<'_> {
8 $( $crate::impl_method!{ $kind $name () () ($($param $variant $ptype)*) => ($($variant $param)*) $($text)+ } )+
9 }
10 };
11}
12
13#[macro_export]
14#[doc(hidden)]
15macro_rules! decl_method {
16 ( ? $name:ident $doc:literal ($($gen_type:ident)*) ($($fn_params:tt)*) ) => {
17 #[doc=$doc]
18 fn $name<$($gen_type : ::sibyl::ToSql ,)* F>(&self $($fn_params)* , row_cb: F) -> ::sibyl::Result<()>
19 where F: FnMut(::sibyl::Row) -> ::sibyl::Result<()>;
20 };
21
22 ( ! $name:ident $doc:literal ($($gen_type:ident)*) ($($fn_params:tt)*) ) => {
23 #[doc=$doc]
24 fn $name<$($gen_type : ::sibyl::ToSql),*>(&self $($fn_params)*) -> ::sibyl::Result<usize>;
25 };
26
27 ( . $name:ident $doc:literal ($($gen_type:ident)*) ($($fn_params:tt)*) ) => {
28 #[doc=$doc]
29 fn $name(&self) -> ::sibyl::Result<::sibyl::Statement>;
30 };
31
32 ( $kind:tt $name:ident $doc:literal ($($gen_type:ident)*) ($($fn_params:tt)*) $param:ident : _ $($tail:tt)* ) => {
33 $crate::decl_method!{
34 $kind
35 $name
36 $doc
37 ($($gen_type)*)
38 ($($fn_params)* , $param : impl ::sibyl::ToSql)
39 $($tail)*
40 }
41 };
42 ( $kind:tt $name:ident $doc:literal ($($gen_type:ident)*) ($($fn_params:tt)*) $param:ident : ($ptype:ty) $($tail:tt)* ) => {
43 $crate::decl_method!{
44 $kind
45 $name
46 $doc
47 ($($gen_type)*)
48 ($($fn_params)* , $param : $ptype)
49 $($tail)*
50 }
51 };
52 ( $kind:tt $name:ident $doc:literal ($($gen_type:ident)*) ($($fn_params:tt)*) $param:ident # [$gtype:ident] $($tail:tt)* ) => {
53 $crate::decl_method!{
54 $kind
55 $name
56 $doc
57 ($($gen_type)* $gtype)
58 ($($fn_params)* , $param : & [ $gtype ] )
59 $($tail)*
60 }
61 };
62 ( $kind:tt $name:ident $doc:literal ($($gen_type:ident)*) ($($fn_params:tt)*) $param:ident # ($ptype:ty) $($tail:tt)* ) => {
63 $crate::decl_method!{
64 $kind
65 $name
66 $doc
67 ($($gen_type)*)
68 ($($fn_params)* , $param : & [ $ptype ] )
69 $($tail)*
70 }
71 };
72}
73
74#[macro_export]
75#[doc(hidden)]
76macro_rules! impl_method {
77 ( ? $name:ident () () () => () $text:literal ) => {
78 fn $name<F>(&self, mut row_cb: F) -> ::sibyl::Result<()>
79 where F: FnMut(::sibyl::Row) -> ::sibyl::Result<()>
80 {
81 let stmt = self.prepare($text)?;
82 let rows = stmt.query(())?;
83 while let Some(row) = rows.next()? {
84 row_cb(row)?;
85 }
86 Ok(())
87 }
88 };
89 ( ? $name:ident () ($($fn_params:tt)+) () => ($(: $arg:ident)+) $($text:tt)+) => {
90 fn $name<F>(&self $($fn_params)+ , mut row_cb: F) -> ::sibyl::Result<()>
91 where F: FnMut(::sibyl::Row) -> ::sibyl::Result<()>
92 {
93 let stmt = self.prepare( $crate::sql_literal!( $($text)+ ) )?;
94 let rows = stmt.query( $crate::util::map!( $($arg)+ => $($text)+ ) )?;
95 while let Some(row) = rows.next()? {
96 row_cb(row)?;
97 }
98 Ok(())
99 }
100 };
101 ( ? $name:ident ($($gen_type:ident)*) ($($fn_params:tt)+) () => ($($pv:tt $arg:ident)+) $($text:tt)+) => {
102 fn $name<$($gen_type : ::sibyl::ToSql ,)* F>(&self $($fn_params)+, mut row_cb: F) -> ::sibyl::Result<()>
103 where F: FnMut(::sibyl::Row) -> ::sibyl::Result<()>
104 {
105 let mut stmt = ::std::string::String::with_capacity( $crate::sql_len!($($text)+) );
106 let mut i = 0;
107 $crate::dynamic_sql!(stmt i $($text)+);
108 let stmt = self.prepare(&stmt)?;
109 let rows = stmt.query( $crate::util::map!( $($arg)+ => $($text)+ ) )?;
110 while let Some(row) = rows.next()? {
111 row_cb(row)?;
112 }
113 Ok(())
114 }
115 };
116
117 ( ! $name:ident () () () => () $text:literal ) => {
118 fn $name(&self) -> ::sibyl::Result<usize> {
119 let stmt = self.prepare($text)?;
120 stmt.execute(())
121 }
122 };
123 ( ! $name:ident () ($($fn_params:tt)+) () => ($(: $arg:ident)+) $($text:tt)+) => {
124 fn $name(&self $($fn_params)+) -> ::sibyl::Result<usize> {
125 let stmt = self.prepare( $crate::sql_literal!( $($text)+ ) )?;
126 stmt.execute( $crate::util::map!( $($arg)+ => $($text)+ ) )
127 }
128 };
129 ( ! $name:ident ($($gen_type:ident)*) ($($fn_params:tt)+) () => ($($pv:tt $arg:ident)+) $($text:tt)+) => {
130 fn $name<$($gen_type : ::sibyl::ToSql),*>(&self $($fn_params)+ ) -> ::sibyl::Result<usize> {
131 let mut stmt = ::std::string::String::with_capacity( $crate::sql_len!($($text)+) );
132 let mut i = 0;
133 $crate::dynamic_sql!(stmt i $($text)+);
134 let stmt = self.prepare(&stmt)?;
135 stmt.execute( $crate::util::map!( $($arg)+ => $($text)+ ) )
136 }
137 };
138
139 ( . $name:ident ($($gen_type:ident)*) ($($fn_params:tt)*) () => ($($pv:tt $arg:ident)*) $($text:tt)+) => {
140 fn $name(&self) -> ::sibyl::Result<::sibyl::Statement> {
141 self.prepare( $crate::sql_literal!( $($text)+ ) )
142 }
143 };
144
145 ( $kind:tt $name:ident ($($gen_type:ident)*) ($($fn_params:tt)*) ($param:ident : _ $($tail:tt)*) => ($($pv:tt $param_name:ident)+) $($text:tt)+) => {
146 $crate::impl_method!{
147 $kind
148 $name
149 ($($gen_type)*)
150 ($($fn_params)* , $param : impl ::sibyl::ToSql)
151 ($($tail)*)
152 =>
153 ($($pv $param_name)+)
154 $($text)+
155 }
156 };
157 ( $kind:tt $name:ident ($($gen_type:ident)*) ($($fn_params:tt)*) ($param:ident : ($ptype:ty) $($tail:tt)*) => ($($pv:tt $param_name:ident)+) $($text:tt)+) => {
158 $crate::impl_method!{
159 $kind
160 $name
161 ($($gen_type)*)
162 ($($fn_params)* , $param : $ptype)
163 ($($tail)*)
164 =>
165 ($($pv $param_name)+)
166 $($text)+
167 }
168 };
169 ( $kind:tt $name:ident ($($gen_type:ident)*) ($($fn_params:tt)*) ($param:ident # [$gtype:ident] $($tail:tt)*) => ($($pv:tt $param_name:ident)+) $($text:tt)+) => {
170 $crate::impl_method!{
171 $kind
172 $name
173 ($($gen_type)* $gtype)
174 ($($fn_params)* , $param : & [ $gtype ])
175 ($($tail)*)
176 =>
177 ($($pv $param_name)+)
178 $($text)+
179 }
180 };
181 ( $kind:tt $name:ident ($($gen_type:ident)*) ($($fn_params:tt)*) ($param:ident # ($ptype:ty) $($tail:tt)*) => ($($pv:tt $param_name:ident)+) $($text:tt)+) => {
182 $crate::impl_method!{
183 $kind
184 $name
185 ($($gen_type)*)
186 ($($fn_params)* , $param : & [ $ptype ])
187 ($($tail)*)
188 =>
189 ($($pv $param_name)+)
190 $($text)+
191 }
192 };
193}