wip: get all posts route working state

This commit is contained in:
2024-09-25 18:29:12 -04:00
parent 7842baf5f2
commit 9bd2cf373a
5 changed files with 72 additions and 43 deletions

View File

@@ -1,11 +1,15 @@
use sqlx::PgPool;
use sqlx::{PgPool, Pool, Postgres};
use crate::routes::posts::Post;
pub struct PostsDatasource;
impl PostsDatasource {
pub async fn get_all(pool: PgPool) {
sqlx::query("SELECT title, body, created_at FROM posts ORDER BY created_at DESC LIMIT 10")
.fetch_all(&pool)
.await;
pub async fn get_all(pool: &Pool<Postgres>) -> Result<Vec<Post>, sqlx::Error> {
sqlx::query_as::<_, Post>(
"SELECT post_id, title, body, created_at FROM posts ORDER BY created_at DESC LIMIT 10",
)
.fetch_all(pool)
.await
}
pub async fn get_one(pool: PgPool) {}
pub async fn get_one(pool: PgPool, post_id: i32) {}
}