-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add HTM persistence, move migrations file to crate root (#510)
* Add HTM persistence, move migrations file to crate root * Ensure sqlx files exist * Remove space after newline in htm persistence message
- Loading branch information
Showing
12 changed files
with
126 additions
and
4 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
.sqlx/query-3b3211af0c35f19ad8c32a048456b2adbb47775cec208ce1aebd543f38a1bfef.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
.sqlx/query-7577bdae53f7407534a632826a88564656e456434966a3296cc5375414697feb.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
.sqlx/query-f0d2ab5f212ef40d1ecec2a5424d5b861b09058f7527712ef343fc117237847c.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use serenity::model::id::UserId; | ||
|
||
use crate::Db; | ||
|
||
#[derive(Debug)] | ||
pub struct HardToModerateEntry { | ||
pub user: UserId, | ||
} | ||
|
||
impl Db { | ||
#[tracing::instrument(skip_all)] | ||
pub async fn check_user_htm(&self, id: UserId) -> anyhow::Result<bool> { | ||
let id = id.0 as i64; | ||
Ok(sqlx::query!(r#"select * from hard_to_moderate where usr=?"#, id) | ||
.fetch_optional(&self.pool) | ||
.await? | ||
.is_some()) | ||
} | ||
|
||
#[tracing::instrument(skip_all)] | ||
pub async fn add_htm(&self, id: UserId) -> anyhow::Result<()> { | ||
let id = id.0 as i64; | ||
sqlx::query!(r#"insert or ignore into hard_to_moderate (usr) values (?)"#, id) | ||
.fetch_optional(&self.pool) | ||
.await?; | ||
Ok(()) | ||
} | ||
|
||
#[tracing::instrument(skip_all)] | ||
pub async fn remove_htm(&self, id: UserId) -> anyhow::Result<()> { | ||
let id = id.0 as i64; | ||
sqlx::query!(r#"delete from hard_to_moderate where usr=?"#, id) | ||
.fetch_optional(&self.pool) | ||
.await?; | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
CREATE TABLE IF NOT EXISTS hard_to_moderate ( | ||
usr integer primary key | ||
); |