forked from projectmoon/tenebrous-dicebot
Implement variable count; fix listing all variables returning values for all users.
This commit is contained in:
parent
a665293268
commit
9f97a6cb43
|
@ -42,6 +42,30 @@
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"59313c67900a1a9399389720b522e572f181ae503559cd2b49d6305acb9e2207": {
|
||||||
|
"query": "SELECT key, value as \"value: i32\" FROM user_variables\n WHERE room_id = ? AND user_id = ?",
|
||||||
|
"describe": {
|
||||||
|
"columns": [
|
||||||
|
{
|
||||||
|
"name": "key",
|
||||||
|
"ordinal": 0,
|
||||||
|
"type_info": "Text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "value: i32",
|
||||||
|
"ordinal": 1,
|
||||||
|
"type_info": "Int64"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"parameters": {
|
||||||
|
"Right": 2
|
||||||
|
},
|
||||||
|
"nullable": [
|
||||||
|
false,
|
||||||
|
false
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
"636b1b868eaf04cd234fbf17747d94a66e81f7bc1b060ba14151dbfaf40eeefc": {
|
"636b1b868eaf04cd234fbf17747d94a66e81f7bc1b060ba14151dbfaf40eeefc": {
|
||||||
"query": "SELECT value as \"value: i32\" FROM user_variables\n WHERE user_id = ? AND room_id = ? AND key = ?",
|
"query": "SELECT value as \"value: i32\" FROM user_variables\n WHERE user_id = ? AND room_id = ? AND key = ?",
|
||||||
"describe": {
|
"describe": {
|
||||||
|
@ -60,6 +84,24 @@
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"711d222911c1258365a6a0de1fe00eeec4686fd3589e976e225ad599e7cfc75d": {
|
||||||
|
"query": "SELECT count(*) as \"count: i32\" FROM user_variables\n WHERE room_id = ? and user_id = ?",
|
||||||
|
"describe": {
|
||||||
|
"columns": [
|
||||||
|
{
|
||||||
|
"name": "count: i32",
|
||||||
|
"ordinal": 0,
|
||||||
|
"type_info": "Int"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"parameters": {
|
||||||
|
"Right": 2
|
||||||
|
},
|
||||||
|
"nullable": [
|
||||||
|
false
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
"ad52bc29fc1eef2bbff8b5f7316047f81ea31b1f910d0e0226125fea89530aa2": {
|
"ad52bc29fc1eef2bbff8b5f7316047f81ea31b1f910d0e0226125fea89530aa2": {
|
||||||
"query": "SELECT room_id FROM room_users\n WHERE username = ?",
|
"query": "SELECT room_id FROM room_users\n WHERE username = ?",
|
||||||
"describe": {
|
"describe": {
|
||||||
|
@ -113,29 +155,5 @@
|
||||||
false
|
false
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
|
||||||
"d6558668b7395b95ded8da71c80963ddde957abdcc3c68b03431f8e904e0d21f": {
|
|
||||||
"query": "SELECT key, value as \"value: i32\" FROM user_variables\n WHERE room_id = ?",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"name": "key",
|
|
||||||
"ordinal": 0,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "value: i32",
|
|
||||||
"ordinal": 1,
|
|
||||||
"type_info": "Int64"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Right": 1
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
false,
|
|
||||||
false
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -17,8 +17,9 @@ impl Variables for Database {
|
||||||
) -> Result<HashMap<String, i32>, DataError> {
|
) -> Result<HashMap<String, i32>, DataError> {
|
||||||
let rows = sqlx::query!(
|
let rows = sqlx::query!(
|
||||||
r#"SELECT key, value as "value: i32" FROM user_variables
|
r#"SELECT key, value as "value: i32" FROM user_variables
|
||||||
WHERE room_id = ?"#,
|
WHERE room_id = ? AND user_id = ?"#,
|
||||||
room_id,
|
room_id,
|
||||||
|
user
|
||||||
)
|
)
|
||||||
.fetch_all(&self.conn)
|
.fetch_all(&self.conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
@ -27,7 +28,16 @@ impl Variables for Database {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_variable_count(&self, user: &str, room_id: &str) -> Result<i32, DataError> {
|
async fn get_variable_count(&self, user: &str, room_id: &str) -> Result<i32, DataError> {
|
||||||
Ok(1)
|
let row = sqlx::query!(
|
||||||
|
r#"SELECT count(*) as "count: i32" FROM user_variables
|
||||||
|
WHERE room_id = ? and user_id = ?"#,
|
||||||
|
room_id,
|
||||||
|
user
|
||||||
|
)
|
||||||
|
.fetch_optional(&self.conn)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(row.map(|r| r.count).unwrap_or(0))
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_user_variable(
|
async fn get_user_variable(
|
||||||
|
|
Loading…
Reference in New Issue