Skip to repository content

tenant.openagents/omega

No repository description is available.

OpenAgents Git authority 2026-07-28T02:53:51.566Z Public web read
NIP-34 coordinate30617:7649603503856e5148d571eac2766b288a8ff1e9e35d380337a1d2b0015b4f92:omega
MaintainersHidden in public view
References2 branches · 1 tag
Read-only clonegit clone https://openagents.com/git/tenant.openagents/omega.git
Browse files

query.rs

315 lines · 13.3 KB · rust
1#[macro_export]
2macro_rules! query {
3    ($vis:vis fn $id:ident() -> Result<()> { $($sql:tt)+ }) => {
4        $vis fn $id(&self) -> $crate::anyhow::Result<()> {
5            use $crate::anyhow::Context;
6
7            let sql_stmt = $crate::sqlez_macros::sql!($($sql)+);
8
9            self.exec(sql_stmt)?().context(::std::format!(
10                "Error in {}, exec failed to execute or parse for: {}",
11                ::std::stringify!($id),
12                sql_stmt,
13            ))
14        }
15    };
16    ($vis:vis async fn $id:ident() -> Result<()> { $($sql:tt)+ }) => {
17        $vis async fn $id(&self) -> $crate::anyhow::Result<()> {
18            use $crate::anyhow::Context;
19
20            self.write(|connection| {
21                let sql_stmt = $crate::sqlez_macros::sql!($($sql)+);
22
23                connection.exec(sql_stmt)?().context(::std::format!(
24                    "Error in {}, exec failed to execute or parse for: {}",
25                    ::std::stringify!($id),
26                    sql_stmt
27                ))
28            }).await
29        }
30    };
31    ($vis:vis fn $id:ident($($arg:ident: $arg_type:ty),+) -> Result<()> { $($sql:tt)+ }) => {
32        $vis fn $id(&self, $($arg: $arg_type),+) -> $crate::anyhow::Result<()> {
33            use $crate::anyhow::Context;
34
35            let sql_stmt = $crate::sqlez_macros::sql!($($sql)+);
36
37            self.exec_bound::<($($arg_type),+)>(sql_stmt)?(($($arg),+))
38                .context(::std::format!(
39                    "Error in {}, exec_bound failed to execute or parse for: {}",
40                    ::std::stringify!($id),
41                    sql_stmt
42                ))
43        }
44    };
45    ($vis:vis async fn $id:ident($arg:ident: $arg_type:ty) -> Result<()> { $($sql:tt)+ }) => {
46        $vis async fn $id(&self, $arg: $arg_type) -> $crate::anyhow::Result<()> {
47            use $crate::anyhow::Context;
48
49            self.write(move |connection| {
50                let sql_stmt = $crate::sqlez_macros::sql!($($sql)+);
51
52                connection.exec_bound::<$arg_type>(sql_stmt)?($arg)
53                    .context(::std::format!(
54                        "Error in {}, exec_bound failed to execute or parse for: {}",
55                        ::std::stringify!($id),
56                        sql_stmt
57                    ))
58            }).await
59        }
60    };
61    ($vis:vis async fn $id:ident($($arg:ident: $arg_type:ty),+) -> Result<()> { $($sql:tt)+ }) => {
62        $vis async fn $id(&self, $($arg: $arg_type),+) -> $crate::anyhow::Result<()> {
63            use $crate::anyhow::Context;
64
65            self.write(move |connection| {
66                let sql_stmt = $crate::sqlez_macros::sql!($($sql)+);
67
68                connection.exec_bound::<($($arg_type),+)>(sql_stmt)?(($($arg),+))
69                    .context(::std::format!(
70                        "Error in {}, exec_bound failed to execute or parse for: {}",
71                        ::std::stringify!($id),
72                        sql_stmt
73                    ))
74            }).await
75        }
76    };
77    ($vis:vis fn $id:ident() ->  Result<Vec<$return_type:ty>> { $($sql:tt)+ }) => {
78        $vis fn $id(&self) -> $crate::anyhow::Result<Vec<$return_type>> {
79            use $crate::anyhow::Context;
80
81            let sql_stmt = $crate::sqlez_macros::sql!($($sql)+);
82
83            self.select::<$return_type>(sql_stmt)?()
84                .context(::std::format!(
85                    "Error in {}, select_row failed to execute or parse for: {}",
86                    ::std::stringify!($id),
87                    sql_stmt
88                ))
89        }
90    };
91    ($vis:vis async fn $id:ident() -> Result<Vec<$return_type:ty>> { $($sql:tt)+ }) => {
92        pub async fn $id(&self) -> $crate::anyhow::Result<Vec<$return_type>> {
93            use $crate::anyhow::Context;
94
95            self.write(|connection| {
96                let sql_stmt = $crate::sqlez_macros::sql!($($sql)+);
97
98                connection.select::<$return_type>(sql_stmt)?()
99                    .context(::std::format!(
100                        "Error in {}, select_row failed to execute or parse for: {}",
101                        ::std::stringify!($id),
102                        sql_stmt
103                    ))
104            }).await
105        }
106    };
107    ($vis:vis fn $id:ident($($arg:ident: $arg_type:ty),+) -> Result<Vec<$return_type:ty>> { $($sql:tt)+ }) => {
108        $vis fn $id(&self, $($arg: $arg_type),+) -> $crate::anyhow::Result<Vec<$return_type>> {
109            use $crate::anyhow::Context;
110
111            let sql_stmt = $crate::sqlez_macros::sql!($($sql)+);
112
113            self.select_bound::<($($arg_type),+), $return_type>(sql_stmt)?(($($arg),+))
114                .context(::std::format!(
115                    "Error in {}, exec_bound failed to execute or parse for: {}",
116                    ::std::stringify!($id),
117                    sql_stmt
118                ))
119        }
120    };
121    ($vis:vis async fn $id:ident($($arg:ident: $arg_type:ty),+) -> Result<Vec<$return_type:ty>> { $($sql:tt)+ }) => {
122        $vis async fn $id(&self, $($arg: $arg_type),+) -> $crate::anyhow::Result<Vec<$return_type>> {
123            use $crate::anyhow::Context;
124
125            self.write(|connection| {
126                let sql_stmt = $crate::sqlez_macros::sql!($($sql)+);
127
128                connection.select_bound::<($($arg_type),+), $return_type>(sql_stmt)?(($($arg),+))
129                    .context(::std::format!(
130                        "Error in {}, exec_bound failed to execute or parse for: {}",
131                        ::std::stringify!($id),
132                        sql_stmt
133                    ))
134            }).await
135        }
136    };
137    ($vis:vis fn $id:ident() ->  Result<Option<$return_type:ty>> { $($sql:tt)+ }) => {
138        $vis fn $id(&self) -> $crate::anyhow::Result<Option<$return_type>> {
139            use $crate::anyhow::Context;
140
141            let sql_stmt = $crate::sqlez_macros::sql!($($sql)+);
142
143            self.select_row::<$return_type>(sql_stmt)?()
144                .context(::std::format!(
145                    "Error in {}, select_row failed to execute or parse for: {}",
146                    ::std::stringify!($id),
147                    sql_stmt
148                ))
149        }
150    };
151    ($vis:vis async fn $id:ident() ->  Result<Option<$return_type:ty>> { $($sql:tt)+ }) => {
152        $vis async fn $id(&self) -> $crate::anyhow::Result<Option<$return_type>> {
153            use $crate::anyhow::Context;
154
155            self.write(|connection| {
156                let sql_stmt = $crate::sqlez_macros::sql!($($sql)+);
157
158                connection.select_row::<$return_type>(sql_stmt)?()
159                    .context(::std::format!(
160                        "Error in {}, select_row failed to execute or parse for: {}",
161                        ::std::stringify!($id),
162                        sql_stmt
163                    ))
164            }).await
165        }
166    };
167    ($vis:vis fn $id:ident($arg:ident: $arg_type:ty) ->  Result<Option<$return_type:ty>> { $($sql:tt)+ }) => {
168        $vis fn $id(&self, $arg: $arg_type) -> $crate::anyhow::Result<Option<$return_type>>  {
169            use $crate::anyhow::Context;
170
171            let sql_stmt = $crate::sqlez_macros::sql!($($sql)+);
172
173            self.select_row_bound::<$arg_type, $return_type>(sql_stmt)?($arg)
174                .context(::std::format!(
175                    "Error in {}, select_row_bound failed to execute or parse for: {}",
176                    ::std::stringify!($id),
177                    sql_stmt
178                ))
179
180        }
181    };
182    ($vis:vis fn $id:ident($($arg:ident: $arg_type:ty),+) ->  Result<Option<$return_type:ty>> { $($sql:tt)+ }) => {
183        $vis fn $id(&self, $($arg: $arg_type),+) -> $crate::anyhow::Result<Option<$return_type>>  {
184            use $crate::anyhow::Context;
185
186            let sql_stmt = $crate::sqlez_macros::sql!($($sql)+);
187
188            self.select_row_bound::<($($arg_type),+), $return_type>(sql_stmt)?(($($arg),+))
189                .context(::std::format!(
190                    "Error in {}, select_row_bound failed to execute or parse for: {}",
191                    ::std::stringify!($id),
192                    sql_stmt
193                ))
194
195        }
196    };
197    ($vis:vis async fn $id:ident($($arg:ident: $arg_type:ty),+) ->  Result<Option<$return_type:ty>> { $($sql:tt)+ }) => {
198        $vis async fn $id(&self, $($arg: $arg_type),+) -> $crate::anyhow::Result<Option<$return_type>>  {
199            use $crate::anyhow::Context;
200
201
202            self.write(move |connection| {
203                let sql_stmt = $crate::sqlez_macros::sql!($($sql)+);
204
205                connection.select_row_bound::<($($arg_type),+), $return_type>(sql_stmt)?(($($arg),+))
206                    .context(::std::format!(
207                        "Error in {}, select_row_bound failed to execute or parse for: {}",
208                        ::std::stringify!($id),
209                        sql_stmt
210                    ))
211            }).await
212        }
213    };
214    ($vis:vis fn $id:ident() ->  Result<$return_type:ty> { $($sql:tt)+ }) => {
215        $vis fn $id(&self) ->  $crate::anyhow::Result<$return_type>  {
216            use $crate::anyhow::Context;
217
218            let sql_stmt = $crate::sqlez_macros::sql!($($sql)+);
219
220            self.select_row::<$return_type>(sql_stmt)?()
221                .context(::std::format!(
222                    "Error in {}, select_row_bound failed to execute or parse for: {}",
223                    ::std::stringify!($id),
224                    sql_stmt
225                ))?
226                .context(::std::format!(
227                    "Error in {}, select_row_bound expected single row result but found none for: {}",
228                    ::std::stringify!($id),
229                    sql_stmt
230                ))
231        }
232    };
233    ($vis:vis async fn $id:ident() ->  Result<$return_type:ty> { $($sql:tt)+ }) => {
234        $vis async fn $id(&self) ->  $crate::anyhow::Result<$return_type>  {
235            use $crate::anyhow::Context;
236
237            self.write(|connection| {
238                let sql_stmt = $crate::sqlez_macros::sql!($($sql)+);
239
240                connection.select_row::<$return_type>(sql_stmt)?()
241                    .context(::std::format!(
242                        "Error in {}, select_row_bound failed to execute or parse for: {}",
243                        ::std::stringify!($id),
244                        sql_stmt
245                    ))?
246                    .context(::std::format!(
247                        "Error in {}, select_row_bound expected single row result but found none for: {}",
248                        ::std::stringify!($id),
249                        sql_stmt
250                    ))
251            }).await
252        }
253    };
254    ($vis:vis fn $id:ident($arg:ident: $arg_type:ty) ->  Result<$return_type:ty> { $($sql:tt)+ }) => {
255        pub fn $id(&self, $arg: $arg_type) ->  $crate::anyhow::Result<$return_type>  {
256            use $crate::anyhow::Context;
257
258            let sql_stmt = $crate::sqlez_macros::sql!($($sql)+);
259
260            self.select_row_bound::<$arg_type, $return_type>(sql_stmt)?($arg)
261                .context(::std::format!(
262                    "Error in {}, select_row_bound failed to execute or parse for: {}",
263                    ::std::stringify!($id),
264                    sql_stmt
265                ))?
266                .context(::std::format!(
267                    "Error in {}, select_row_bound expected single row result but found none for: {}",
268                    ::std::stringify!($id),
269                    sql_stmt
270                ))
271        }
272    };
273    ($vis:vis fn $id:ident($($arg:ident: $arg_type:ty),+) ->  Result<$return_type:ty> { $($sql:tt)+ }) => {
274        $vis fn $id(&self, $($arg: $arg_type),+) ->  $crate::anyhow::Result<$return_type>  {
275            use $crate::anyhow::Context;
276
277            let sql_stmt = $crate::sqlez_macros::sql!($($sql)+);
278
279            self.select_row_bound::<($($arg_type),+), $return_type>(sql_stmt)?(($($arg),+))
280                .context(::std::format!(
281                    "Error in {}, select_row_bound failed to execute or parse for: {}",
282                    ::std::stringify!($id),
283                    sql_stmt
284                ))?
285                .context(::std::format!(
286                    "Error in {}, select_row_bound expected single row result but found none for: {}",
287                    ::std::stringify!($id),
288                    sql_stmt
289                ))
290        }
291    };
292    ($vis:vis fn async $id:ident($($arg:ident: $arg_type:ty),+) ->  Result<$return_type:ty> { $($sql:tt)+ }) => {
293        $vis async fn $id(&self, $($arg: $arg_type),+) ->  $crate::anyhow::Result<$return_type>  {
294            use $crate::anyhow::Context;
295
296
297            self.write(|connection| {
298                let sql_stmt = $crate::sqlez_macros::sql!($($sql)+);
299
300                connection.select_row_bound::<($($arg_type),+), $return_type>(sql_stmt)?(($($arg),+))
301                    .context(::std::format!(
302                        "Error in {}, select_row_bound failed to execute or parse for: {}",
303                        ::std::stringify!($id),
304                        sql_stmt
305                    ))?
306                    .context(::std::format!(
307                        "Error in {}, select_row_bound expected single row result but found none for: {}",
308                        ::std::stringify!($id),
309                        sql_stmt
310                    ))
311            }).await
312        }
313    };
314}
315
Served at tenant.openagents/omega Member data and write actions are omitted.