26 lines
616 B
Rust
26 lines
616 B
Rust
|
use crate::types::{NewPost, Post};
|
||
|
use sqlx::{Any, AnyPool, Row};
|
||
|
|
||
|
fn db_get_user() -> String {
|
||
|
unimplemented!();
|
||
|
}
|
||
|
|
||
|
fn db_get_posts() -> Vec<Post> {
|
||
|
unimplemented!();
|
||
|
}
|
||
|
|
||
|
async fn db_new_post(post: NewPost, pool: &AnyPool) -> i32 {
|
||
|
let q = "INSERT INTO posts (content) VALUES (?)";
|
||
|
let query = sqlx::query(q).bind(post.content);
|
||
|
let result = query.fetch_one(pool).await.ok();
|
||
|
if let Some(row) = result {
|
||
|
row.get::<i32, _>("id")
|
||
|
} else {
|
||
|
panic!("Failed to insert post into database");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
fn db_vote(post_id: i32, user_id: i32, upvote: bool) {
|
||
|
unimplemented!();
|
||
|
}
|