mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-03-31 16:45:27 +00:00
remove extra rc wrapper
This commit is contained in:
parent
b71b2cd7fa
commit
4002c94a4a
9 changed files with 53 additions and 56 deletions
|
|
@ -19,7 +19,7 @@ impl Bookmark {
|
|||
// Constructors
|
||||
|
||||
/// Create new `Self`
|
||||
pub fn build(connection: &Rc<RwLock<Connection>>, profile_id: &Rc<i64>) -> Result<Self> {
|
||||
pub fn build(connection: &Rc<RwLock<Connection>>, profile_id: i64) -> Result<Self> {
|
||||
// Init children components
|
||||
let database = Database::new(connection, profile_id);
|
||||
let memory = RefCell::new(Memory::new());
|
||||
|
|
|
|||
|
|
@ -6,17 +6,17 @@ use std::{rc::Rc, sync::RwLock};
|
|||
|
||||
pub struct Database {
|
||||
connection: Rc<RwLock<Connection>>,
|
||||
profile_id: Rc<i64>, // multi-profile relationship
|
||||
profile_id: i64,
|
||||
}
|
||||
|
||||
impl Database {
|
||||
// Constructors
|
||||
|
||||
/// Create new `Self`
|
||||
pub fn new(connection: &Rc<RwLock<Connection>>, profile_id: &Rc<i64>) -> Self {
|
||||
pub fn new(connection: &Rc<RwLock<Connection>>, profile_id: i64) -> Self {
|
||||
Self {
|
||||
connection: connection.clone(),
|
||||
profile_id: profile_id.clone(),
|
||||
profile_id,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -26,7 +26,7 @@ impl Database {
|
|||
pub fn records(&self, request: Option<&str>, title: Option<&str>) -> Result<Vec<Item>> {
|
||||
let readable = self.connection.read().unwrap(); // @TODO
|
||||
let tx = readable.unchecked_transaction()?;
|
||||
select(&tx, *self.profile_id, request, title)
|
||||
select(&tx, self.profile_id, request, title)
|
||||
}
|
||||
|
||||
// Setters
|
||||
|
|
@ -36,7 +36,7 @@ impl Database {
|
|||
pub fn add(&self, time: DateTime, request: &str, title: Option<&str>) -> Result<i64> {
|
||||
let mut writable = self.connection.write().unwrap(); // @TODO
|
||||
let tx = writable.transaction()?;
|
||||
let id = insert(&tx, *self.profile_id, time, request, title)?;
|
||||
let id = insert(&tx, self.profile_id, time, request, title)?;
|
||||
tx.commit()?;
|
||||
Ok(id)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ impl History {
|
|||
// Constructors
|
||||
|
||||
/// Create new `Self`
|
||||
pub fn build(connection: &Rc<RwLock<Connection>>, profile_id: &Rc<i64>) -> Result<Self> {
|
||||
pub fn build(connection: &Rc<RwLock<Connection>>, profile_id: i64) -> Result<Self> {
|
||||
// Init children components
|
||||
let database = Database::build(connection, profile_id);
|
||||
let memory = RefCell::new(Memory::new());
|
||||
|
|
|
|||
|
|
@ -6,17 +6,17 @@ use std::{rc::Rc, sync::RwLock};
|
|||
|
||||
pub struct Database {
|
||||
connection: Rc<RwLock<Connection>>,
|
||||
profile_id: Rc<i64>, // multi-profile relationship
|
||||
profile_id: i64,
|
||||
}
|
||||
|
||||
impl Database {
|
||||
// Constructors
|
||||
|
||||
/// Create new `Self`
|
||||
pub fn build(connection: &Rc<RwLock<Connection>>, profile_id: &Rc<i64>) -> Self {
|
||||
pub fn build(connection: &Rc<RwLock<Connection>>, profile_id: i64) -> Self {
|
||||
Self {
|
||||
connection: connection.clone(),
|
||||
profile_id: profile_id.clone(),
|
||||
profile_id,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -26,7 +26,7 @@ impl Database {
|
|||
pub fn records(&self, request: Option<&str>, title: Option<&str>) -> Result<Vec<Item>> {
|
||||
let readable = self.connection.read().unwrap(); // @TODO
|
||||
let tx = readable.unchecked_transaction()?;
|
||||
select(&tx, *self.profile_id, request, title)
|
||||
select(&tx, self.profile_id, request, title)
|
||||
}
|
||||
|
||||
// Actions
|
||||
|
|
@ -36,7 +36,7 @@ impl Database {
|
|||
pub fn add(&self, item: &Item) -> Result<i64> {
|
||||
let mut writable = self.connection.write().unwrap(); // @TODO
|
||||
let tx = writable.transaction()?;
|
||||
let id = insert(&tx, *self.profile_id, item)?;
|
||||
let id = insert(&tx, self.profile_id, item)?;
|
||||
tx.commit()?;
|
||||
Ok(id)
|
||||
}
|
||||
|
|
@ -44,7 +44,7 @@ impl Database {
|
|||
pub fn update(&self, item: &Item) -> Result<usize> {
|
||||
let mut writable = self.connection.write().unwrap(); // @TODO
|
||||
let tx = writable.transaction()?;
|
||||
let affected = update(&tx, *self.profile_id, item)?;
|
||||
let affected = update(&tx, self.profile_id, item)?;
|
||||
tx.commit()?;
|
||||
Ok(affected)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,23 +17,20 @@ use std::{rc::Rc, sync::RwLock};
|
|||
///
|
||||
/// https://geminiprotocol.net/docs/protocol-specification.gmi#client-certificates
|
||||
pub struct Identity {
|
||||
pub auth: Rc<Auth>,
|
||||
pub database: Rc<Database>,
|
||||
pub memory: Rc<Memory>,
|
||||
}
|
||||
pub auth: Auth,
|
||||
pub database: Database,
|
||||
pub memory: Memory,
|
||||
} // @TODO remove pub access
|
||||
|
||||
impl Identity {
|
||||
// Constructors
|
||||
|
||||
/// Create new `Self`
|
||||
pub fn build(
|
||||
connection: &Rc<RwLock<Connection>>,
|
||||
profile_identity_id: &Rc<i64>,
|
||||
) -> Result<Self> {
|
||||
pub fn build(connection: &Rc<RwLock<Connection>>, profile_identity_id: i64) -> Result<Self> {
|
||||
// Init components
|
||||
let auth = Rc::new(Auth::build(connection)?);
|
||||
let database = Rc::new(Database::build(connection, profile_identity_id));
|
||||
let memory = Rc::new(Memory::new());
|
||||
let auth = Auth::build(connection)?;
|
||||
let database = Database::build(connection, profile_identity_id);
|
||||
let memory = Memory::new();
|
||||
|
||||
// Init `Self`
|
||||
let this = Self {
|
||||
|
|
|
|||
|
|
@ -10,17 +10,17 @@ pub struct Table {
|
|||
/// Storage for Gemini auth certificates
|
||||
pub struct Database {
|
||||
connection: Rc<RwLock<Connection>>,
|
||||
profile_id: Rc<i64>, // multi-profile relationship
|
||||
profile_id: i64,
|
||||
}
|
||||
|
||||
impl Database {
|
||||
// Constructors
|
||||
|
||||
/// Create new `Self`
|
||||
pub fn build(connection: &Rc<RwLock<Connection>>, profile_id: &Rc<i64>) -> Self {
|
||||
pub fn build(connection: &Rc<RwLock<Connection>>, profile_id: i64) -> Self {
|
||||
Self {
|
||||
connection: connection.clone(),
|
||||
profile_id: profile_id.clone(),
|
||||
profile_id,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -33,7 +33,7 @@ impl Database {
|
|||
let tx = writable.transaction()?;
|
||||
|
||||
// Create new record
|
||||
insert(&tx, *self.profile_id, pem)?;
|
||||
insert(&tx, self.profile_id, pem)?;
|
||||
|
||||
// Hold insert ID for result
|
||||
let id = last_insert_id(&tx);
|
||||
|
|
@ -65,7 +65,7 @@ impl Database {
|
|||
pub fn record(&self, id: i64) -> Result<Option<Table>, Error> {
|
||||
let readable = self.connection.read().unwrap();
|
||||
let tx = readable.unchecked_transaction()?;
|
||||
let records = select(&tx, *self.profile_id)?; // @TODO single record query
|
||||
let records = select(&tx, self.profile_id)?; // @TODO single record query
|
||||
|
||||
for record in records {
|
||||
if record.id == id {
|
||||
|
|
@ -80,7 +80,7 @@ impl Database {
|
|||
pub fn records(&self) -> Result<Vec<Table>, Error> {
|
||||
let readable = self.connection.read().unwrap(); // @TODO
|
||||
let tx = readable.unchecked_transaction()?;
|
||||
select(&tx, *self.profile_id)
|
||||
select(&tx, self.profile_id)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ impl Search {
|
|||
// Constructors
|
||||
|
||||
/// Create new `Self`
|
||||
pub fn build(connection: &Rc<RwLock<Connection>>, profile_id: &Rc<i64>) -> Result<Self> {
|
||||
pub fn build(connection: &Rc<RwLock<Connection>>, profile_id: i64) -> Result<Self> {
|
||||
let database = Database::init(connection, profile_id)?;
|
||||
// Init fast search index
|
||||
let memory = Memory::init();
|
||||
|
|
|
|||
|
|
@ -12,27 +12,27 @@ pub struct Row {
|
|||
|
||||
pub struct Database {
|
||||
connection: Rc<RwLock<Connection>>,
|
||||
profile_id: Rc<i64>, // multi-profile relationship
|
||||
profile_id: i64,
|
||||
}
|
||||
|
||||
impl Database {
|
||||
// Constructors
|
||||
|
||||
/// Create new `Self`
|
||||
pub fn init(connection: &Rc<RwLock<Connection>>, profile_id: &Rc<i64>) -> Result<Self> {
|
||||
pub fn init(connection: &Rc<RwLock<Connection>>, profile_id: i64) -> Result<Self> {
|
||||
let mut writable = connection.write().unwrap(); // @TODO handle
|
||||
let tx = writable.transaction()?;
|
||||
|
||||
let records = select(&tx, **profile_id)?;
|
||||
let records = select(&tx, profile_id)?;
|
||||
|
||||
if records.is_empty() {
|
||||
add_defaults(&tx, **profile_id)?;
|
||||
add_defaults(&tx, profile_id)?;
|
||||
tx.commit()?;
|
||||
}
|
||||
|
||||
Ok(Self {
|
||||
connection: connection.clone(),
|
||||
profile_id: profile_id.clone(),
|
||||
profile_id,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -42,7 +42,7 @@ impl Database {
|
|||
pub fn records(&self) -> Result<Vec<Row>> {
|
||||
let readable = self.connection.read().unwrap(); // @TODO handle
|
||||
let tx = readable.unchecked_transaction()?;
|
||||
select(&tx, *self.profile_id)
|
||||
select(&tx, self.profile_id)
|
||||
}
|
||||
|
||||
// Setters
|
||||
|
|
@ -53,9 +53,9 @@ impl Database {
|
|||
let mut writable = self.connection.write().unwrap(); // @TODO handle
|
||||
let tx = writable.transaction()?;
|
||||
if is_default {
|
||||
reset(&tx, *self.profile_id, !is_default)?;
|
||||
reset(&tx, self.profile_id, !is_default)?;
|
||||
}
|
||||
let id = insert(&tx, *self.profile_id, query, is_default)?;
|
||||
let id = insert(&tx, self.profile_id, query, is_default)?;
|
||||
tx.commit()?;
|
||||
Ok(id)
|
||||
}
|
||||
|
|
@ -69,11 +69,11 @@ impl Database {
|
|||
// Delete record by ID
|
||||
delete(&tx, id)?;
|
||||
|
||||
let records = select(&tx, *self.profile_id)?;
|
||||
let records = select(&tx, self.profile_id)?;
|
||||
|
||||
// Restore defaults if DB becomes empty
|
||||
if records.is_empty() {
|
||||
add_defaults(&tx, *self.profile_id)?;
|
||||
add_defaults(&tx, self.profile_id)?;
|
||||
} else {
|
||||
// At least one provider should be selected as default
|
||||
let mut has_default = false;
|
||||
|
|
@ -85,7 +85,7 @@ impl Database {
|
|||
}
|
||||
// Select first
|
||||
if !has_default {
|
||||
set_default(&tx, *self.profile_id, records[0].id, true)?;
|
||||
set_default(&tx, self.profile_id, records[0].id, true)?;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -101,10 +101,10 @@ impl Database {
|
|||
let tx = writable.transaction()?;
|
||||
|
||||
// Make sure only one default provider in set
|
||||
reset(&tx, *self.profile_id, false)?;
|
||||
reset(&tx, self.profile_id, false)?;
|
||||
|
||||
// Delete record by ID
|
||||
set_default(&tx, *self.profile_id, id, true)?;
|
||||
set_default(&tx, self.profile_id, id, true)?;
|
||||
tx.commit()?;
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue