deactivate welcome dialog, auto-generate profile on first launch, remove extra references, draft bookmarks model

This commit is contained in:
yggverse 2024-11-14 06:00:41 +02:00
parent f81e496fa4
commit b441a681f7
7 changed files with 75 additions and 25 deletions

View file

@ -1,6 +1,22 @@
mod database;
use database::Database;
use sqlite::Transaction;
use sqlite::{Connection, Transaction};
use std::{rc::Rc, sync::RwLock};
pub struct Bookmark {
pub database: Rc<Database>,
}
impl Bookmark {
// Constructors
pub fn new(connection: Rc<RwLock<Connection>>, profile_id: i64) -> Self {
Self {
database: Rc::new(Database::new(connection, profile_id)),
}
}
}
// Tools

View file

@ -1,5 +1,6 @@
use gtk::glib::DateTime;
use sqlite::{Error, Transaction};
use sqlite::{Connection, Error, Transaction};
use std::{rc::Rc, sync::RwLock};
pub struct Table {
pub id: i64,
@ -8,8 +9,20 @@ pub struct Table {
pub request: String,
}
pub struct Bookmark {
// nothing yet..
pub struct Database {
pub connection: Rc<RwLock<Connection>>,
profile_id: i64, // @TODO multi-profile implementation
}
impl Database {
// Constructors
pub fn new(connection: Rc<RwLock<Connection>>, profile_id: i64) -> Self {
Self {
connection,
profile_id,
}
}
}
// Low-level DB API
@ -29,9 +42,9 @@ pub fn init(tx: &Transaction) -> Result<usize, Error> {
pub fn insert(
tx: &Transaction,
profile_id: &i64,
time: &DateTime,
request: &str,
profile_id: i64,
time: DateTime,
request: String,
) -> Result<usize, Error> {
tx.execute(
"INSERT INTO `profile_bookmark` (
@ -45,8 +58,8 @@ pub fn insert(
pub fn select(
tx: &Transaction,
profile_id: &i64,
request: Option<&str>,
profile_id: i64,
request: Option<String>,
) -> Result<Vec<Table>, Error> {
let mut stmt = tx.prepare(
"SELECT `id`, `profile_id`, `time`, `request`
@ -56,7 +69,7 @@ pub fn select(
let filter = match request {
Some(value) => value,
None => "%",
None => format!("%"),
};
let result = stmt.query_map((profile_id, filter), |row| {
@ -78,6 +91,6 @@ pub fn select(
Ok(records)
}
pub fn delete(tx: &Transaction, id: &i64) -> Result<usize, Error> {
pub fn delete(tx: &Transaction, id: i64) -> Result<usize, Error> {
tx.execute("DELETE FROM `profile_bookmark` WHERE `id` = ?", [id])
}

View file

@ -30,8 +30,8 @@ impl Database {
select(&tx).unwrap()
}
/// Get selected profile record if exist
pub fn selected(&self) -> Option<Table> {
/// Get active profile record if exist
pub fn active(&self) -> Option<Table> {
for record in self.records() {
if record.is_active {
return Some(record);

View file

@ -8,7 +8,7 @@ pub struct Table {
pub request: String,
}
pub struct History {
pub struct Database {
// nothing yet..
}
@ -29,9 +29,9 @@ pub fn init(tx: &Transaction) -> Result<usize, Error> {
pub fn insert(
tx: &Transaction,
profile_id: &i64,
time: &DateTime,
request: &str,
profile_id: i64,
time: DateTime,
request: String,
) -> Result<usize, Error> {
tx.execute(
"INSERT INTO `history` (
@ -45,8 +45,8 @@ pub fn insert(
pub fn select(
tx: &Transaction,
profile_id: &i64,
request: Option<&str>,
profile_id: i64,
request: Option<String>,
) -> Result<Vec<Table>, Error> {
let mut stmt = tx.prepare(
"SELECT `id`, `profile_id`, `time`, `request`
@ -56,7 +56,7 @@ pub fn select(
let filter = match request {
Some(value) => value,
None => "%",
None => format!("%"),
};
let result = stmt.query_map((profile_id, filter), |row| {
@ -78,6 +78,6 @@ pub fn select(
Ok(records)
}
pub fn delete(tx: &Transaction, id: &i64) -> Result<usize, Error> {
pub fn delete(tx: &Transaction, id: i64) -> Result<usize, Error> {
tx.execute("DELETE FROM `profile_history` WHERE `id` = ?", [id])
}