rename low-level db api

This commit is contained in:
yggverse 2024-11-13 11:45:33 +02:00
parent 091b7da7b8
commit aa076b370b
27 changed files with 70 additions and 70 deletions

View File

@ -47,7 +47,7 @@ impl App {
match connection.unchecked_transaction() {
Ok(transaction) => {
// Restore previous session from DB
match database::records(&transaction) {
match database::select(&transaction) {
Ok(records) => {
// Restore child components
for record in records {
@ -82,7 +82,7 @@ impl App {
// Create transaction
match connection.transaction() {
Ok(transaction) => {
match database::records(&transaction) {
match database::select(&transaction) {
Ok(records) => {
// Cleanup previous session records
for record in records {
@ -100,7 +100,7 @@ impl App {
}
// Save current session to DB
match database::add(&transaction) {
match database::insert(&transaction) {
Ok(_) => {
// Delegate save action to childs
if let Err(e) = browser.save(

View File

@ -104,7 +104,7 @@ impl Browser {
// Actions
pub fn clean(&self, transaction: &Transaction, app_id: &i64) -> Result<(), String> {
match database::records(transaction, app_id) {
match database::select(transaction, app_id) {
Ok(records) => {
for record in records {
match database::delete(transaction, &record.id) {
@ -127,7 +127,7 @@ impl Browser {
}
pub fn restore(&self, transaction: &Transaction, app_id: &i64) -> Result<(), String> {
match database::records(transaction, app_id) {
match database::select(transaction, app_id) {
Ok(records) => {
for record in records {
// Delegate restore action to childs
@ -145,7 +145,7 @@ impl Browser {
}
pub fn save(&self, transaction: &Transaction, app_id: &i64) -> Result<(), String> {
match database::add(transaction, app_id) {
match database::insert(transaction, app_id) {
Ok(_) => {
let id = database::last_insert_id(transaction);

View File

@ -16,11 +16,11 @@ pub fn init(tx: &Transaction) -> Result<usize, Error> {
)
}
pub fn add(tx: &Transaction, app_id: &i64) -> Result<usize, Error> {
pub fn insert(tx: &Transaction, app_id: &i64) -> Result<usize, Error> {
tx.execute("INSERT INTO `app_browser` (`app_id`) VALUES (?)", [app_id])
}
pub fn records(tx: &Transaction, app_id: &i64) -> Result<Vec<Table>, Error> {
pub fn select(tx: &Transaction, app_id: &i64) -> Result<Vec<Table>, Error> {
let mut stmt = tx.prepare("SELECT `id`, `app_id` FROM `app_browser` WHERE `app_id` = ?")?;
let result = stmt.query_map([app_id], |row| {

View File

@ -42,7 +42,7 @@ impl Widget {
// Actions
pub fn clean(&self, transaction: &Transaction, app_browser_id: &i64) -> Result<(), String> {
match database::records(transaction, app_browser_id) {
match database::select(transaction, app_browser_id) {
Ok(records) => {
for record in records {
match database::delete(transaction, &record.id) {
@ -61,7 +61,7 @@ impl Widget {
}
pub fn restore(&self, transaction: &Transaction, app_browser_id: &i64) -> Result<(), String> {
match database::records(transaction, app_browser_id) {
match database::select(transaction, app_browser_id) {
Ok(records) => {
for record in records {
// Restore widget
@ -80,7 +80,7 @@ impl Widget {
}
pub fn save(&self, transaction: &Transaction, app_browser_id: &i64) -> Result<(), String> {
match database::add(
match database::insert(
transaction,
app_browser_id,
&self.gobject.default_width(),

View File

@ -22,7 +22,7 @@ pub fn init(tx: &Transaction) -> Result<usize, Error> {
)
}
pub fn add(
pub fn insert(
tx: &Transaction,
app_browser_id: &i64,
default_width: &i32,
@ -45,7 +45,7 @@ pub fn add(
)
}
pub fn records(tx: &Transaction, app_browser_id: &i64) -> Result<Vec<Table>, Error> {
pub fn select(tx: &Transaction, app_browser_id: &i64) -> Result<Vec<Table>, Error> {
let mut stmt = tx.prepare(
"SELECT `id`,
`app_browser_id`,

View File

@ -107,7 +107,7 @@ impl Window {
}
pub fn clean(&self, transaction: &Transaction, app_browser_id: &i64) -> Result<(), String> {
match database::records(transaction, app_browser_id) {
match database::select(transaction, app_browser_id) {
Ok(records) => {
for record in records {
match database::delete(transaction, &record.id) {
@ -126,7 +126,7 @@ impl Window {
}
pub fn restore(&self, transaction: &Transaction, app_browser_id: &i64) -> Result<(), String> {
match database::records(transaction, app_browser_id) {
match database::select(transaction, app_browser_id) {
Ok(records) => {
for record in records {
// Delegate restore action to childs
@ -140,7 +140,7 @@ impl Window {
}
pub fn save(&self, transaction: &Transaction, app_browser_id: &i64) -> Result<(), String> {
match database::add(transaction, app_browser_id) {
match database::insert(transaction, app_browser_id) {
Ok(_) => {
// Delegate save action to childs
if let Err(e) = self

View File

@ -16,14 +16,14 @@ pub fn init(tx: &Transaction) -> Result<usize, Error> {
)
}
pub fn add(tx: &Transaction, app_browser_id: &i64) -> Result<usize, Error> {
pub fn insert(tx: &Transaction, app_browser_id: &i64) -> Result<usize, Error> {
tx.execute(
"INSERT INTO `app_browser_window` (`app_browser_id`) VALUES (?)",
[app_browser_id],
)
}
pub fn records(tx: &Transaction, app_browser_id: &i64) -> Result<Vec<Table>, Error> {
pub fn select(tx: &Transaction, app_browser_id: &i64) -> Result<Vec<Table>, Error> {
let mut stmt = tx.prepare(
"SELECT `id`,
`app_browser_id` FROM `app_browser_window`

View File

@ -248,7 +248,7 @@ impl Tab {
transaction: &Transaction,
app_browser_window_id: &i64,
) -> Result<(), String> {
match database::records(transaction, app_browser_window_id) {
match database::select(transaction, app_browser_window_id) {
Ok(records) => {
for record in records {
match database::delete(transaction, &record.id) {
@ -273,7 +273,7 @@ impl Tab {
transaction: &Transaction,
app_browser_window_id: &i64,
) -> Result<(), String> {
match database::records(transaction, app_browser_window_id) {
match database::select(transaction, app_browser_window_id) {
Ok(records) => {
for record in records {
match Item::restore(
@ -306,7 +306,7 @@ impl Tab {
transaction: &Transaction,
app_browser_window_id: &i64,
) -> Result<(), String> {
match database::add(transaction, app_browser_window_id) {
match database::insert(transaction, app_browser_window_id) {
Ok(_) => {
// Delegate save action to childs
let id = database::last_insert_id(transaction);

View File

@ -16,7 +16,7 @@ pub fn init(tx: &Transaction) -> Result<usize, Error> {
)
}
pub fn add(tx: &Transaction, app_browser_window_id: &i64) -> Result<usize, Error> {
pub fn insert(tx: &Transaction, app_browser_window_id: &i64) -> Result<usize, Error> {
tx.execute(
"INSERT INTO `app_browser_window_tab` (
`app_browser_window_id`
@ -25,7 +25,7 @@ pub fn add(tx: &Transaction, app_browser_window_id: &i64) -> Result<usize, Error
)
}
pub fn records(tx: &Transaction, app_browser_window_id: &i64) -> Result<Vec<Table>, Error> {
pub fn select(tx: &Transaction, app_browser_window_id: &i64) -> Result<Vec<Table>, Error> {
let mut stmt = tx.prepare(
"SELECT `id`,
`app_browser_window_id` FROM `app_browser_window_tab`

View File

@ -108,7 +108,7 @@ impl Item {
transaction: &Transaction,
app_browser_window_tab_id: &i64,
) -> Result<(), String> {
match database::records(transaction, app_browser_window_tab_id) {
match database::select(transaction, app_browser_window_tab_id) {
Ok(records) => {
for record in records {
match database::delete(transaction, &record.id) {
@ -139,7 +139,7 @@ impl Item {
) -> Result<Vec<Rc<Item>>, String> {
let mut items = Vec::new();
match database::records(transaction, app_browser_window_tab_id) {
match database::select(transaction, app_browser_window_tab_id) {
Ok(records) => {
for record in records {
// Construct new item object
@ -182,7 +182,7 @@ impl Item {
is_selected: &bool,
is_attention: &bool,
) -> Result<(), String> {
match database::add(
match database::insert(
transaction,
app_browser_window_tab_id,
page_position,

View File

@ -23,7 +23,7 @@ pub fn init(tx: &Transaction) -> Result<usize, Error> {
)
}
pub fn add(
pub fn insert(
tx: &Transaction,
app_browser_window_tab_id: &i64,
page_position: &i32,
@ -49,7 +49,7 @@ pub fn add(
)
}
pub fn records(tx: &Transaction, app_browser_window_tab_id: &i64) -> Result<Vec<Table>, Error> {
pub fn select(tx: &Transaction, app_browser_window_tab_id: &i64) -> Result<Vec<Table>, Error> {
let mut stmt = tx.prepare(
"SELECT `id`,
`app_browser_window_tab_id`,

View File

@ -295,7 +295,7 @@ impl Page {
transaction: &Transaction,
app_browser_window_tab_item_id: &i64,
) -> Result<(), String> {
match database::records(transaction, app_browser_window_tab_item_id) {
match database::select(transaction, app_browser_window_tab_item_id) {
Ok(records) => {
for record in records {
match database::delete(transaction, &record.id) {
@ -323,7 +323,7 @@ impl Page {
self.meta.set_status(Status::SessionRestore);
// Begin page restore
match database::records(transaction, app_browser_window_tab_item_id) {
match database::select(transaction, app_browser_window_tab_item_id) {
Ok(records) => {
for record in records {
// Delegate restore action to the item childs
@ -345,7 +345,7 @@ impl Page {
transaction: &Transaction,
app_browser_window_tab_item_id: &i64,
) -> Result<(), String> {
match database::add(transaction, app_browser_window_tab_item_id) {
match database::insert(transaction, app_browser_window_tab_item_id) {
Ok(_) => {
let id = database::last_insert_id(transaction);

View File

@ -16,7 +16,7 @@ pub fn init(tx: &Transaction) -> Result<usize, Error> {
)
}
pub fn add(tx: &Transaction, app_browser_window_tab_item_id: &i64) -> Result<usize, Error> {
pub fn insert(tx: &Transaction, app_browser_window_tab_item_id: &i64) -> Result<usize, Error> {
tx.execute(
"INSERT INTO `app_browser_window_tab_item_page` (
`app_browser_window_tab_item_id`
@ -25,10 +25,7 @@ pub fn add(tx: &Transaction, app_browser_window_tab_item_id: &i64) -> Result<usi
)
}
pub fn records(
tx: &Transaction,
app_browser_window_tab_item_id: &i64,
) -> Result<Vec<Table>, Error> {
pub fn select(tx: &Transaction, app_browser_window_tab_item_id: &i64) -> Result<Vec<Table>, Error> {
let mut stmt = tx.prepare(
"SELECT `id`,
`app_browser_window_tab_item_id`

View File

@ -111,7 +111,7 @@ impl Meta {
transaction: &Transaction,
app_browser_window_tab_page_id: &i64,
) -> Result<(), String> {
match database::records(transaction, app_browser_window_tab_page_id) {
match database::select(transaction, app_browser_window_tab_page_id) {
Ok(records) => {
for record in records {
match database::delete(transaction, &record.id) {
@ -134,7 +134,7 @@ impl Meta {
transaction: &Transaction,
app_browser_window_tab_page_id: &i64,
) -> Result<(), String> {
match database::records(transaction, app_browser_window_tab_page_id) {
match database::select(transaction, app_browser_window_tab_page_id) {
Ok(records) => {
for record in records {
// Record value can be stored as NULL
@ -160,7 +160,7 @@ impl Meta {
// Keep value in memory until operation complete
let title = self.title();
match database::add(
match database::insert(
transaction,
app_browser_window_tab_page_id,
match title.is_empty() {

View File

@ -18,7 +18,7 @@ pub fn init(tx: &Transaction) -> Result<usize, Error> {
)
}
pub fn add(
pub fn insert(
tx: &Transaction,
app_browser_window_tab_item_page_id: &i64,
title: Option<&str>,
@ -32,7 +32,7 @@ pub fn add(
)
}
pub fn records(
pub fn select(
tx: &Transaction,
app_browser_window_tab_item_page_id: &i64,
) -> Result<Vec<Table>, Error> {

View File

@ -74,7 +74,7 @@ impl Navigation {
transaction: &Transaction,
app_browser_window_tab_item_page_id: &i64,
) -> Result<(), String> {
match database::records(transaction, app_browser_window_tab_item_page_id) {
match database::select(transaction, app_browser_window_tab_item_page_id) {
Ok(records) => {
for record in records {
match database::delete(transaction, &record.id) {
@ -97,7 +97,7 @@ impl Navigation {
transaction: &Transaction,
app_browser_window_tab_item_page_id: &i64,
) -> Result<(), String> {
match database::records(transaction, app_browser_window_tab_item_page_id) {
match database::select(transaction, app_browser_window_tab_item_page_id) {
Ok(records) => {
for record in records {
// Delegate restore action to the item childs
@ -115,7 +115,7 @@ impl Navigation {
transaction: &Transaction,
app_browser_window_tab_item_page_id: &i64,
) -> Result<(), String> {
match database::add(transaction, app_browser_window_tab_item_page_id) {
match database::insert(transaction, app_browser_window_tab_item_page_id) {
Ok(_) => {
let id = database::last_insert_id(transaction);

View File

@ -16,7 +16,7 @@ pub fn init(tx: &Transaction) -> Result<usize, Error> {
)
}
pub fn add(tx: &Transaction, app_browser_window_tab_item_page_id: &i64) -> Result<usize, Error> {
pub fn insert(tx: &Transaction, app_browser_window_tab_item_page_id: &i64) -> Result<usize, Error> {
tx.execute(
"INSERT INTO `app_browser_window_tab_item_page_navigation` (
`app_browser_window_tab_item_page_id`
@ -25,7 +25,7 @@ pub fn add(tx: &Transaction, app_browser_window_tab_item_page_id: &i64) -> Resul
)
}
pub fn records(
pub fn select(
tx: &Transaction,
app_browser_window_tab_item_page_id: &i64,
) -> Result<Vec<Table>, Error> {

View File

@ -34,7 +34,7 @@ impl Request {
transaction: &Transaction,
app_browser_window_tab_item_page_navigation_id: &i64,
) -> Result<(), String> {
match database::records(transaction, app_browser_window_tab_item_page_navigation_id) {
match database::select(transaction, app_browser_window_tab_item_page_navigation_id) {
Ok(records) => {
for record in records {
match database::delete(transaction, &record.id) {
@ -57,7 +57,7 @@ impl Request {
transaction: &Transaction,
app_browser_window_tab_item_page_navigation_id: &i64,
) -> Result<(), String> {
match database::records(transaction, app_browser_window_tab_item_page_navigation_id) {
match database::select(transaction, app_browser_window_tab_item_page_navigation_id) {
Ok(records) => {
for record in records {
// Delegate restore action to the item childs
@ -75,7 +75,7 @@ impl Request {
transaction: &Transaction,
app_browser_window_tab_item_page_navigation_id: &i64,
) -> Result<(), String> {
match database::add(transaction, app_browser_window_tab_item_page_navigation_id) {
match database::insert(transaction, app_browser_window_tab_item_page_navigation_id) {
Ok(_) => {
let id = database::last_insert_id(transaction);

View File

@ -16,7 +16,7 @@ pub fn init(tx: &Transaction) -> Result<usize, Error> {
)
}
pub fn add(
pub fn insert(
tx: &Transaction,
app_browser_window_tab_item_page_navigation_id: &i64,
) -> Result<usize, Error> {
@ -28,7 +28,7 @@ pub fn add(
)
}
pub fn records(
pub fn select(
tx: &Transaction,
app_browser_window_tab_item_page_navigation_id: &i64,
) -> Result<Vec<Table>, Error> {

View File

@ -80,7 +80,7 @@ impl Widget {
transaction: &Transaction,
app_browser_window_tab_item_page_navigation_request_id: &i64,
) -> Result<(), String> {
match database::records(
match database::select(
transaction,
app_browser_window_tab_item_page_navigation_request_id,
) {
@ -106,7 +106,7 @@ impl Widget {
transaction: &Transaction,
app_browser_window_tab_item_page_navigation_request_id: &i64,
) -> Result<(), String> {
match database::records(
match database::select(
transaction,
app_browser_window_tab_item_page_navigation_request_id,
) {
@ -134,7 +134,7 @@ impl Widget {
// Keep value in memory until operation complete
let text = self.gobject.text();
match database::add(
match database::insert(
transaction,
app_browser_window_tab_item_page_navigation_request_id,
match text.is_empty() {

View File

@ -18,7 +18,7 @@ pub fn init(tx: &Transaction) -> Result<usize, Error> {
)
}
pub fn add(
pub fn insert(
tx: &Transaction,
app_browser_window_tab_item_page_navigation_request_id: &i64,
text: Option<&str>,
@ -32,7 +32,7 @@ pub fn add(
)
}
pub fn records(
pub fn select(
tx: &Transaction,
app_browser_window_tab_item_page_navigation_request_id: &i64,
) -> Result<Vec<Table>, Error> {

View File

@ -60,7 +60,7 @@ impl Widget {
transaction: &Transaction,
app_browser_window_tab_item_id: &i64,
) -> Result<(), String> {
match database::records(transaction, app_browser_window_tab_item_id) {
match database::select(transaction, app_browser_window_tab_item_id) {
Ok(records) => {
for record in records {
match database::delete(transaction, &record.id) {
@ -83,7 +83,7 @@ impl Widget {
transaction: &Transaction,
app_browser_window_tab_item_id: &i64,
) -> Result<(), String> {
match database::records(transaction, app_browser_window_tab_item_id) {
match database::select(transaction, app_browser_window_tab_item_id) {
Ok(records) => {
for record in records {
// Record value can be stored as NULL
@ -109,7 +109,7 @@ impl Widget {
// Keep value in memory until operation complete
let title = self.gobject.title();
match database::add(
match database::insert(
transaction,
app_browser_window_tab_item_id,
match title.is_empty() {

View File

@ -18,7 +18,7 @@ pub fn init(tx: &Transaction) -> Result<usize, Error> {
)
}
pub fn add(
pub fn insert(
tx: &Transaction,
app_browser_window_tab_item_id: &i64,
title: Option<&str>,
@ -32,10 +32,7 @@ pub fn add(
)
}
pub fn records(
tx: &Transaction,
app_browser_window_tab_item_id: &i64,
) -> Result<Vec<Table>, Error> {
pub fn select(tx: &Transaction, app_browser_window_tab_item_id: &i64) -> Result<Vec<Table>, Error> {
let mut stmt = tx.prepare(
"SELECT `id`,
`app_browser_window_tab_item_id`,

View File

@ -14,11 +14,11 @@ pub fn init(tx: &Transaction) -> Result<usize, Error> {
)
}
pub fn add(tx: &Transaction) -> Result<usize, Error> {
pub fn insert(tx: &Transaction) -> Result<usize, Error> {
tx.execute("INSERT INTO `app` DEFAULT VALUES", [])
}
pub fn records(tx: &Transaction) -> Result<Vec<Table>, Error> {
pub fn select(tx: &Transaction) -> Result<Vec<Table>, Error> {
let mut stmt = tx.prepare("SELECT `id` FROM `app`")?;
let result = stmt.query_map([], |row| Ok(Table { id: row.get(0)? }))?;

View File

@ -12,6 +12,8 @@ pub struct Bookmark {
// nothing yet..
}
// Low-level DB API
pub fn init(tx: &Transaction) -> Result<usize, Error> {
tx.execute(
"CREATE TABLE IF NOT EXISTS `profile_bookmark`
@ -25,7 +27,7 @@ pub fn init(tx: &Transaction) -> Result<usize, Error> {
)
}
pub fn add(
pub fn insert(
tx: &Transaction,
profile_id: &i64,
time: &DateTime,
@ -41,7 +43,7 @@ pub fn add(
)
}
pub fn records(
pub fn select(
tx: &Transaction,
profile_id: &i64,
request: Option<&str>,

View File

@ -12,6 +12,8 @@ pub struct History {
// nothing yet..
}
// Low-level DB API
pub fn init(tx: &Transaction) -> Result<usize, Error> {
tx.execute(
"CREATE TABLE IF NOT EXISTS `profile_history`
@ -25,7 +27,7 @@ pub fn init(tx: &Transaction) -> Result<usize, Error> {
)
}
pub fn add(
pub fn insert(
tx: &Transaction,
profile_id: &i64,
time: &DateTime,
@ -41,7 +43,7 @@ pub fn add(
)
}
pub fn records(
pub fn select(
tx: &Transaction,
profile_id: &i64,
request: Option<&str>,

View File

@ -5,6 +5,8 @@ pub struct Table {
//pub profile_id: i64,
}
// Low-level DB API
pub fn init(tx: &Transaction) -> Result<usize, Error> {
tx.execute(
"CREATE TABLE IF NOT EXISTS `profile_identity`