wip: get all posts route working state
This commit is contained in:
@@ -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) {}
|
||||
}
|
||||
|
Reference in New Issue
Block a user