post, comment interaction db
This commit is contained in:
parent
60d18771d7
commit
1e8d656711
10 changed files with 184 additions and 0 deletions
|
@ -0,0 +1,2 @@
|
||||||
|
-- Add down migration script here
|
||||||
|
DROP TABLE IF EXISTS "post_interaction";
|
|
@ -0,0 +1,7 @@
|
||||||
|
-- Add up migration script here
|
||||||
|
CREATE TABLE IF NOT EXISTS "post_interaction"(
|
||||||
|
post_creation_time TIMESTAMPTZ NOT NULL REFERENCES "post"(creation_time),
|
||||||
|
interaction_id BIGSERIAL NOT NULL REFERENCES "interaction"(id),
|
||||||
|
interactor_id BIGSERIAL NOT NULL REFERENCES "user"(id),
|
||||||
|
interaction_time TIMESTAMPTZ PRIMARY KEY NOT NULL UNIQUE
|
||||||
|
);
|
|
@ -0,0 +1,2 @@
|
||||||
|
-- Add down migration script here
|
||||||
|
DROP TABLE IF EXISTS "comment_interaction";
|
|
@ -0,0 +1,7 @@
|
||||||
|
-- Add up migration script here
|
||||||
|
CREATE TABLE IF NOT EXISTS "comment_interaction"(
|
||||||
|
comment_creation_time TIMESTAMPTZ NOT NULL REFERENCES "comment"(creation_time),
|
||||||
|
interaction_id BIGSERIAL NOT NULL REFERENCES "interaction"(id),
|
||||||
|
interactor_id BIGSERIAL NOT NULL REFERENCES "user"(id),
|
||||||
|
interaction_time TIMESTAMPTZ PRIMARY KEY NOT NULL UNIQUE
|
||||||
|
);
|
|
@ -1,6 +1,8 @@
|
||||||
pub mod comment;
|
pub mod comment;
|
||||||
|
pub mod comment_interaction;
|
||||||
pub mod interaction;
|
pub mod interaction;
|
||||||
pub mod post;
|
pub mod post;
|
||||||
|
pub mod post_interaction;
|
||||||
pub mod role;
|
pub mod role;
|
||||||
pub mod user;
|
pub mod user;
|
||||||
|
|
||||||
|
|
73
src/database/comment_interaction.rs
Normal file
73
src/database/comment_interaction.rs
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
use chrono::{DateTime, Utc};
|
||||||
|
use sqlx::{Pool, Postgres};
|
||||||
|
|
||||||
|
use crate::feature::comment_interaction::CommentInteraction;
|
||||||
|
|
||||||
|
pub async fn create(
|
||||||
|
comment_creation_time: &DateTime<Utc>,
|
||||||
|
interaction_id: i64,
|
||||||
|
interactor_id: i64,
|
||||||
|
interaction_time: &DateTime<Utc>,
|
||||||
|
database_connection: &Pool<Postgres>,
|
||||||
|
) -> Result<CommentInteraction, sqlx::Error> {
|
||||||
|
sqlx::query_as!(
|
||||||
|
CommentInteraction,
|
||||||
|
r#"
|
||||||
|
INSERT INTO "comment_interaction"(comment_creation_time, interaction_id, interactor_id, interaction_time)
|
||||||
|
VALUES ($1, $2, $3, $4)
|
||||||
|
RETURNING *
|
||||||
|
"#,
|
||||||
|
comment_creation_time, interaction_id, interactor_id, interaction_time,
|
||||||
|
)
|
||||||
|
.fetch_one(database_connection)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn read(
|
||||||
|
interaction_time: &DateTime<Utc>,
|
||||||
|
database_connection: &Pool<Postgres>,
|
||||||
|
) -> Result<CommentInteraction, sqlx::Error> {
|
||||||
|
sqlx::query_as!(
|
||||||
|
CommentInteraction,
|
||||||
|
r#"
|
||||||
|
SELECT * FROM "comment_interaction" WHERE "interaction_time" = $1
|
||||||
|
"#,
|
||||||
|
interaction_time
|
||||||
|
)
|
||||||
|
.fetch_one(database_connection)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn update(
|
||||||
|
interaction_time: &DateTime<Utc>,
|
||||||
|
interaction_id: i64,
|
||||||
|
database_connection: &Pool<Postgres>,
|
||||||
|
) -> Result<CommentInteraction, sqlx::Error> {
|
||||||
|
sqlx::query_as!(
|
||||||
|
CommentInteraction,
|
||||||
|
r#"
|
||||||
|
UPDATE "comment_interaction" SET "interaction_id" = $1 WHERE "interaction_time" = $2
|
||||||
|
RETURNING *
|
||||||
|
"#,
|
||||||
|
interaction_id,
|
||||||
|
interaction_time
|
||||||
|
)
|
||||||
|
.fetch_one(database_connection)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn delete(
|
||||||
|
interaction_time: &DateTime<Utc>,
|
||||||
|
database_connection: &Pool<Postgres>,
|
||||||
|
) -> Result<CommentInteraction, sqlx::Error> {
|
||||||
|
sqlx::query_as!(
|
||||||
|
CommentInteraction,
|
||||||
|
r#"
|
||||||
|
DELETE FROM "comment_interaction" where "interaction_time" = $1
|
||||||
|
RETURNING *
|
||||||
|
"#,
|
||||||
|
interaction_time
|
||||||
|
)
|
||||||
|
.fetch_one(database_connection)
|
||||||
|
.await
|
||||||
|
}
|
73
src/database/post_interaction.rs
Normal file
73
src/database/post_interaction.rs
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
use chrono::{DateTime, Utc};
|
||||||
|
use sqlx::{Pool, Postgres};
|
||||||
|
|
||||||
|
use crate::feature::post_interaction::PostInteraction;
|
||||||
|
|
||||||
|
pub async fn create(
|
||||||
|
post_creation_time: &DateTime<Utc>,
|
||||||
|
interaction_id: i64,
|
||||||
|
interactor_id: i64,
|
||||||
|
interaction_time: &DateTime<Utc>,
|
||||||
|
database_connection: &Pool<Postgres>,
|
||||||
|
) -> Result<PostInteraction, sqlx::Error> {
|
||||||
|
sqlx::query_as!(
|
||||||
|
PostInteraction,
|
||||||
|
r#"
|
||||||
|
INSERT INTO "post_interaction"(post_creation_time, interaction_id, interactor_id, interaction_time)
|
||||||
|
VALUES ($1, $2, $3, $4)
|
||||||
|
RETURNING *
|
||||||
|
"#,
|
||||||
|
post_creation_time, interaction_id, interactor_id, interaction_time,
|
||||||
|
)
|
||||||
|
.fetch_one(database_connection)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn read(
|
||||||
|
interaction_time: &DateTime<Utc>,
|
||||||
|
database_connection: &Pool<Postgres>,
|
||||||
|
) -> Result<PostInteraction, sqlx::Error> {
|
||||||
|
sqlx::query_as!(
|
||||||
|
PostInteraction,
|
||||||
|
r#"
|
||||||
|
SELECT * FROM "post_interaction" WHERE "interaction_time" = $1
|
||||||
|
"#,
|
||||||
|
interaction_time
|
||||||
|
)
|
||||||
|
.fetch_one(database_connection)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn update(
|
||||||
|
interaction_time: &DateTime<Utc>,
|
||||||
|
interaction_id: i64,
|
||||||
|
database_connection: &Pool<Postgres>,
|
||||||
|
) -> Result<PostInteraction, sqlx::Error> {
|
||||||
|
sqlx::query_as!(
|
||||||
|
PostInteraction,
|
||||||
|
r#"
|
||||||
|
UPDATE "post_interaction" SET "interaction_id" = $1 WHERE "interaction_time" = $2
|
||||||
|
RETURNING *
|
||||||
|
"#,
|
||||||
|
interaction_id,
|
||||||
|
interaction_time
|
||||||
|
)
|
||||||
|
.fetch_one(database_connection)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn delete(
|
||||||
|
interaction_time: &DateTime<Utc>,
|
||||||
|
database_connection: &Pool<Postgres>,
|
||||||
|
) -> Result<PostInteraction, sqlx::Error> {
|
||||||
|
sqlx::query_as!(
|
||||||
|
PostInteraction,
|
||||||
|
r#"
|
||||||
|
DELETE FROM "post_interaction" where "interaction_time" = $1
|
||||||
|
RETURNING *
|
||||||
|
"#,
|
||||||
|
interaction_time
|
||||||
|
)
|
||||||
|
.fetch_one(database_connection)
|
||||||
|
.await
|
||||||
|
}
|
|
@ -1,5 +1,7 @@
|
||||||
pub mod comment;
|
pub mod comment;
|
||||||
|
pub mod comment_interaction;
|
||||||
pub mod interaction;
|
pub mod interaction;
|
||||||
pub mod post;
|
pub mod post;
|
||||||
|
pub mod post_interaction;
|
||||||
pub mod role;
|
pub mod role;
|
||||||
pub mod user;
|
pub mod user;
|
||||||
|
|
8
src/feature/comment_interaction.rs
Normal file
8
src/feature/comment_interaction.rs
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
use chrono::{DateTime, Utc};
|
||||||
|
|
||||||
|
pub struct CommentInteraction {
|
||||||
|
pub comment_creation_time: DateTime<Utc>,
|
||||||
|
pub interaction_id: i64,
|
||||||
|
pub interactor_id: i64,
|
||||||
|
pub interaction_time: DateTime<Utc>,
|
||||||
|
}
|
8
src/feature/post_interaction.rs
Normal file
8
src/feature/post_interaction.rs
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
use chrono::{DateTime, Utc};
|
||||||
|
|
||||||
|
pub struct PostInteraction {
|
||||||
|
pub post_creation_time: DateTime<Utc>,
|
||||||
|
pub interaction_id: i64,
|
||||||
|
pub interactor_id: i64,
|
||||||
|
pub interaction_time: DateTime<Utc>,
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue