Skip to content

Commit

Permalink
Merge pull request #2478 from HTGAzureX1212/nightly
Browse files Browse the repository at this point in the history
Update Queries and Delegate Parsing Individual Statements
  • Loading branch information
HTGAzureX1212 authored Dec 5, 2024
2 parents e785a30 + ef6044b commit 636e32c
Show file tree
Hide file tree
Showing 23 changed files with 2,352 additions and 786 deletions.
251 changes: 168 additions & 83 deletions database/hartex-database-queries/generated/api_backend.rs
Original file line number Diff line number Diff line change
@@ -1,96 +1,181 @@
// This file was generated with `cornucopia`. Do not modify.

#[allow(clippy::all, clippy::pedantic)] #[allow(unused_variables)]
#[allow(unused_imports)] #[allow(dead_code)] pub mod types { }#[allow(clippy::all, clippy::pedantic)] #[allow(unused_variables)]
#[allow(unused_imports)] #[allow(dead_code)] pub mod queries
{ pub mod start_timestamp_select_by_component
{ use futures::{{StreamExt, TryStreamExt}};use futures; use cornucopia_async::GenericClient;#[derive( Debug, Clone, PartialEq,)] pub struct SelectStartTimestampByComponent
{ pub component : String,pub timestamp : time::OffsetDateTime,}pub struct SelectStartTimestampByComponentBorrowed<'a> { pub component : &'a str,pub timestamp : time::OffsetDateTime,}
impl<'a> From<SelectStartTimestampByComponentBorrowed<'a>> for SelectStartTimestampByComponent
{
fn from(SelectStartTimestampByComponentBorrowed { component,timestamp,}: SelectStartTimestampByComponentBorrowed<'a>) ->
Self { Self { component: component.into(),timestamp,} }
}pub struct SelectStartTimestampByComponentQuery<'a, C: GenericClient, T, const N: usize>
{
client: &'a C, params:
[&'a (dyn postgres_types::ToSql + Sync); N], stmt: &'a mut
cornucopia_async::private::Stmt, extractor: fn(&tokio_postgres::Row) -> SelectStartTimestampByComponentBorrowed,
mapper: fn(SelectStartTimestampByComponentBorrowed) -> T,
} impl<'a, C, T:'a, const N: usize> SelectStartTimestampByComponentQuery<'a, C, T, N> where C:
GenericClient
{
pub fn map<R>(self, mapper: fn(SelectStartTimestampByComponentBorrowed) -> R) ->
SelectStartTimestampByComponentQuery<'a,C,R,N>
{
SelectStartTimestampByComponentQuery
#[allow(clippy::all, clippy::pedantic)]
#[allow(unused_variables)]
#[allow(unused_imports)]
#[allow(dead_code)]
pub mod types {}
#[allow(clippy::all, clippy::pedantic)]
#[allow(unused_variables)]
#[allow(unused_imports)]
#[allow(dead_code)]
pub mod queries {
pub mod start_timestamp_select_by_component {
use cornucopia_async::GenericClient;
use futures;
use futures::{StreamExt, TryStreamExt};
#[derive(Debug, Clone, PartialEq)]
pub struct SelectStartTimestampByComponent {
pub component: String,
pub timestamp: time::OffsetDateTime,
}
pub struct SelectStartTimestampByComponentBorrowed<'a> {
pub component: &'a str,
pub timestamp: time::OffsetDateTime,
}
impl<'a> From<SelectStartTimestampByComponentBorrowed<'a>> for SelectStartTimestampByComponent {
fn from(
SelectStartTimestampByComponentBorrowed {
component,
timestamp,
}: SelectStartTimestampByComponentBorrowed<'a>,
) -> Self {
Self {
component: component.into(),
timestamp,
}
}
}
pub struct SelectStartTimestampByComponentQuery<'a, C: GenericClient, T, const N: usize> {
client: &'a C,
params: [&'a (dyn postgres_types::ToSql + Sync); N],
stmt: &'a mut cornucopia_async::private::Stmt,
extractor: fn(&tokio_postgres::Row) -> SelectStartTimestampByComponentBorrowed,
mapper: fn(SelectStartTimestampByComponentBorrowed) -> T,
}
impl<'a, C, T: 'a, const N: usize> SelectStartTimestampByComponentQuery<'a, C, T, N>
where
C: GenericClient,
{
client: self.client, params: self.params, stmt: self.stmt,
extractor: self.extractor, mapper,
pub fn map<R>(
self,
mapper: fn(SelectStartTimestampByComponentBorrowed) -> R,
) -> SelectStartTimestampByComponentQuery<'a, C, R, N> {
SelectStartTimestampByComponentQuery {
client: self.client,
params: self.params,
stmt: self.stmt,
extractor: self.extractor,
mapper,
}
}
pub async fn one(self) -> Result<T, tokio_postgres::Error> {
let stmt = self.stmt.prepare(self.client).await?;
let row = self.client.query_one(stmt, &self.params).await?;
Ok((self.mapper)((self.extractor)(&row)))
}
pub async fn all(self) -> Result<Vec<T>, tokio_postgres::Error> {
self.iter().await?.try_collect().await
}
pub async fn opt(self) -> Result<Option<T>, tokio_postgres::Error> {
let stmt = self.stmt.prepare(self.client).await?;
Ok(self
.client
.query_opt(stmt, &self.params)
.await?
.map(|row| (self.mapper)((self.extractor)(&row))))
}
pub async fn iter(
self,
) -> Result<
impl futures::Stream<Item = Result<T, tokio_postgres::Error>> + 'a,
tokio_postgres::Error,
> {
let stmt = self.stmt.prepare(self.client).await?;
let it = self
.client
.query_raw(stmt, cornucopia_async::private::slice_iter(&self.params))
.await?
.map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row))))
.into_stream();
Ok(it)
}
}
} pub async fn one(self) -> Result<T, tokio_postgres::Error>
{
let stmt = self.stmt.prepare(self.client).await?; let row =
self.client.query_one(stmt, &self.params).await?;
Ok((self.mapper)((self.extractor)(&row)))
} pub async fn all(self) -> Result<Vec<T>, tokio_postgres::Error>
{ self.iter().await?.try_collect().await } pub async fn opt(self) ->
Result<Option<T>, tokio_postgres::Error>
{
let stmt = self.stmt.prepare(self.client).await?;
Ok(self.client.query_opt(stmt, &self.params) .await?
.map(|row| (self.mapper)((self.extractor)(&row))))
} pub async fn iter(self,) -> Result<impl futures::Stream<Item = Result<T,
tokio_postgres::Error>> + 'a, tokio_postgres::Error>
{
let stmt = self.stmt.prepare(self.client).await?; let it =
self.client.query_raw(stmt,
cornucopia_async::private::slice_iter(&self.params)) .await?
.map(move |res|
res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream();
Ok(it)
}
}pub fn select_start_timestamp_by_component() -> SelectStartTimestampByComponentStmt
{ SelectStartTimestampByComponentStmt(cornucopia_async::private::Stmt::new("SELECT
pub fn select_start_timestamp_by_component() -> SelectStartTimestampByComponentStmt {
SelectStartTimestampByComponentStmt(cornucopia_async::private::Stmt::new(
"SELECT
*
FROM
\"APIBackend\".public.\"StartTimestamps\"
WHERE
\"component\" = $1")) } pub struct
SelectStartTimestampByComponentStmt(cornucopia_async::private::Stmt); impl SelectStartTimestampByComponentStmt
{ pub fn bind<'a, C:
GenericClient,T1:
cornucopia_async::StringSql,>(&'a mut self, client: &'a C,
component: &'a T1,) -> SelectStartTimestampByComponentQuery<'a,C,
SelectStartTimestampByComponent, 1>
{
SelectStartTimestampByComponentQuery
{
client, params: [component,], stmt: &mut self.0, extractor:
|row| { SelectStartTimestampByComponentBorrowed { component: row.get(0),timestamp: row.get(1),} }, mapper: |it| { <SelectStartTimestampByComponent>::from(it) },
\"component\" = $1",
))
}
pub struct SelectStartTimestampByComponentStmt(cornucopia_async::private::Stmt);
impl SelectStartTimestampByComponentStmt {
pub fn bind<'a, C: GenericClient, T1: cornucopia_async::StringSql>(
&'a mut self,
client: &'a C,
component: &'a T1,
) -> SelectStartTimestampByComponentQuery<'a, C, SelectStartTimestampByComponent, 1>
{
SelectStartTimestampByComponentQuery {
client,
params: [component],
stmt: &mut self.0,
extractor: |row| SelectStartTimestampByComponentBorrowed {
component: row.get(0),
timestamp: row.get(1),
},
mapper: |it| <SelectStartTimestampByComponent>::from(it),
}
}
}
}
} }}pub mod start_timestamp_upsert
{ 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
{ StartTimestampUpsertStmt(cornucopia_async::private::Stmt::new("INSERT INTO
pub mod start_timestamp_upsert {
use cornucopia_async::GenericClient;
use futures;
use futures::{StreamExt, TryStreamExt};
#[derive(Debug)]
pub struct StartTimestampUpsertParams<T1: cornucopia_async::StringSql> {
pub component: T1,
pub timestamp: time::OffsetDateTime,
}
pub fn start_timestamp_upsert() -> StartTimestampUpsertStmt {
StartTimestampUpsertStmt(cornucopia_async::private::Stmt::new(
"INSERT INTO
\"APIBackend\".public.\"StartTimestamps\" (\"component\", \"timestamp\")
VALUES ($1, $2)
ON CONFLICT (\"component\") DO UPDATE
SET
\"timestamp\" = $2")) } pub struct
StartTimestampUpsertStmt(cornucopia_async::private::Stmt); impl StartTimestampUpsertStmt
{ pub async fn bind<'a, C:
GenericClient,T1:
cornucopia_async::StringSql,>(&'a mut self, client: &'a C,
component: &'a T1,timestamp: &'a time::OffsetDateTime,) -> Result<u64, tokio_postgres::Error>
{
let stmt = self.0.prepare(client).await?;
client.execute(stmt, &[component,timestamp,]).await
} }impl <'a, C: GenericClient + Send + Sync, T1: cornucopia_async::StringSql,>
cornucopia_async::Params<'a, StartTimestampUpsertParams<T1,>, std::pin::Pin<Box<dyn futures::Future<Output = Result<u64,
tokio_postgres::Error>> + Send + 'a>>, C> for StartTimestampUpsertStmt
{
fn
params(&'a mut self, client: &'a C, params: &'a
StartTimestampUpsertParams<T1,>) -> std::pin::Pin<Box<dyn futures::Future<Output = Result<u64,
tokio_postgres::Error>> + Send + 'a>>
{ Box::pin(self.bind(client, &params.component,&params.timestamp,)) }
}}}
\"timestamp\" = $2",
))
}
pub struct StartTimestampUpsertStmt(cornucopia_async::private::Stmt);
impl StartTimestampUpsertStmt {
pub async fn bind<'a, C: GenericClient, T1: cornucopia_async::StringSql>(
&'a mut self,
client: &'a C,
component: &'a T1,
timestamp: &'a time::OffsetDateTime,
) -> Result<u64, tokio_postgres::Error> {
let stmt = self.0.prepare(client).await?;
client.execute(stmt, &[component, timestamp]).await
}
}
impl<'a, C: GenericClient + Send + Sync, T1: cornucopia_async::StringSql>
cornucopia_async::Params<
'a,
StartTimestampUpsertParams<T1>,
std::pin::Pin<
Box<
dyn futures::Future<Output = Result<u64, tokio_postgres::Error>>
+ Send
+ 'a,
>,
>,
C,
> for StartTimestampUpsertStmt
{
fn params(
&'a mut self,
client: &'a C,
params: &'a StartTimestampUpsertParams<T1>,
) -> std::pin::Pin<
Box<dyn futures::Future<Output = Result<u64, tokio_postgres::Error>> + Send + 'a>,
> {
Box::pin(self.bind(client, &params.component, &params.timestamp))
}
}
}
}
Loading

0 comments on commit 636e32c

Please sign in to comment.