16 lines
454 B
Rust
Raw Normal View History

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