mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-01 17:15:28 +00:00
draft app records selection
This commit is contained in:
parent
efa97b820e
commit
9ea3091174
1 changed files with 25 additions and 7 deletions
|
|
@ -1,11 +1,11 @@
|
||||||
use sqlite::Connection;
|
use sqlite::{Connection, Error};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
const DEBUG: bool = true; // @TODO
|
const DEBUG: bool = true; // @TODO
|
||||||
|
|
||||||
enum Table {
|
pub struct Table {
|
||||||
Id,
|
pub id: i64,
|
||||||
Time,
|
pub time: i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Database {
|
pub struct Database {
|
||||||
|
|
@ -42,11 +42,29 @@ impl Database {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn clean(&self) -> Result<usize, String> {
|
pub fn records(&self) -> Result<Vec<Table>, Error> {
|
||||||
return match self.connection.execute("DELETE FROM `app`", []) {
|
let mut records: Vec<Table> = Vec::new();
|
||||||
|
|
||||||
|
let mut statement = self.connection.prepare("SELECT `id`, `time` FROM `app`")?;
|
||||||
|
let _ = statement.query_map([], |row| {
|
||||||
|
records.push(Table {
|
||||||
|
id: row.get(0)?,
|
||||||
|
time: row.get(1)?,
|
||||||
|
});
|
||||||
|
Ok(())
|
||||||
|
});
|
||||||
|
|
||||||
|
Ok(records)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn delete(&self, id: i64) -> Result<usize, String> {
|
||||||
|
return match self
|
||||||
|
.connection
|
||||||
|
.execute("DELETE FROM `app` WHERE `id` = ?", [id])
|
||||||
|
{
|
||||||
Ok(total) => {
|
Ok(total) => {
|
||||||
if DEBUG {
|
if DEBUG {
|
||||||
println!("Deleted {total} rows from `app` table");
|
println!("Deleted {total} row(s) from `app` table");
|
||||||
}
|
}
|
||||||
Ok(total)
|
Ok(total)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue