Skip to content

Commit

Permalink
Merge pull request #2477 from HTGAzureX1212/nightly
Browse files Browse the repository at this point in the history
Initial Query Parsing, Disabling `cornucopia`
  • Loading branch information
HTGAzureX1212 authored Dec 4, 2024
2 parents 4599309 + acb7f61 commit e785a30
Show file tree
Hide file tree
Showing 25 changed files with 926 additions and 1,996 deletions.
6 changes: 3 additions & 3 deletions database/hartex-database-queries/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub fn main() {
return;
}

let api_backend_queries_path = "queries/api_backend";
/*let api_backend_queries_path = "queries/api_backend";
println!("cargo::rerun-if-changed={api_backend_queries_path}");
let url = env::var("API_PGSQL_URL").unwrap();
Expand Down Expand Up @@ -74,7 +74,7 @@ pub fn main() {
is_async: true,
},
)
.unwrap();
.unwrap();*/

hartex_database_typedsql::generate_queries_with_schemas("schemas", "", "").unwrap();
hartex_database_typedsql::generate_queries_with_schemas("schemas", "queries", "").unwrap();
}
251 changes: 83 additions & 168 deletions database/hartex-database-queries/generated/api_backend.rs
Original file line number Diff line number Diff line change
@@ -1,181 +1,96 @@
// 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 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,
#[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
{
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)
}
client: self.client, params: self.params, stmt: self.stmt,
extractor: self.extractor, mapper,
}
pub fn select_start_timestamp_by_component() -> SelectStartTimestampByComponentStmt {
SelectStartTimestampByComponentStmt(cornucopia_async::private::Stmt::new(
"SELECT
} 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
*
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 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
} }}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
\"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 e785a30

Please sign in to comment.