mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-01 00:55:28 +00:00
implements records getter
This commit is contained in:
parent
3ed0e0f276
commit
74e9daeddb
1 changed files with 10 additions and 2 deletions
|
|
@ -23,6 +23,14 @@ impl Database {
|
||||||
profile_id,
|
profile_id,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Getters
|
||||||
|
|
||||||
|
pub fn records(&self, request: Option<&str>) -> Vec<Table> {
|
||||||
|
let readable = self.connection.read().unwrap();
|
||||||
|
let tx = readable.unchecked_transaction().unwrap();
|
||||||
|
select(&tx, self.profile_id, request).unwrap()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Low-level DB API
|
// Low-level DB API
|
||||||
|
|
@ -59,7 +67,7 @@ pub fn insert(
|
||||||
pub fn select(
|
pub fn select(
|
||||||
tx: &Transaction,
|
tx: &Transaction,
|
||||||
profile_id: i64,
|
profile_id: i64,
|
||||||
request: Option<String>,
|
request: Option<&str>,
|
||||||
) -> Result<Vec<Table>, Error> {
|
) -> Result<Vec<Table>, Error> {
|
||||||
let mut stmt = tx.prepare(
|
let mut stmt = tx.prepare(
|
||||||
"SELECT `id`, `profile_id`, `time`, `request`
|
"SELECT `id`, `profile_id`, `time`, `request`
|
||||||
|
|
@ -69,7 +77,7 @@ pub fn select(
|
||||||
|
|
||||||
let filter = match request {
|
let filter = match request {
|
||||||
Some(value) => value,
|
Some(value) => value,
|
||||||
None => format!("%"),
|
None => "%",
|
||||||
};
|
};
|
||||||
|
|
||||||
let result = stmt.query_map((profile_id, filter), |row| {
|
let result = stmt.query_map((profile_id, filter), |row| {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue