mirror of
https://github.com/natsukagami/youmubot.git
synced 2025-04-19 08:48:54 +00:00
New table ignored_users
and queries
This commit is contained in:
parent
a36fa87964
commit
afea682408
11 changed files with 122 additions and 145 deletions
12
.sqlx/query-1619aac8983ad68177bd698393b24eefd77bada44bec1043972493146c09bb73.json
generated
Normal file
12
.sqlx/query-1619aac8983ad68177bd698393b24eefd77bada44bec1043972493146c09bb73.json
generated
Normal file
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"db_name": "SQLite",
|
||||
"query": "DELETE FROM ignored_users WHERE id = ?",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Right": 1
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "1619aac8983ad68177bd698393b24eefd77bada44bec1043972493146c09bb73"
|
||||
}
|
|
@ -25,7 +25,7 @@
|
|||
"nullable": [
|
||||
false,
|
||||
false,
|
||||
false
|
||||
true
|
||||
]
|
||||
},
|
||||
"hash": "1bf34dddbe994d6124c9382c75e70e1347329e945de2eefad4bfcab5f81b73ce"
|
||||
|
|
32
.sqlx/query-db5960586bc418d2a6a31c18b4a63f4efcfe4685c0561e07a2c954538be4789b.json
generated
Normal file
32
.sqlx/query-db5960586bc418d2a6a31c18b4a63f4efcfe4685c0561e07a2c954538be4789b.json
generated
Normal file
|
@ -0,0 +1,32 @@
|
|||
{
|
||||
"db_name": "SQLite",
|
||||
"query": "SELECT\n id,\n username,\n ignored_since as \"ignored_since: DateTime\"\n FROM ignored_users\n ORDER BY id ASC",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"name": "id",
|
||||
"ordinal": 0,
|
||||
"type_info": "Int64"
|
||||
},
|
||||
{
|
||||
"name": "username",
|
||||
"ordinal": 1,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "ignored_since: DateTime",
|
||||
"ordinal": 2,
|
||||
"type_info": "Datetime"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Right": 0
|
||||
},
|
||||
"nullable": [
|
||||
false,
|
||||
false,
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "db5960586bc418d2a6a31c18b4a63f4efcfe4685c0561e07a2c954538be4789b"
|
||||
}
|
12
.sqlx/query-e5da2c27e9d61239ebd9de291e08de8333d3097ada82da790942f05acdd87fc3.json
generated
Normal file
12
.sqlx/query-e5da2c27e9d61239ebd9de291e08de8333d3097ada82da790942f05acdd87fc3.json
generated
Normal file
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"db_name": "SQLite",
|
||||
"query": "INSERT INTO ignored_users(id, username) VALUES (?, ?)\n ON CONFLICT (id) DO UPDATE SET username = excluded.username",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Right": 2
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "e5da2c27e9d61239ebd9de291e08de8333d3097ada82da790942f05acdd87fc3"
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
{
|
||||
"db_name": "SQLite",
|
||||
"query": "SELECT\n user_id as \"user_id: i64\",\n username,\n id as \"id: i64\",\n preferred_mode as \"preferred_mode: u8\",\n failures as \"failures: u8\"\n FROM osu_users WHERE user_id = ?",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"name": "user_id: i64",
|
||||
"ordinal": 0,
|
||||
"type_info": "Int64"
|
||||
},
|
||||
{
|
||||
"name": "username",
|
||||
"ordinal": 1,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "id: i64",
|
||||
"ordinal": 2,
|
||||
"type_info": "Int64"
|
||||
},
|
||||
{
|
||||
"name": "preferred_mode: u8",
|
||||
"ordinal": 3,
|
||||
"type_info": "Int64"
|
||||
},
|
||||
{
|
||||
"name": "failures: u8",
|
||||
"ordinal": 4,
|
||||
"type_info": "Int64"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Right": 1
|
||||
},
|
||||
"nullable": [
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "25dcc59341e6375ee6a55aa014aecc54be42e1e8787ae5a06a61bb8ba8e9c366"
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
{
|
||||
"db_name": "SQLite",
|
||||
"query": "SELECT\n user_id as \"user_id: i64\",\n username,\n id as \"id: i64\",\n preferred_mode as \"preferred_mode: u8\",\n failures as \"failures: u8\"\n FROM osu_users",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"name": "user_id: i64",
|
||||
"ordinal": 0,
|
||||
"type_info": "Int64"
|
||||
},
|
||||
{
|
||||
"name": "username",
|
||||
"ordinal": 1,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "id: i64",
|
||||
"ordinal": 2,
|
||||
"type_info": "Int64"
|
||||
},
|
||||
{
|
||||
"name": "preferred_mode: u8",
|
||||
"ordinal": 3,
|
||||
"type_info": "Int64"
|
||||
},
|
||||
{
|
||||
"name": "failures: u8",
|
||||
"ordinal": 4,
|
||||
"type_info": "Int64"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Right": 0
|
||||
},
|
||||
"nullable": [
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "54f54f669244fbdf1ad68664290d8f32f0bda74ceee62d10c84ac03b710c828c"
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
{
|
||||
"db_name": "SQLite",
|
||||
"query": "INSERT\n INTO osu_users(user_id, username, id, preferred_mode, failures)\n VALUES(?, ?, ?, ?, ?)\n ON CONFLICT (user_id) WHERE id = ? DO UPDATE\n SET\n username = excluded.username,\n preferred_mode = excluded.preferred_mode,\n failures = excluded.failures\n ",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Right": 6
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "b9c63ef764711088cfbb58ce2ed1f46e3521357ec1d7c062bef762d3e4267378"
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
{
|
||||
"db_name": "SQLite",
|
||||
"query": "SELECT\n user_id as \"user_id: i64\",\n username,\n id as \"id: i64\",\n preferred_mode as \"preferred_mode: u8\",\n failures as \"failures: u8\"\n FROM osu_users WHERE id = ?",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"name": "user_id: i64",
|
||||
"ordinal": 0,
|
||||
"type_info": "Int64"
|
||||
},
|
||||
{
|
||||
"name": "username",
|
||||
"ordinal": 1,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "id: i64",
|
||||
"ordinal": 2,
|
||||
"type_info": "Int64"
|
||||
},
|
||||
{
|
||||
"name": "preferred_mode: u8",
|
||||
"ordinal": 3,
|
||||
"type_info": "Int64"
|
||||
},
|
||||
{
|
||||
"name": "failures: u8",
|
||||
"ordinal": 4,
|
||||
"type_info": "Int64"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Right": 1
|
||||
},
|
||||
"nullable": [
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "e313b2e91d0da80a94e9a1030f94cf30b025c9ac0ac4d5bcc12656459c5e083a"
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
-- Add migration script here
|
||||
|
||||
CREATE TABLE ignored_users (
|
||||
id BIGINT NOT NULL PRIMARY KEY,
|
||||
username TEXT NOT NULL UNIQUE,
|
||||
ignored_since DATETIME NOT NULL DEFAULT (DATETIME('now'))
|
||||
);
|
57
youmubot-db-sql/src/models/ignore_list.rs
Normal file
57
youmubot-db-sql/src/models/ignore_list.rs
Normal file
|
@ -0,0 +1,57 @@
|
|||
use super::*;
|
||||
use sqlx::Executor;
|
||||
|
||||
/// An ignored user in the ignored user list.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct IgnoredUser {
|
||||
pub id: i64,
|
||||
pub username: String,
|
||||
pub ignored_since: DateTime,
|
||||
}
|
||||
|
||||
impl IgnoredUser {
|
||||
/// Returns a list of all ignored users.
|
||||
pub async fn get_all<'a, E>(conn: E) -> Result<Vec<Self>>
|
||||
where
|
||||
E: Executor<'a, Database = Database>,
|
||||
{
|
||||
Ok(query_as!(
|
||||
IgnoredUser,
|
||||
r#"SELECT
|
||||
id,
|
||||
username,
|
||||
ignored_since as "ignored_since: DateTime"
|
||||
FROM ignored_users
|
||||
ORDER BY id ASC"#
|
||||
)
|
||||
.fetch_all(conn)
|
||||
.await?)
|
||||
}
|
||||
|
||||
/// Add an user to ignore list.
|
||||
pub async fn add<'a, E>(conn: E, user_id: i64, username: String) -> Result<()>
|
||||
where
|
||||
E: Executor<'a, Database = Database>,
|
||||
{
|
||||
query!(
|
||||
r#"INSERT INTO ignored_users(id, username) VALUES (?, ?)
|
||||
ON CONFLICT (id) DO UPDATE SET username = excluded.username"#,
|
||||
user_id,
|
||||
username
|
||||
)
|
||||
.execute(conn)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// Remove an user from ignore list.
|
||||
pub async fn remove<'a, E>(conn: E, user_id: i64) -> Result<()>
|
||||
where
|
||||
E: Executor<'a, Database = Database>,
|
||||
{
|
||||
query!(r#"DELETE FROM ignored_users WHERE id = ?"#, user_id)
|
||||
.execute(conn)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
|
@ -4,5 +4,6 @@ use sqlx::{query, query_as, Executor};
|
|||
/// The DateTime used in the package.
|
||||
pub type DateTime = chrono::DateTime<chrono::Utc>;
|
||||
|
||||
pub mod ignore_list;
|
||||
pub mod osu;
|
||||
pub mod osu_user;
|
||||
|
|
Loading…
Add table
Reference in a new issue