2024-12-05 01:57:47 +03:00
|
|
|
use sqlx::{Pool, Postgres};
|
2024-12-02 23:56:43 +03:00
|
|
|
|
2024-12-05 01:57:47 +03:00
|
|
|
use crate::feature::interaction::Interaction;
|
|
|
|
|
|
|
|
pub async fn create(
|
|
|
|
name: &String,
|
|
|
|
database_connection: &Pool<Postgres>,
|
|
|
|
) -> Result<Interaction, sqlx::Error> {
|
|
|
|
sqlx::query_as!(
|
|
|
|
Interaction,
|
|
|
|
r#"
|
|
|
|
INSERT INTO "interaction"(name)
|
|
|
|
VALUES ($1)
|
|
|
|
RETURNING *
|
|
|
|
"#,
|
|
|
|
name,
|
|
|
|
)
|
|
|
|
.fetch_one(database_connection)
|
|
|
|
.await
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn read(
|
|
|
|
name: &String,
|
|
|
|
database_connection: &Pool<Postgres>,
|
|
|
|
) -> Result<Interaction, sqlx::Error> {
|
|
|
|
sqlx::query_as!(
|
|
|
|
Interaction,
|
|
|
|
r#"
|
|
|
|
SELECT * FROM "interaction" WHERE "name" = $1
|
|
|
|
"#,
|
|
|
|
name
|
|
|
|
)
|
|
|
|
.fetch_one(database_connection)
|
|
|
|
.await
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn update(
|
2024-12-09 15:18:32 +03:00
|
|
|
id: &i64,
|
2024-12-05 01:57:47 +03:00
|
|
|
name: &String,
|
|
|
|
database_connection: &Pool<Postgres>,
|
|
|
|
) -> Result<Interaction, sqlx::Error> {
|
|
|
|
sqlx::query_as!(
|
|
|
|
Interaction,
|
|
|
|
r#"
|
2024-12-14 03:11:39 +03:00
|
|
|
UPDATE "interaction" SET "name" = $2 WHERE "id" = $1
|
2024-12-05 01:57:47 +03:00
|
|
|
RETURNING *
|
|
|
|
"#,
|
2024-12-14 03:11:39 +03:00
|
|
|
id,
|
|
|
|
name
|
2024-12-05 01:57:47 +03:00
|
|
|
)
|
|
|
|
.fetch_one(database_connection)
|
|
|
|
.await
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn delete(
|
2024-12-09 15:18:32 +03:00
|
|
|
id: &i64,
|
2024-12-05 01:57:47 +03:00
|
|
|
database_connection: &Pool<Postgres>,
|
|
|
|
) -> Result<Interaction, sqlx::Error> {
|
|
|
|
sqlx::query_as!(
|
|
|
|
Interaction,
|
|
|
|
r#"
|
2024-12-15 03:58:47 +03:00
|
|
|
DELETE FROM "interaction" WHERE "id" = $1
|
2024-12-05 01:57:47 +03:00
|
|
|
RETURNING *
|
|
|
|
"#,
|
|
|
|
id
|
|
|
|
)
|
|
|
|
.fetch_one(database_connection)
|
|
|
|
.await
|
|
|
|
}
|