mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-01-30 13:04:13 +00:00
implement additional fields for profile table
This commit is contained in:
parent
b12f5e8b8f
commit
1de6b54daa
@ -1,26 +1,38 @@
|
|||||||
use sqlite::{Error, Transaction};
|
use sqlite::{Error, Transaction};
|
||||||
|
|
||||||
|
use gtk::glib::DateTime;
|
||||||
|
|
||||||
pub struct Table {
|
pub struct Table {
|
||||||
pub id: i64,
|
pub id: i64,
|
||||||
|
pub time: DateTime,
|
||||||
|
pub name: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init(tx: &Transaction) -> Result<usize, Error> {
|
pub fn init(tx: &Transaction) -> Result<usize, Error> {
|
||||||
tx.execute(
|
tx.execute(
|
||||||
"CREATE TABLE IF NOT EXISTS `profile`
|
"CREATE TABLE IF NOT EXISTS `profile`
|
||||||
(
|
(
|
||||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
|
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||||
|
`time` INTEGER NOT NULL,
|
||||||
|
`name` VARCHAR(255)
|
||||||
)",
|
)",
|
||||||
[],
|
[],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add(tx: &Transaction) -> Result<usize, Error> {
|
pub fn add(tx: &Transaction, time: &DateTime, name: Option<&str>) -> Result<usize, Error> {
|
||||||
tx.execute("INSERT INTO `profile` DEFAULT VALUES", [])
|
tx.execute("INSERT INTO `profile`", (time.to_unix(), name))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn records(tx: &Transaction) -> Result<Vec<Table>, Error> {
|
pub fn records(tx: &Transaction) -> Result<Vec<Table>, Error> {
|
||||||
let mut stmt = tx.prepare("SELECT `profile_id` FROM `profile`")?;
|
let mut stmt = tx.prepare("SELECT `id`, `time`, `name` FROM `profile`")?;
|
||||||
let result = stmt.query_map([], |row| Ok(Table { id: row.get(0)? }))?;
|
let result = stmt.query_map([], |row| {
|
||||||
|
Ok(Table {
|
||||||
|
id: row.get(0)?,
|
||||||
|
time: DateTime::from_unix_local(row.get(1)?).unwrap(),
|
||||||
|
name: row.get(2)?,
|
||||||
|
})
|
||||||
|
})?;
|
||||||
|
|
||||||
let mut records = Vec::new();
|
let mut records = Vec::new();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user