better query_as!
This commit is contained in:
parent
0811e89e65
commit
68dce235c1
1 changed files with 5 additions and 19 deletions
24
src/main.rs
24
src/main.rs
|
@ -13,10 +13,10 @@ use figment::{
|
|||
Figment,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sqlx::{postgres::PgPoolOptions, query_as, Pool, Postgres};
|
||||
use sqlx::{postgres::PgPoolOptions, Pool, Postgres};
|
||||
use std::{net::SocketAddr, sync::Arc};
|
||||
|
||||
use crate::content::{Page, PageBlock};
|
||||
use crate::content::Page;
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
struct Config {
|
||||
|
@ -56,23 +56,9 @@ struct AppState {
|
|||
}
|
||||
|
||||
async fn root(State(state): State<Arc<AppState>>) -> Result<String, GenericError> {
|
||||
let page = query_as!(
|
||||
Page,
|
||||
r#"select
|
||||
id,
|
||||
author,
|
||||
title,
|
||||
description,
|
||||
tags,
|
||||
slug,
|
||||
created_at,
|
||||
modified_at,
|
||||
deleted_at,
|
||||
blocks as "blocks!: sqlx::types::Json<Vec<PageBlock>>"
|
||||
from pages limit 1"#
|
||||
)
|
||||
.fetch_one(&state.database)
|
||||
.await?;
|
||||
let select_query: sqlx::query::QueryAs<'_, _, Page, _> =
|
||||
sqlx::query_as::<_, Page>("SELECT * FROM pages");
|
||||
let page: Page = select_query.fetch_one(&state.database).await?;
|
||||
Ok(page.title)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue