wip: get all posts route working state

This commit is contained in:
wymiller committed 2024-09-25 18:29:12 -04:00
1 parent 7842baf5f2
commit 9bd2cf373a
5 files changed
+72 -43

No files matched your search

+10 -6
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) {}
}