mirror of
https://git.ethanthesleepy.one/ethanaobrien/ew
synced 2026-01-12 00:02:38 +08:00
Move sql get_live_data function to clear_rate.rs
This commit is contained in:
@@ -8,6 +8,29 @@ use crate::encryption;
|
||||
use crate::sql::SQLite;
|
||||
use crate::router::{global, databases};
|
||||
|
||||
trait SqlClearRate {
|
||||
fn get_live_data(&self, id: i64) -> Result<Live, rusqlite::Error>;
|
||||
}
|
||||
impl SqlClearRate for SQLite {
|
||||
fn get_live_data(&self, id: i64) -> Result<Live, rusqlite::Error> {
|
||||
let conn = rusqlite::Connection::open(self.get_path()).unwrap();
|
||||
let mut stmt = conn.prepare("SELECT * FROM lives WHERE live_id=?1")?;
|
||||
stmt.query_row(params!(id), |row| {
|
||||
Ok(Live {
|
||||
live_id: row.get(0)?,
|
||||
normal_failed: row.get(1)?,
|
||||
normal_pass: row.get(2)?,
|
||||
hard_failed: row.get(3)?,
|
||||
hard_pass: row.get(4)?,
|
||||
expert_failed: row.get(5)?,
|
||||
expert_pass: row.get(6)?,
|
||||
master_failed: row.get(7)?,
|
||||
master_pass: row.get(8)?,
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
static ref DATABASE: SQLite = SQLite::new("live_statistics.db", setup_tables);
|
||||
static ref CACHED_DATA: Mutex<Option<JsonValue>> = Mutex::new(None);
|
||||
|
||||
24
src/sql.rs
24
src/sql.rs
@@ -1,8 +1,6 @@
|
||||
use rusqlite::{Connection, params, ToSql};
|
||||
use rusqlite::{Connection, ToSql};
|
||||
use json::{JsonValue, array};
|
||||
|
||||
use crate::router::clear_rate::Live;
|
||||
|
||||
pub struct SQLite {
|
||||
path: String
|
||||
}
|
||||
@@ -18,6 +16,9 @@ impl SQLite {
|
||||
setup(&conn);
|
||||
instance
|
||||
}
|
||||
pub fn get_path(&self) -> &str {
|
||||
&self.path
|
||||
}
|
||||
pub fn lock_and_exec(&self, command: &str, args: &[&dyn ToSql]) {
|
||||
let conn = Connection::open(&self.path).unwrap();
|
||||
conn.execute(command, args).unwrap();
|
||||
@@ -51,21 +52,4 @@ impl SQLite {
|
||||
}
|
||||
Ok(rv)
|
||||
}
|
||||
pub fn get_live_data(&self, id: i64) -> Result<Live, rusqlite::Error> {
|
||||
let conn = Connection::open(&self.path).unwrap();
|
||||
let mut stmt = conn.prepare("SELECT * FROM lives WHERE live_id=?1")?;
|
||||
stmt.query_row(params!(id), |row| {
|
||||
Ok(Live {
|
||||
live_id: row.get(0)?,
|
||||
normal_failed: row.get(1)?,
|
||||
normal_pass: row.get(2)?,
|
||||
hard_failed: row.get(3)?,
|
||||
hard_pass: row.get(4)?,
|
||||
expert_failed: row.get(5)?,
|
||||
expert_pass: row.get(6)?,
|
||||
master_failed: row.get(7)?,
|
||||
master_pass: row.get(8)?,
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user