2024-09-25 18:29:12 -04:00
|
|
|
use sqlx::{PgPool, Pool, Postgres};
|
|
|
|
|
|
|
|
use crate::routes::posts::Post;
|
2024-09-24 20:26:15 -04:00
|
|
|
|
2024-09-22 22:38:35 -04:00
|
|
|
pub struct PostsDatasource;
|
2024-09-24 20:26:15 -04:00
|
|
|
impl PostsDatasource {
|
2024-09-25 18:29:12 -04:00
|
|
|
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
|
2024-09-24 20:26:15 -04:00
|
|
|
}
|
2024-09-25 18:29:12 -04:00
|
|
|
pub async fn get_one(pool: PgPool, post_id: i32) {}
|
2024-09-24 20:26:15 -04:00
|
|
|
}
|