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

View File

@ -104,7 +104,7 @@ impl Browser {
// Actions // Actions
pub fn clean(&self, transaction: &Transaction, app_id: &i64) -> Result<(), String> { 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) => { Ok(records) => {
for record in records { for record in records {
match database::delete(transaction, &record.id) { match database::delete(transaction, &record.id) {
@ -127,7 +127,7 @@ impl Browser {
} }
pub fn restore(&self, transaction: &Transaction, app_id: &i64) -> Result<(), String> { 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) => { Ok(records) => {
for record in records { for record in records {
// Delegate restore action to childs // Delegate restore action to childs
@ -145,7 +145,7 @@ impl Browser {
} }
pub fn save(&self, transaction: &Transaction, app_id: &i64) -> Result<(), String> { pub fn save(&self, transaction: &Transaction, app_id: &i64) -> Result<(), String> {
match database::add(transaction, app_id) { match database::insert(transaction, app_id) {
Ok(_) => { Ok(_) => {
let id = database::last_insert_id(transaction); 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]) 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 mut stmt = tx.prepare("SELECT `id`, `app_id` FROM `app_browser` WHERE `app_id` = ?")?;
let result = stmt.query_map([app_id], |row| { let result = stmt.query_map([app_id], |row| {

View File

@ -42,7 +42,7 @@ impl Widget {
// Actions // Actions
pub fn clean(&self, transaction: &Transaction, app_browser_id: &i64) -> Result<(), String> { 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) => { Ok(records) => {
for record in records { for record in records {
match database::delete(transaction, &record.id) { match database::delete(transaction, &record.id) {
@ -61,7 +61,7 @@ impl Widget {
} }
pub fn restore(&self, transaction: &Transaction, app_browser_id: &i64) -> Result<(), String> { 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) => { Ok(records) => {
for record in records { for record in records {
// Restore widget // Restore widget
@ -80,7 +80,7 @@ impl Widget {
} }
pub fn save(&self, transaction: &Transaction, app_browser_id: &i64) -> Result<(), String> { pub fn save(&self, transaction: &Transaction, app_browser_id: &i64) -> Result<(), String> {
match database::add( match database::insert(
transaction, transaction,
app_browser_id, app_browser_id,
&self.gobject.default_width(), &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, tx: &Transaction,
app_browser_id: &i64, app_browser_id: &i64,
default_width: &i32, 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( let mut stmt = tx.prepare(
"SELECT `id`, "SELECT `id`,
`app_browser_id`, `app_browser_id`,

View File

@ -107,7 +107,7 @@ impl Window {
} }
pub fn clean(&self, transaction: &Transaction, app_browser_id: &i64) -> Result<(), String> { 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) => { Ok(records) => {
for record in records { for record in records {
match database::delete(transaction, &record.id) { match database::delete(transaction, &record.id) {
@ -126,7 +126,7 @@ impl Window {
} }
pub fn restore(&self, transaction: &Transaction, app_browser_id: &i64) -> Result<(), String> { 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) => { Ok(records) => {
for record in records { for record in records {
// Delegate restore action to childs // Delegate restore action to childs
@ -140,7 +140,7 @@ impl Window {
} }
pub fn save(&self, transaction: &Transaction, app_browser_id: &i64) -> Result<(), String> { 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(_) => { Ok(_) => {
// Delegate save action to childs // Delegate save action to childs
if let Err(e) = self 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( tx.execute(
"INSERT INTO `app_browser_window` (`app_browser_id`) VALUES (?)", "INSERT INTO `app_browser_window` (`app_browser_id`) VALUES (?)",
[app_browser_id], [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( let mut stmt = tx.prepare(
"SELECT `id`, "SELECT `id`,
`app_browser_id` FROM `app_browser_window` `app_browser_id` FROM `app_browser_window`

View File

@ -248,7 +248,7 @@ impl Tab {
transaction: &Transaction, transaction: &Transaction,
app_browser_window_id: &i64, app_browser_window_id: &i64,
) -> Result<(), String> { ) -> Result<(), String> {
match database::records(transaction, app_browser_window_id) { match database::select(transaction, app_browser_window_id) {
Ok(records) => { Ok(records) => {
for record in records { for record in records {
match database::delete(transaction, &record.id) { match database::delete(transaction, &record.id) {
@ -273,7 +273,7 @@ impl Tab {
transaction: &Transaction, transaction: &Transaction,
app_browser_window_id: &i64, app_browser_window_id: &i64,
) -> Result<(), String> { ) -> Result<(), String> {
match database::records(transaction, app_browser_window_id) { match database::select(transaction, app_browser_window_id) {
Ok(records) => { Ok(records) => {
for record in records { for record in records {
match Item::restore( match Item::restore(
@ -306,7 +306,7 @@ impl Tab {
transaction: &Transaction, transaction: &Transaction,
app_browser_window_id: &i64, app_browser_window_id: &i64,
) -> Result<(), String> { ) -> Result<(), String> {
match database::add(transaction, app_browser_window_id) { match database::insert(transaction, app_browser_window_id) {
Ok(_) => { Ok(_) => {
// Delegate save action to childs // Delegate save action to childs
let id = database::last_insert_id(transaction); 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( tx.execute(
"INSERT INTO `app_browser_window_tab` ( "INSERT INTO `app_browser_window_tab` (
`app_browser_window_id` `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( let mut stmt = tx.prepare(
"SELECT `id`, "SELECT `id`,
`app_browser_window_id` FROM `app_browser_window_tab` `app_browser_window_id` FROM `app_browser_window_tab`

View File

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

View File

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

View File

@ -295,7 +295,7 @@ impl Page {
transaction: &Transaction, transaction: &Transaction,
app_browser_window_tab_item_id: &i64, app_browser_window_tab_item_id: &i64,
) -> Result<(), String> { ) -> Result<(), String> {
match database::records(transaction, app_browser_window_tab_item_id) { match database::select(transaction, app_browser_window_tab_item_id) {
Ok(records) => { Ok(records) => {
for record in records { for record in records {
match database::delete(transaction, &record.id) { match database::delete(transaction, &record.id) {
@ -323,7 +323,7 @@ impl Page {
self.meta.set_status(Status::SessionRestore); self.meta.set_status(Status::SessionRestore);
// Begin page restore // 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) => { Ok(records) => {
for record in records { for record in records {
// Delegate restore action to the item childs // Delegate restore action to the item childs
@ -345,7 +345,7 @@ impl Page {
transaction: &Transaction, transaction: &Transaction,
app_browser_window_tab_item_id: &i64, app_browser_window_tab_item_id: &i64,
) -> Result<(), String> { ) -> Result<(), String> {
match database::add(transaction, app_browser_window_tab_item_id) { match database::insert(transaction, app_browser_window_tab_item_id) {
Ok(_) => { Ok(_) => {
let id = database::last_insert_id(transaction); 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( tx.execute(
"INSERT INTO `app_browser_window_tab_item_page` ( "INSERT INTO `app_browser_window_tab_item_page` (
`app_browser_window_tab_item_id` `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( pub fn select(tx: &Transaction, app_browser_window_tab_item_id: &i64) -> Result<Vec<Table>, Error> {
tx: &Transaction,
app_browser_window_tab_item_id: &i64,
) -> Result<Vec<Table>, Error> {
let mut stmt = tx.prepare( let mut stmt = tx.prepare(
"SELECT `id`, "SELECT `id`,
`app_browser_window_tab_item_id` `app_browser_window_tab_item_id`

View File

@ -111,7 +111,7 @@ impl Meta {
transaction: &Transaction, transaction: &Transaction,
app_browser_window_tab_page_id: &i64, app_browser_window_tab_page_id: &i64,
) -> Result<(), String> { ) -> Result<(), String> {
match database::records(transaction, app_browser_window_tab_page_id) { match database::select(transaction, app_browser_window_tab_page_id) {
Ok(records) => { Ok(records) => {
for record in records { for record in records {
match database::delete(transaction, &record.id) { match database::delete(transaction, &record.id) {
@ -134,7 +134,7 @@ impl Meta {
transaction: &Transaction, transaction: &Transaction,
app_browser_window_tab_page_id: &i64, app_browser_window_tab_page_id: &i64,
) -> Result<(), String> { ) -> Result<(), String> {
match database::records(transaction, app_browser_window_tab_page_id) { match database::select(transaction, app_browser_window_tab_page_id) {
Ok(records) => { Ok(records) => {
for record in records { for record in records {
// Record value can be stored as NULL // Record value can be stored as NULL
@ -160,7 +160,7 @@ impl Meta {
// Keep value in memory until operation complete // Keep value in memory until operation complete
let title = self.title(); let title = self.title();
match database::add( match database::insert(
transaction, transaction,
app_browser_window_tab_page_id, app_browser_window_tab_page_id,
match title.is_empty() { 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, tx: &Transaction,
app_browser_window_tab_item_page_id: &i64, app_browser_window_tab_item_page_id: &i64,
title: Option<&str>, title: Option<&str>,
@ -32,7 +32,7 @@ pub fn add(
) )
} }
pub fn records( pub fn select(
tx: &Transaction, tx: &Transaction,
app_browser_window_tab_item_page_id: &i64, app_browser_window_tab_item_page_id: &i64,
) -> Result<Vec<Table>, Error> { ) -> Result<Vec<Table>, Error> {

View File

@ -74,7 +74,7 @@ impl Navigation {
transaction: &Transaction, transaction: &Transaction,
app_browser_window_tab_item_page_id: &i64, app_browser_window_tab_item_page_id: &i64,
) -> Result<(), String> { ) -> 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) => { Ok(records) => {
for record in records { for record in records {
match database::delete(transaction, &record.id) { match database::delete(transaction, &record.id) {
@ -97,7 +97,7 @@ impl Navigation {
transaction: &Transaction, transaction: &Transaction,
app_browser_window_tab_item_page_id: &i64, app_browser_window_tab_item_page_id: &i64,
) -> Result<(), String> { ) -> 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) => { Ok(records) => {
for record in records { for record in records {
// Delegate restore action to the item childs // Delegate restore action to the item childs
@ -115,7 +115,7 @@ impl Navigation {
transaction: &Transaction, transaction: &Transaction,
app_browser_window_tab_item_page_id: &i64, app_browser_window_tab_item_page_id: &i64,
) -> Result<(), String> { ) -> 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(_) => { Ok(_) => {
let id = database::last_insert_id(transaction); 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( tx.execute(
"INSERT INTO `app_browser_window_tab_item_page_navigation` ( "INSERT INTO `app_browser_window_tab_item_page_navigation` (
`app_browser_window_tab_item_page_id` `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, tx: &Transaction,
app_browser_window_tab_item_page_id: &i64, app_browser_window_tab_item_page_id: &i64,
) -> Result<Vec<Table>, Error> { ) -> Result<Vec<Table>, Error> {

View File

@ -34,7 +34,7 @@ impl Request {
transaction: &Transaction, transaction: &Transaction,
app_browser_window_tab_item_page_navigation_id: &i64, app_browser_window_tab_item_page_navigation_id: &i64,
) -> Result<(), String> { ) -> 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) => { Ok(records) => {
for record in records { for record in records {
match database::delete(transaction, &record.id) { match database::delete(transaction, &record.id) {
@ -57,7 +57,7 @@ impl Request {
transaction: &Transaction, transaction: &Transaction,
app_browser_window_tab_item_page_navigation_id: &i64, app_browser_window_tab_item_page_navigation_id: &i64,
) -> Result<(), String> { ) -> 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) => { Ok(records) => {
for record in records { for record in records {
// Delegate restore action to the item childs // Delegate restore action to the item childs
@ -75,7 +75,7 @@ impl Request {
transaction: &Transaction, transaction: &Transaction,
app_browser_window_tab_item_page_navigation_id: &i64, app_browser_window_tab_item_page_navigation_id: &i64,
) -> Result<(), String> { ) -> 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(_) => { Ok(_) => {
let id = database::last_insert_id(transaction); 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, tx: &Transaction,
app_browser_window_tab_item_page_navigation_id: &i64, app_browser_window_tab_item_page_navigation_id: &i64,
) -> Result<usize, Error> { ) -> Result<usize, Error> {
@ -28,7 +28,7 @@ pub fn add(
) )
} }
pub fn records( pub fn select(
tx: &Transaction, tx: &Transaction,
app_browser_window_tab_item_page_navigation_id: &i64, app_browser_window_tab_item_page_navigation_id: &i64,
) -> Result<Vec<Table>, Error> { ) -> Result<Vec<Table>, Error> {

View File

@ -80,7 +80,7 @@ impl Widget {
transaction: &Transaction, transaction: &Transaction,
app_browser_window_tab_item_page_navigation_request_id: &i64, app_browser_window_tab_item_page_navigation_request_id: &i64,
) -> Result<(), String> { ) -> Result<(), String> {
match database::records( match database::select(
transaction, transaction,
app_browser_window_tab_item_page_navigation_request_id, app_browser_window_tab_item_page_navigation_request_id,
) { ) {
@ -106,7 +106,7 @@ impl Widget {
transaction: &Transaction, transaction: &Transaction,
app_browser_window_tab_item_page_navigation_request_id: &i64, app_browser_window_tab_item_page_navigation_request_id: &i64,
) -> Result<(), String> { ) -> Result<(), String> {
match database::records( match database::select(
transaction, transaction,
app_browser_window_tab_item_page_navigation_request_id, app_browser_window_tab_item_page_navigation_request_id,
) { ) {
@ -134,7 +134,7 @@ impl Widget {
// Keep value in memory until operation complete // Keep value in memory until operation complete
let text = self.gobject.text(); let text = self.gobject.text();
match database::add( match database::insert(
transaction, transaction,
app_browser_window_tab_item_page_navigation_request_id, app_browser_window_tab_item_page_navigation_request_id,
match text.is_empty() { 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, tx: &Transaction,
app_browser_window_tab_item_page_navigation_request_id: &i64, app_browser_window_tab_item_page_navigation_request_id: &i64,
text: Option<&str>, text: Option<&str>,
@ -32,7 +32,7 @@ pub fn add(
) )
} }
pub fn records( pub fn select(
tx: &Transaction, tx: &Transaction,
app_browser_window_tab_item_page_navigation_request_id: &i64, app_browser_window_tab_item_page_navigation_request_id: &i64,
) -> Result<Vec<Table>, Error> { ) -> Result<Vec<Table>, Error> {

View File

@ -60,7 +60,7 @@ impl Widget {
transaction: &Transaction, transaction: &Transaction,
app_browser_window_tab_item_id: &i64, app_browser_window_tab_item_id: &i64,
) -> Result<(), String> { ) -> Result<(), String> {
match database::records(transaction, app_browser_window_tab_item_id) { match database::select(transaction, app_browser_window_tab_item_id) {
Ok(records) => { Ok(records) => {
for record in records { for record in records {
match database::delete(transaction, &record.id) { match database::delete(transaction, &record.id) {
@ -83,7 +83,7 @@ impl Widget {
transaction: &Transaction, transaction: &Transaction,
app_browser_window_tab_item_id: &i64, app_browser_window_tab_item_id: &i64,
) -> Result<(), String> { ) -> Result<(), String> {
match database::records(transaction, app_browser_window_tab_item_id) { match database::select(transaction, app_browser_window_tab_item_id) {
Ok(records) => { Ok(records) => {
for record in records { for record in records {
// Record value can be stored as NULL // Record value can be stored as NULL
@ -109,7 +109,7 @@ impl Widget {
// Keep value in memory until operation complete // Keep value in memory until operation complete
let title = self.gobject.title(); let title = self.gobject.title();
match database::add( match database::insert(
transaction, transaction,
app_browser_window_tab_item_id, app_browser_window_tab_item_id,
match title.is_empty() { 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, tx: &Transaction,
app_browser_window_tab_item_id: &i64, app_browser_window_tab_item_id: &i64,
title: Option<&str>, title: Option<&str>,
@ -32,10 +32,7 @@ pub fn add(
) )
} }
pub fn records( pub fn select(tx: &Transaction, app_browser_window_tab_item_id: &i64) -> Result<Vec<Table>, Error> {
tx: &Transaction,
app_browser_window_tab_item_id: &i64,
) -> Result<Vec<Table>, Error> {
let mut stmt = tx.prepare( let mut stmt = tx.prepare(
"SELECT `id`, "SELECT `id`,
`app_browser_window_tab_item_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", []) 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 mut stmt = tx.prepare("SELECT `id` FROM `app`")?;
let result = stmt.query_map([], |row| Ok(Table { id: row.get(0)? }))?; let result = stmt.query_map([], |row| Ok(Table { id: row.get(0)? }))?;

View File

@ -12,6 +12,8 @@ pub struct Bookmark {
// nothing yet.. // nothing yet..
} }
// Low-level DB API
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_bookmark` "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, tx: &Transaction,
profile_id: &i64, profile_id: &i64,
time: &DateTime, time: &DateTime,
@ -41,7 +43,7 @@ pub fn add(
) )
} }
pub fn records( pub fn select(
tx: &Transaction, tx: &Transaction,
profile_id: &i64, profile_id: &i64,
request: Option<&str>, request: Option<&str>,

View File

@ -12,6 +12,8 @@ pub struct History {
// nothing yet.. // nothing yet..
} }
// Low-level DB API
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_history` "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, tx: &Transaction,
profile_id: &i64, profile_id: &i64,
time: &DateTime, time: &DateTime,
@ -41,7 +43,7 @@ pub fn add(
) )
} }
pub fn records( pub fn select(
tx: &Transaction, tx: &Transaction,
profile_id: &i64, profile_id: &i64,
request: Option<&str>, request: Option<&str>,

View File

@ -5,6 +5,8 @@ pub struct Table {
//pub profile_id: i64, //pub profile_id: i64,
} }
// Low-level DB API
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_identity` "CREATE TABLE IF NOT EXISTS `profile_identity`