refactor: ♻️ Singleton Pattern Database Connection
This commit is contained in:
parent
bcfcd2c6f0
commit
3f2aa572a6
37 changed files with 565 additions and 1221 deletions
|
@ -1,6 +1,5 @@
|
|||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sqlx::{Pool, Postgres};
|
||||
|
||||
use crate::database::post;
|
||||
|
||||
|
@ -12,45 +11,31 @@ pub struct Post {
|
|||
}
|
||||
|
||||
impl Post {
|
||||
pub async fn create(
|
||||
user_id: &i64,
|
||||
post: &String,
|
||||
database_connection: &Pool<Postgres>,
|
||||
) -> Result<Post, sqlx::Error> {
|
||||
post::create(user_id, post, database_connection).await
|
||||
pub async fn create(user_id: &i64, post: &String) -> Result<Post, sqlx::Error> {
|
||||
post::create(user_id, post).await
|
||||
}
|
||||
|
||||
pub async fn read(
|
||||
creation_time: &DateTime<Utc>,
|
||||
database_connection: &Pool<Postgres>,
|
||||
) -> Result<Post, sqlx::Error> {
|
||||
post::read(creation_time, database_connection).await
|
||||
pub async fn read(creation_time: &DateTime<Utc>) -> Result<Post, sqlx::Error> {
|
||||
post::read(creation_time).await
|
||||
}
|
||||
|
||||
pub async fn update(
|
||||
creation_time: &DateTime<Utc>,
|
||||
user_id: &i64,
|
||||
post: &String,
|
||||
database_connection: &Pool<Postgres>,
|
||||
) -> Result<Post, sqlx::Error> {
|
||||
post::update(creation_time, user_id, post, database_connection).await
|
||||
post::update(creation_time, user_id, post).await
|
||||
}
|
||||
|
||||
pub async fn delete(
|
||||
creation_time: &DateTime<Utc>,
|
||||
database_connection: &Pool<Postgres>,
|
||||
) -> Result<Post, sqlx::Error> {
|
||||
post::delete(creation_time, database_connection).await
|
||||
pub async fn delete(creation_time: &DateTime<Utc>) -> Result<Post, sqlx::Error> {
|
||||
post::delete(creation_time).await
|
||||
}
|
||||
|
||||
pub async fn read_all(database_connection: &Pool<Postgres>) -> Result<Vec<Post>, sqlx::Error> {
|
||||
post::read_all(database_connection).await
|
||||
pub async fn read_all() -> Result<Vec<Post>, sqlx::Error> {
|
||||
post::read_all().await
|
||||
}
|
||||
|
||||
pub async fn read_all_for_user(
|
||||
user_id: &i64,
|
||||
database_connection: &Pool<Postgres>,
|
||||
) -> Result<Vec<Post>, sqlx::Error> {
|
||||
post::read_all_for_user(user_id, database_connection).await
|
||||
pub async fn read_all_for_user(user_id: &i64) -> Result<Vec<Post>, sqlx::Error> {
|
||||
post::read_all_for_user(user_id).await
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue