Skip to content

Commit e785a30

Browse files
Merge pull request #2477 from HTGAzureX1212/nightly
Initial Query Parsing, Disabling `cornucopia`
2 parents 4599309 + acb7f61 commit e785a30

25 files changed

+926
-1996
lines changed

database/hartex-database-queries/build.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub fn main() {
3131
return;
3232
}
3333

34-
let api_backend_queries_path = "queries/api_backend";
34+
/*let api_backend_queries_path = "queries/api_backend";
3535
println!("cargo::rerun-if-changed={api_backend_queries_path}");
3636
3737
let url = env::var("API_PGSQL_URL").unwrap();
@@ -74,7 +74,7 @@ pub fn main() {
7474
is_async: true,
7575
},
7676
)
77-
.unwrap();
77+
.unwrap();*/
7878

79-
hartex_database_typedsql::generate_queries_with_schemas("schemas", "", "").unwrap();
79+
hartex_database_typedsql::generate_queries_with_schemas("schemas", "queries", "").unwrap();
8080
}
Lines changed: 83 additions & 168 deletions
Original file line numberDiff line numberDiff line change
@@ -1,181 +1,96 @@
11
// This file was generated with `cornucopia`. Do not modify.
22

3-
#[allow(clippy::all, clippy::pedantic)]
4-
#[allow(unused_variables)]
5-
#[allow(unused_imports)]
6-
#[allow(dead_code)]
7-
pub mod types {}
8-
#[allow(clippy::all, clippy::pedantic)]
9-
#[allow(unused_variables)]
10-
#[allow(unused_imports)]
11-
#[allow(dead_code)]
12-
pub mod queries {
13-
pub mod start_timestamp_select_by_component {
14-
use cornucopia_async::GenericClient;
15-
use futures;
16-
use futures::{StreamExt, TryStreamExt};
17-
#[derive(Debug, Clone, PartialEq)]
18-
pub struct SelectStartTimestampByComponent {
19-
pub component: String,
20-
pub timestamp: time::OffsetDateTime,
21-
}
22-
pub struct SelectStartTimestampByComponentBorrowed<'a> {
23-
pub component: &'a str,
24-
pub timestamp: time::OffsetDateTime,
25-
}
26-
impl<'a> From<SelectStartTimestampByComponentBorrowed<'a>> for SelectStartTimestampByComponent {
27-
fn from(
28-
SelectStartTimestampByComponentBorrowed {
29-
component,
30-
timestamp,
31-
}: SelectStartTimestampByComponentBorrowed<'a>,
32-
) -> Self {
33-
Self {
34-
component: component.into(),
35-
timestamp,
36-
}
37-
}
38-
}
39-
pub struct SelectStartTimestampByComponentQuery<'a, C: GenericClient, T, const N: usize> {
40-
client: &'a C,
41-
params: [&'a (dyn postgres_types::ToSql + Sync); N],
42-
stmt: &'a mut cornucopia_async::private::Stmt,
43-
extractor: fn(&tokio_postgres::Row) -> SelectStartTimestampByComponentBorrowed,
44-
mapper: fn(SelectStartTimestampByComponentBorrowed) -> T,
45-
}
46-
impl<'a, C, T: 'a, const N: usize> SelectStartTimestampByComponentQuery<'a, C, T, N>
47-
where
48-
C: GenericClient,
3+
#[allow(clippy::all, clippy::pedantic)] #[allow(unused_variables)]
4+
#[allow(unused_imports)] #[allow(dead_code)] pub mod types { }#[allow(clippy::all, clippy::pedantic)] #[allow(unused_variables)]
5+
#[allow(unused_imports)] #[allow(dead_code)] pub mod queries
6+
{ pub mod start_timestamp_select_by_component
7+
{ use futures::{{StreamExt, TryStreamExt}};use futures; use cornucopia_async::GenericClient;#[derive( Debug, Clone, PartialEq,)] pub struct SelectStartTimestampByComponent
8+
{ pub component : String,pub timestamp : time::OffsetDateTime,}pub struct SelectStartTimestampByComponentBorrowed<'a> { pub component : &'a str,pub timestamp : time::OffsetDateTime,}
9+
impl<'a> From<SelectStartTimestampByComponentBorrowed<'a>> for SelectStartTimestampByComponent
10+
{
11+
fn from(SelectStartTimestampByComponentBorrowed { component,timestamp,}: SelectStartTimestampByComponentBorrowed<'a>) ->
12+
Self { Self { component: component.into(),timestamp,} }
13+
}pub struct SelectStartTimestampByComponentQuery<'a, C: GenericClient, T, const N: usize>
14+
{
15+
client: &'a C, params:
16+
[&'a (dyn postgres_types::ToSql + Sync); N], stmt: &'a mut
17+
cornucopia_async::private::Stmt, extractor: fn(&tokio_postgres::Row) -> SelectStartTimestampByComponentBorrowed,
18+
mapper: fn(SelectStartTimestampByComponentBorrowed) -> T,
19+
} impl<'a, C, T:'a, const N: usize> SelectStartTimestampByComponentQuery<'a, C, T, N> where C:
20+
GenericClient
21+
{
22+
pub fn map<R>(self, mapper: fn(SelectStartTimestampByComponentBorrowed) -> R) ->
23+
SelectStartTimestampByComponentQuery<'a,C,R,N>
24+
{
25+
SelectStartTimestampByComponentQuery
4926
{
50-
pub fn map<R>(
51-
self,
52-
mapper: fn(SelectStartTimestampByComponentBorrowed) -> R,
53-
) -> SelectStartTimestampByComponentQuery<'a, C, R, N> {
54-
SelectStartTimestampByComponentQuery {
55-
client: self.client,
56-
params: self.params,
57-
stmt: self.stmt,
58-
extractor: self.extractor,
59-
mapper,
60-
}
61-
}
62-
pub async fn one(self) -> Result<T, tokio_postgres::Error> {
63-
let stmt = self.stmt.prepare(self.client).await?;
64-
let row = self.client.query_one(stmt, &self.params).await?;
65-
Ok((self.mapper)((self.extractor)(&row)))
66-
}
67-
pub async fn all(self) -> Result<Vec<T>, tokio_postgres::Error> {
68-
self.iter().await?.try_collect().await
69-
}
70-
pub async fn opt(self) -> Result<Option<T>, tokio_postgres::Error> {
71-
let stmt = self.stmt.prepare(self.client).await?;
72-
Ok(self
73-
.client
74-
.query_opt(stmt, &self.params)
75-
.await?
76-
.map(|row| (self.mapper)((self.extractor)(&row))))
77-
}
78-
pub async fn iter(
79-
self,
80-
) -> Result<
81-
impl futures::Stream<Item = Result<T, tokio_postgres::Error>> + 'a,
82-
tokio_postgres::Error,
83-
> {
84-
let stmt = self.stmt.prepare(self.client).await?;
85-
let it = self
86-
.client
87-
.query_raw(stmt, cornucopia_async::private::slice_iter(&self.params))
88-
.await?
89-
.map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row))))
90-
.into_stream();
91-
Ok(it)
92-
}
27+
client: self.client, params: self.params, stmt: self.stmt,
28+
extractor: self.extractor, mapper,
9329
}
94-
pub fn select_start_timestamp_by_component() -> SelectStartTimestampByComponentStmt {
95-
SelectStartTimestampByComponentStmt(cornucopia_async::private::Stmt::new(
96-
"SELECT
30+
} pub async fn one(self) -> Result<T, tokio_postgres::Error>
31+
{
32+
let stmt = self.stmt.prepare(self.client).await?; let row =
33+
self.client.query_one(stmt, &self.params).await?;
34+
Ok((self.mapper)((self.extractor)(&row)))
35+
} pub async fn all(self) -> Result<Vec<T>, tokio_postgres::Error>
36+
{ self.iter().await?.try_collect().await } pub async fn opt(self) ->
37+
Result<Option<T>, tokio_postgres::Error>
38+
{
39+
let stmt = self.stmt.prepare(self.client).await?;
40+
Ok(self.client.query_opt(stmt, &self.params) .await?
41+
.map(|row| (self.mapper)((self.extractor)(&row))))
42+
} pub async fn iter(self,) -> Result<impl futures::Stream<Item = Result<T,
43+
tokio_postgres::Error>> + 'a, tokio_postgres::Error>
44+
{
45+
let stmt = self.stmt.prepare(self.client).await?; let it =
46+
self.client.query_raw(stmt,
47+
cornucopia_async::private::slice_iter(&self.params)) .await?
48+
.map(move |res|
49+
res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream();
50+
Ok(it)
51+
}
52+
}pub fn select_start_timestamp_by_component() -> SelectStartTimestampByComponentStmt
53+
{ SelectStartTimestampByComponentStmt(cornucopia_async::private::Stmt::new("SELECT
9754
*
9855
FROM
9956
\"APIBackend\".public.\"StartTimestamps\"
10057
WHERE
101-
\"component\" = $1",
102-
))
103-
}
104-
pub struct SelectStartTimestampByComponentStmt(cornucopia_async::private::Stmt);
105-
impl SelectStartTimestampByComponentStmt {
106-
pub fn bind<'a, C: GenericClient, T1: cornucopia_async::StringSql>(
107-
&'a mut self,
108-
client: &'a C,
109-
component: &'a T1,
110-
) -> SelectStartTimestampByComponentQuery<'a, C, SelectStartTimestampByComponent, 1>
111-
{
112-
SelectStartTimestampByComponentQuery {
113-
client,
114-
params: [component],
115-
stmt: &mut self.0,
116-
extractor: |row| SelectStartTimestampByComponentBorrowed {
117-
component: row.get(0),
118-
timestamp: row.get(1),
119-
},
120-
mapper: |it| <SelectStartTimestampByComponent>::from(it),
121-
}
122-
}
123-
}
58+
\"component\" = $1")) } pub struct
59+
SelectStartTimestampByComponentStmt(cornucopia_async::private::Stmt); impl SelectStartTimestampByComponentStmt
60+
{ pub fn bind<'a, C:
61+
GenericClient,T1:
62+
cornucopia_async::StringSql,>(&'a mut self, client: &'a C,
63+
component: &'a T1,) -> SelectStartTimestampByComponentQuery<'a,C,
64+
SelectStartTimestampByComponent, 1>
65+
{
66+
SelectStartTimestampByComponentQuery
67+
{
68+
client, params: [component,], stmt: &mut self.0, extractor:
69+
|row| { SelectStartTimestampByComponentBorrowed { component: row.get(0),timestamp: row.get(1),} }, mapper: |it| { <SelectStartTimestampByComponent>::from(it) },
12470
}
125-
pub mod start_timestamp_upsert {
126-
use cornucopia_async::GenericClient;
127-
use futures;
128-
use futures::{StreamExt, TryStreamExt};
129-
#[derive(Debug)]
130-
pub struct StartTimestampUpsertParams<T1: cornucopia_async::StringSql> {
131-
pub component: T1,
132-
pub timestamp: time::OffsetDateTime,
133-
}
134-
pub fn start_timestamp_upsert() -> StartTimestampUpsertStmt {
135-
StartTimestampUpsertStmt(cornucopia_async::private::Stmt::new(
136-
"INSERT INTO
71+
} }}pub mod start_timestamp_upsert
72+
{ use futures::{{StreamExt, TryStreamExt}};use futures; use cornucopia_async::GenericClient;#[derive( Debug)] pub struct StartTimestampUpsertParams<T1: cornucopia_async::StringSql,> { pub component: T1,pub timestamp: time::OffsetDateTime,}pub fn start_timestamp_upsert() -> StartTimestampUpsertStmt
73+
{ StartTimestampUpsertStmt(cornucopia_async::private::Stmt::new("INSERT INTO
13774
\"APIBackend\".public.\"StartTimestamps\" (\"component\", \"timestamp\")
13875
VALUES ($1, $2)
13976
ON CONFLICT (\"component\") DO UPDATE
14077
SET
141-
\"timestamp\" = $2",
142-
))
143-
}
144-
pub struct StartTimestampUpsertStmt(cornucopia_async::private::Stmt);
145-
impl StartTimestampUpsertStmt {
146-
pub async fn bind<'a, C: GenericClient, T1: cornucopia_async::StringSql>(
147-
&'a mut self,
148-
client: &'a C,
149-
component: &'a T1,
150-
timestamp: &'a time::OffsetDateTime,
151-
) -> Result<u64, tokio_postgres::Error> {
152-
let stmt = self.0.prepare(client).await?;
153-
client.execute(stmt, &[component, timestamp]).await
154-
}
155-
}
156-
impl<'a, C: GenericClient + Send + Sync, T1: cornucopia_async::StringSql>
157-
cornucopia_async::Params<
158-
'a,
159-
StartTimestampUpsertParams<T1>,
160-
std::pin::Pin<
161-
Box<
162-
dyn futures::Future<Output = Result<u64, tokio_postgres::Error>>
163-
+ Send
164-
+ 'a,
165-
>,
166-
>,
167-
C,
168-
> for StartTimestampUpsertStmt
169-
{
170-
fn params(
171-
&'a mut self,
172-
client: &'a C,
173-
params: &'a StartTimestampUpsertParams<T1>,
174-
) -> std::pin::Pin<
175-
Box<dyn futures::Future<Output = Result<u64, tokio_postgres::Error>> + Send + 'a>,
176-
> {
177-
Box::pin(self.bind(client, &params.component, &params.timestamp))
178-
}
179-
}
180-
}
181-
}
78+
\"timestamp\" = $2")) } pub struct
79+
StartTimestampUpsertStmt(cornucopia_async::private::Stmt); impl StartTimestampUpsertStmt
80+
{ pub async fn bind<'a, C:
81+
GenericClient,T1:
82+
cornucopia_async::StringSql,>(&'a mut self, client: &'a C,
83+
component: &'a T1,timestamp: &'a time::OffsetDateTime,) -> Result<u64, tokio_postgres::Error>
84+
{
85+
let stmt = self.0.prepare(client).await?;
86+
client.execute(stmt, &[component,timestamp,]).await
87+
} }impl <'a, C: GenericClient + Send + Sync, T1: cornucopia_async::StringSql,>
88+
cornucopia_async::Params<'a, StartTimestampUpsertParams<T1,>, std::pin::Pin<Box<dyn futures::Future<Output = Result<u64,
89+
tokio_postgres::Error>> + Send + 'a>>, C> for StartTimestampUpsertStmt
90+
{
91+
fn
92+
params(&'a mut self, client: &'a C, params: &'a
93+
StartTimestampUpsertParams<T1,>) -> std::pin::Pin<Box<dyn futures::Future<Output = Result<u64,
94+
tokio_postgres::Error>> + Send + 'a>>
95+
{ Box::pin(self.bind(client, &params.component,&params.timestamp,)) }
96+
}}}

0 commit comments

Comments
 (0)