Skip to main content

postgres_static_analyzer_reflect_queries/queries/
manual.rs

1// This file was generated with `clorinde`. Do not modify.
2
3#[derive(Debug, Clone, PartialEq)]
4pub struct ReflectPgDbRoleSetting {
5    pub setdatabase: bool,
6    pub setrole: Option<String>,
7    pub setconfig: Option<Vec<String>>,
8}
9pub struct ReflectPgDbRoleSettingBorrowed<'a> {
10    pub setdatabase: bool,
11    pub setrole: Option<&'a str>,
12    pub setconfig: Option<crate::ArrayIterator<'a, &'a str>>,
13}
14impl<'a> From<ReflectPgDbRoleSettingBorrowed<'a>> for ReflectPgDbRoleSetting {
15    fn from(
16        ReflectPgDbRoleSettingBorrowed {
17            setdatabase,
18            setrole,
19            setconfig,
20        }: ReflectPgDbRoleSettingBorrowed<'a>,
21    ) -> Self {
22        Self {
23            setdatabase,
24            setrole: setrole.map(|v| v.into()),
25            setconfig: setconfig.map(|v| v.map(|v| v.into()).collect()),
26        }
27    }
28}
29#[derive(Debug, Clone, PartialEq)]
30pub struct ReflectPgEnum {
31    pub enumtypid: String,
32    pub enumlabels: Vec<String>,
33}
34pub struct ReflectPgEnumBorrowed<'a> {
35    pub enumtypid: &'a str,
36    pub enumlabels: crate::ArrayIterator<'a, &'a str>,
37}
38impl<'a> From<ReflectPgEnumBorrowed<'a>> for ReflectPgEnum {
39    fn from(
40        ReflectPgEnumBorrowed {
41            enumtypid,
42            enumlabels,
43        }: ReflectPgEnumBorrowed<'a>,
44    ) -> Self {
45        Self {
46            enumtypid: enumtypid.into(),
47            enumlabels: enumlabels.map(|v| v.into()).collect(),
48        }
49    }
50}
51#[derive(Debug, Clone, PartialEq)]
52pub struct ReflectPgProc {
53    pub oid: String,
54    pub proname: String,
55    pub pronamespace: String,
56    pub proowner: String,
57    pub prolang: String,
58    pub procost: Option<f32>,
59    pub prorows: Option<f32>,
60    pub provariadic: Option<String>,
61    pub prosupport: Option<String>,
62    pub prokind: i8,
63    pub prosecdef: bool,
64    pub proleakproof: bool,
65    pub proisstrict: bool,
66    pub proretset: bool,
67    pub provolatile: i8,
68    pub proparallel: i8,
69    pub pronargs: i16,
70    pub pronargdefaults: i16,
71    pub prorettype: String,
72    pub proargtypes: Vec<String>,
73    pub proallargtypes: Option<Vec<String>>,
74    pub proargmodes: Option<Vec<i8>>,
75    pub proargnames: Option<Vec<String>>,
76    pub proargdefaults: Option<Vec<Option<String>>>,
77    pub protrftypes: Option<Vec<String>>,
78    pub prosrc: Option<String>,
79    pub probin: Option<String>,
80    pub prosqlbody: Option<String>,
81    pub proconfig: Option<Vec<String>>,
82    pub proacl: Option<Vec<crate::types::pg_temp_1::FunctionAclitem>>,
83    pub description: Option<String>,
84}
85pub struct ReflectPgProcBorrowed<'a> {
86    pub oid: &'a str,
87    pub proname: &'a str,
88    pub pronamespace: &'a str,
89    pub proowner: &'a str,
90    pub prolang: &'a str,
91    pub procost: Option<f32>,
92    pub prorows: Option<f32>,
93    pub provariadic: Option<&'a str>,
94    pub prosupport: Option<&'a str>,
95    pub prokind: i8,
96    pub prosecdef: bool,
97    pub proleakproof: bool,
98    pub proisstrict: bool,
99    pub proretset: bool,
100    pub provolatile: i8,
101    pub proparallel: i8,
102    pub pronargs: i16,
103    pub pronargdefaults: i16,
104    pub prorettype: &'a str,
105    pub proargtypes: crate::ArrayIterator<'a, &'a str>,
106    pub proallargtypes: Option<crate::ArrayIterator<'a, &'a str>>,
107    pub proargmodes: Option<crate::ArrayIterator<'a, i8>>,
108    pub proargnames: Option<crate::ArrayIterator<'a, &'a str>>,
109    pub proargdefaults: Option<crate::ArrayIterator<'a, Option<&'a str>>>,
110    pub protrftypes: Option<crate::ArrayIterator<'a, &'a str>>,
111    pub prosrc: Option<&'a str>,
112    pub probin: Option<&'a str>,
113    pub prosqlbody: Option<&'a str>,
114    pub proconfig: Option<crate::ArrayIterator<'a, &'a str>>,
115    pub proacl:
116        Option<crate::ArrayIterator<'a, crate::types::pg_temp_1::FunctionAclitemBorrowed<'a>>>,
117    pub description: Option<&'a str>,
118}
119impl<'a> From<ReflectPgProcBorrowed<'a>> for ReflectPgProc {
120    fn from(
121        ReflectPgProcBorrowed {
122            oid,
123            proname,
124            pronamespace,
125            proowner,
126            prolang,
127            procost,
128            prorows,
129            provariadic,
130            prosupport,
131            prokind,
132            prosecdef,
133            proleakproof,
134            proisstrict,
135            proretset,
136            provolatile,
137            proparallel,
138            pronargs,
139            pronargdefaults,
140            prorettype,
141            proargtypes,
142            proallargtypes,
143            proargmodes,
144            proargnames,
145            proargdefaults,
146            protrftypes,
147            prosrc,
148            probin,
149            prosqlbody,
150            proconfig,
151            proacl,
152            description,
153        }: ReflectPgProcBorrowed<'a>,
154    ) -> Self {
155        Self {
156            oid: oid.into(),
157            proname: proname.into(),
158            pronamespace: pronamespace.into(),
159            proowner: proowner.into(),
160            prolang: prolang.into(),
161            procost,
162            prorows,
163            provariadic: provariadic.map(|v| v.into()),
164            prosupport: prosupport.map(|v| v.into()),
165            prokind,
166            prosecdef,
167            proleakproof,
168            proisstrict,
169            proretset,
170            provolatile,
171            proparallel,
172            pronargs,
173            pronargdefaults,
174            prorettype: prorettype.into(),
175            proargtypes: proargtypes.map(|v| v.into()).collect(),
176            proallargtypes: proallargtypes.map(|v| v.map(|v| v.into()).collect()),
177            proargmodes: proargmodes.map(|v| v.map(|v| v).collect()),
178            proargnames: proargnames.map(|v| v.map(|v| v.into()).collect()),
179            proargdefaults: proargdefaults.map(|v| v.map(|v| v.map(|v| v.into())).collect()),
180            protrftypes: protrftypes.map(|v| v.map(|v| v.into()).collect()),
181            prosrc: prosrc.map(|v| v.into()),
182            probin: probin.map(|v| v.into()),
183            prosqlbody: prosqlbody.map(|v| v.into()),
184            proconfig: proconfig.map(|v| v.map(|v| v.into()).collect()),
185            proacl: proacl.map(|v| v.map(|v| v.into()).collect()),
186            description: description.map(|v| v.into()),
187        }
188    }
189}
190use crate::client::async_::GenericClient;
191use futures::{self, StreamExt, TryStreamExt};
192pub struct ReflectPgDbRoleSettingQuery<'c, 'a, 's, C: GenericClient, T, const N: usize> {
193    client: &'c C,
194    params: [&'a (dyn postgres_types::ToSql + Sync); N],
195    query: &'static str,
196    cached: Option<&'s tokio_postgres::Statement>,
197    extractor:
198        fn(&tokio_postgres::Row) -> Result<ReflectPgDbRoleSettingBorrowed, tokio_postgres::Error>,
199    mapper: fn(ReflectPgDbRoleSettingBorrowed) -> T,
200}
201impl<'c, 'a, 's, C, T: 'c, const N: usize> ReflectPgDbRoleSettingQuery<'c, 'a, 's, C, T, N>
202where
203    C: GenericClient,
204{
205    pub fn map<R>(
206        self,
207        mapper: fn(ReflectPgDbRoleSettingBorrowed) -> R,
208    ) -> ReflectPgDbRoleSettingQuery<'c, 'a, 's, C, R, N> {
209        ReflectPgDbRoleSettingQuery {
210            client: self.client,
211            params: self.params,
212            query: self.query,
213            cached: self.cached,
214            extractor: self.extractor,
215            mapper,
216        }
217    }
218    pub async fn one(self) -> Result<T, tokio_postgres::Error> {
219        let row =
220            crate::client::async_::one(self.client, self.query, &self.params, self.cached).await?;
221        Ok((self.mapper)((self.extractor)(&row)?))
222    }
223    pub async fn all(self) -> Result<Vec<T>, tokio_postgres::Error> {
224        self.iter().await?.try_collect().await
225    }
226    pub async fn opt(self) -> Result<Option<T>, tokio_postgres::Error> {
227        let opt_row =
228            crate::client::async_::opt(self.client, self.query, &self.params, self.cached).await?;
229        Ok(opt_row
230            .map(|row| {
231                let extracted = (self.extractor)(&row)?;
232                Ok((self.mapper)(extracted))
233            })
234            .transpose()?)
235    }
236    pub async fn iter(
237        self,
238    ) -> Result<
239        impl futures::Stream<Item = Result<T, tokio_postgres::Error>> + 'c,
240        tokio_postgres::Error,
241    > {
242        let stream = crate::client::async_::raw(
243            self.client,
244            self.query,
245            crate::slice_iter(&self.params),
246            self.cached,
247        )
248        .await?;
249        let mapped = stream
250            .map(move |res| {
251                res.and_then(|row| {
252                    let extracted = (self.extractor)(&row)?;
253                    Ok((self.mapper)(extracted))
254                })
255            })
256            .into_stream();
257        Ok(mapped)
258    }
259}
260pub struct ReflectPgEnumQuery<'c, 'a, 's, C: GenericClient, T, const N: usize> {
261    client: &'c C,
262    params: [&'a (dyn postgres_types::ToSql + Sync); N],
263    query: &'static str,
264    cached: Option<&'s tokio_postgres::Statement>,
265    extractor: fn(&tokio_postgres::Row) -> Result<ReflectPgEnumBorrowed, tokio_postgres::Error>,
266    mapper: fn(ReflectPgEnumBorrowed) -> T,
267}
268impl<'c, 'a, 's, C, T: 'c, const N: usize> ReflectPgEnumQuery<'c, 'a, 's, C, T, N>
269where
270    C: GenericClient,
271{
272    pub fn map<R>(
273        self,
274        mapper: fn(ReflectPgEnumBorrowed) -> R,
275    ) -> ReflectPgEnumQuery<'c, 'a, 's, C, R, N> {
276        ReflectPgEnumQuery {
277            client: self.client,
278            params: self.params,
279            query: self.query,
280            cached: self.cached,
281            extractor: self.extractor,
282            mapper,
283        }
284    }
285    pub async fn one(self) -> Result<T, tokio_postgres::Error> {
286        let row =
287            crate::client::async_::one(self.client, self.query, &self.params, self.cached).await?;
288        Ok((self.mapper)((self.extractor)(&row)?))
289    }
290    pub async fn all(self) -> Result<Vec<T>, tokio_postgres::Error> {
291        self.iter().await?.try_collect().await
292    }
293    pub async fn opt(self) -> Result<Option<T>, tokio_postgres::Error> {
294        let opt_row =
295            crate::client::async_::opt(self.client, self.query, &self.params, self.cached).await?;
296        Ok(opt_row
297            .map(|row| {
298                let extracted = (self.extractor)(&row)?;
299                Ok((self.mapper)(extracted))
300            })
301            .transpose()?)
302    }
303    pub async fn iter(
304        self,
305    ) -> Result<
306        impl futures::Stream<Item = Result<T, tokio_postgres::Error>> + 'c,
307        tokio_postgres::Error,
308    > {
309        let stream = crate::client::async_::raw(
310            self.client,
311            self.query,
312            crate::slice_iter(&self.params),
313            self.cached,
314        )
315        .await?;
316        let mapped = stream
317            .map(move |res| {
318                res.and_then(|row| {
319                    let extracted = (self.extractor)(&row)?;
320                    Ok((self.mapper)(extracted))
321                })
322            })
323            .into_stream();
324        Ok(mapped)
325    }
326}
327pub struct ReflectPgProcQuery<'c, 'a, 's, C: GenericClient, T, const N: usize> {
328    client: &'c C,
329    params: [&'a (dyn postgres_types::ToSql + Sync); N],
330    query: &'static str,
331    cached: Option<&'s tokio_postgres::Statement>,
332    extractor: fn(&tokio_postgres::Row) -> Result<ReflectPgProcBorrowed, tokio_postgres::Error>,
333    mapper: fn(ReflectPgProcBorrowed) -> T,
334}
335impl<'c, 'a, 's, C, T: 'c, const N: usize> ReflectPgProcQuery<'c, 'a, 's, C, T, N>
336where
337    C: GenericClient,
338{
339    pub fn map<R>(
340        self,
341        mapper: fn(ReflectPgProcBorrowed) -> R,
342    ) -> ReflectPgProcQuery<'c, 'a, 's, C, R, N> {
343        ReflectPgProcQuery {
344            client: self.client,
345            params: self.params,
346            query: self.query,
347            cached: self.cached,
348            extractor: self.extractor,
349            mapper,
350        }
351    }
352    pub async fn one(self) -> Result<T, tokio_postgres::Error> {
353        let row =
354            crate::client::async_::one(self.client, self.query, &self.params, self.cached).await?;
355        Ok((self.mapper)((self.extractor)(&row)?))
356    }
357    pub async fn all(self) -> Result<Vec<T>, tokio_postgres::Error> {
358        self.iter().await?.try_collect().await
359    }
360    pub async fn opt(self) -> Result<Option<T>, tokio_postgres::Error> {
361        let opt_row =
362            crate::client::async_::opt(self.client, self.query, &self.params, self.cached).await?;
363        Ok(opt_row
364            .map(|row| {
365                let extracted = (self.extractor)(&row)?;
366                Ok((self.mapper)(extracted))
367            })
368            .transpose()?)
369    }
370    pub async fn iter(
371        self,
372    ) -> Result<
373        impl futures::Stream<Item = Result<T, tokio_postgres::Error>> + 'c,
374        tokio_postgres::Error,
375    > {
376        let stream = crate::client::async_::raw(
377            self.client,
378            self.query,
379            crate::slice_iter(&self.params),
380            self.cached,
381        )
382        .await?;
383        let mapped = stream
384            .map(move |res| {
385                res.and_then(|row| {
386                    let extracted = (self.extractor)(&row)?;
387                    Ok((self.mapper)(extracted))
388                })
389            })
390            .into_stream();
391        Ok(mapped)
392    }
393}
394pub struct ReflectPgDbRoleSettingStmt(&'static str, Option<tokio_postgres::Statement>);
395pub fn reflect_pg_db_role_setting() -> ReflectPgDbRoleSettingStmt {
396    ReflectPgDbRoleSettingStmt(
397        "select setdatabase != 0 as setdatabase, case when setrole = 0 then null else pg_get_userbyid(setrole)::text end as setrole, setconfig from pg_db_role_setting where (setdatabase = 0 or setdatabase = (select oid from pg_database where datname = current_database()))",
398        None,
399    )
400}
401impl ReflectPgDbRoleSettingStmt {
402    pub async fn prepare<'a, C: GenericClient>(
403        mut self,
404        client: &'a C,
405    ) -> Result<Self, tokio_postgres::Error> {
406        self.1 = Some(client.prepare(self.0).await?);
407        Ok(self)
408    }
409    pub fn bind<'c, 'a, 's, C: GenericClient>(
410        &'s self,
411        client: &'c C,
412    ) -> ReflectPgDbRoleSettingQuery<'c, 'a, 's, C, ReflectPgDbRoleSetting, 0> {
413        ReflectPgDbRoleSettingQuery {
414            client,
415            params: [],
416            query: self.0,
417            cached: self.1.as_ref(),
418            extractor: |
419                row: &tokio_postgres::Row,
420            | -> Result<ReflectPgDbRoleSettingBorrowed, tokio_postgres::Error> {
421                Ok(ReflectPgDbRoleSettingBorrowed {
422                    setdatabase: row.try_get(0)?,
423                    setrole: row.try_get(1)?,
424                    setconfig: row.try_get(2)?,
425                })
426            },
427            mapper: |it| ReflectPgDbRoleSetting::from(it),
428        }
429    }
430}
431pub struct ReflectPgEnumStmt(&'static str, Option<tokio_postgres::Statement>);
432pub fn reflect_pg_enum() -> ReflectPgEnumStmt {
433    ReflectPgEnumStmt(
434        "select enumtypid::regtype::text as enumtypid, array_agg(enumlabel::text order by enumsortorder) as enumlabels from pg_enum group by enumtypid",
435        None,
436    )
437}
438impl ReflectPgEnumStmt {
439    pub async fn prepare<'a, C: GenericClient>(
440        mut self,
441        client: &'a C,
442    ) -> Result<Self, tokio_postgres::Error> {
443        self.1 = Some(client.prepare(self.0).await?);
444        Ok(self)
445    }
446    pub fn bind<'c, 'a, 's, C: GenericClient>(
447        &'s self,
448        client: &'c C,
449    ) -> ReflectPgEnumQuery<'c, 'a, 's, C, ReflectPgEnum, 0> {
450        ReflectPgEnumQuery {
451            client,
452            params: [],
453            query: self.0,
454            cached: self.1.as_ref(),
455            extractor:
456                |row: &tokio_postgres::Row| -> Result<ReflectPgEnumBorrowed, tokio_postgres::Error> {
457                    Ok(ReflectPgEnumBorrowed {
458                        enumtypid: row.try_get(0)?,
459                        enumlabels: row.try_get(1)?,
460                    })
461                },
462            mapper: |it| ReflectPgEnum::from(it),
463        }
464    }
465}
466pub struct ReflectPgProcStmt(&'static str, Option<tokio_postgres::Statement>);
467pub fn reflect_pg_proc() -> ReflectPgProcStmt {
468    ReflectPgProcStmt(
469        "select pg_proc.oid::regprocedure::text as oid, pg_proc.proname::text as proname, pg_proc.pronamespace::regnamespace::text as pronamespace, pg_get_userbyid(proowner)::text as proowner, prolang_pg_language.lanname::text as prolang, pg_proc.procost as procost, pg_proc.prorows as prorows, case when pg_proc.provariadic = 0 then null else pg_proc.provariadic::regtype::text end as provariadic, case when prosupport = 0 then null else prosupport::regproc::text end as prosupport, pg_proc.prokind as prokind, pg_proc.prosecdef as prosecdef, pg_proc.proleakproof as proleakproof, pg_proc.proisstrict as proisstrict, pg_proc.proretset as proretset, pg_proc.provolatile as provolatile, pg_proc.proparallel as proparallel, pg_proc.pronargs as pronargs, pg_proc.pronargdefaults as pronargdefaults, pg_proc.prorettype::regtype::text as prorettype, pg_proc.proargtypes::regtype[]::text[] as proargtypes, pg_proc.proallargtypes::regtype[]::text[] as proallargtypes, pg_proc.proargmodes as proargmodes, pg_proc.proargnames as proargnames, case when pg_proc.proargdefaults is null then null else pg_temp.format_fn_defaults(pg_proc) end as proargdefaults, pg_proc.protrftypes::regtype[]::text[] as protrftypes, case when pg_proc.prosrc = '' then null else pg_proc.prosrc end as prosrc, case when pg_proc.probin = '' then null else pg_proc.probin end as probin, pg_get_function_sqlbody(pg_proc.oid) as prosqlbody, pg_proc.proconfig as proconfig, pg_temp.format_function_aclitems(proacl) as proacl, pg_description.description as description from pg_proc join pg_language as prolang_pg_language on pg_proc.prolang = prolang_pg_language.oid left join pg_description on pg_description.objoid = pg_proc.oid and pg_description.objsubid = 0 where not starts_with(pg_proc.pronamespace::regnamespace::text, 'pg_temp')",
470        None,
471    )
472}
473impl ReflectPgProcStmt {
474    pub async fn prepare<'a, C: GenericClient>(
475        mut self,
476        client: &'a C,
477    ) -> Result<Self, tokio_postgres::Error> {
478        self.1 = Some(client.prepare(self.0).await?);
479        Ok(self)
480    }
481    pub fn bind<'c, 'a, 's, C: GenericClient>(
482        &'s self,
483        client: &'c C,
484    ) -> ReflectPgProcQuery<'c, 'a, 's, C, ReflectPgProc, 0> {
485        ReflectPgProcQuery {
486            client,
487            params: [],
488            query: self.0,
489            cached: self.1.as_ref(),
490            extractor:
491                |row: &tokio_postgres::Row| -> Result<ReflectPgProcBorrowed, tokio_postgres::Error> {
492                    Ok(ReflectPgProcBorrowed {
493                        oid: row.try_get(0)?,
494                        proname: row.try_get(1)?,
495                        pronamespace: row.try_get(2)?,
496                        proowner: row.try_get(3)?,
497                        prolang: row.try_get(4)?,
498                        procost: row.try_get(5)?,
499                        prorows: row.try_get(6)?,
500                        provariadic: row.try_get(7)?,
501                        prosupport: row.try_get(8)?,
502                        prokind: row.try_get(9)?,
503                        prosecdef: row.try_get(10)?,
504                        proleakproof: row.try_get(11)?,
505                        proisstrict: row.try_get(12)?,
506                        proretset: row.try_get(13)?,
507                        provolatile: row.try_get(14)?,
508                        proparallel: row.try_get(15)?,
509                        pronargs: row.try_get(16)?,
510                        pronargdefaults: row.try_get(17)?,
511                        prorettype: row.try_get(18)?,
512                        proargtypes: row.try_get(19)?,
513                        proallargtypes: row.try_get(20)?,
514                        proargmodes: row.try_get(21)?,
515                        proargnames: row.try_get(22)?,
516                        proargdefaults: row.try_get(23)?,
517                        protrftypes: row.try_get(24)?,
518                        prosrc: row.try_get(25)?,
519                        probin: row.try_get(26)?,
520                        prosqlbody: row.try_get(27)?,
521                        proconfig: row.try_get(28)?,
522                        proacl: row.try_get(29)?,
523                        description: row.try_get(30)?,
524                    })
525                },
526            mapper: |it| ReflectPgProc::from(it),
527        }
528    }
529}