mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-01-15 17:20:08 +00:00
use shared pointer for profile_id value
This commit is contained in:
parent
fa7080762e
commit
be30ec660f
@ -83,13 +83,13 @@ impl Profile {
|
|||||||
let database = Rc::new(Database::new(connection.clone()));
|
let database = Rc::new(Database::new(connection.clone()));
|
||||||
|
|
||||||
// Get active profile or create new one
|
// Get active profile or create new one
|
||||||
let profile_id = match database.active() {
|
let profile_id = Rc::new(match database.active() {
|
||||||
Some(profile) => profile.id,
|
Some(profile) => profile.id,
|
||||||
None => match database.add(true, DateTime::now_local().unwrap(), None) {
|
None => match database.add(true, DateTime::now_local().unwrap(), None) {
|
||||||
Ok(id) => id,
|
Ok(id) => id,
|
||||||
Err(_) => todo!(),
|
Err(_) => todo!(),
|
||||||
},
|
},
|
||||||
};
|
});
|
||||||
|
|
||||||
// Result
|
// Result
|
||||||
Self {
|
Self {
|
||||||
|
@ -19,7 +19,7 @@ impl Bookmark {
|
|||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
/// Create new `Self`
|
/// Create new `Self`
|
||||||
pub fn new(connection: Rc<RwLock<Connection>>, profile_id: i64) -> Self {
|
pub fn new(connection: Rc<RwLock<Connection>>, profile_id: Rc<i64>) -> Self {
|
||||||
// Init children components
|
// Init children components
|
||||||
let database = Rc::new(Database::new(connection, profile_id));
|
let database = Rc::new(Database::new(connection, profile_id));
|
||||||
let memory = Rc::new(Memory::new());
|
let memory = Rc::new(Memory::new());
|
||||||
|
@ -11,14 +11,14 @@ pub struct Table {
|
|||||||
|
|
||||||
pub struct Database {
|
pub struct Database {
|
||||||
connection: Rc<RwLock<Connection>>,
|
connection: Rc<RwLock<Connection>>,
|
||||||
profile_id: i64, // multi-profile relationship @TODO shared reference?
|
profile_id: Rc<i64>, // multi-profile relationship
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Database {
|
impl Database {
|
||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
/// Create new `Self`
|
/// Create new `Self`
|
||||||
pub fn new(connection: Rc<RwLock<Connection>>, profile_id: i64) -> Self {
|
pub fn new(connection: Rc<RwLock<Connection>>, profile_id: Rc<i64>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
connection,
|
connection,
|
||||||
profile_id,
|
profile_id,
|
||||||
@ -31,7 +31,7 @@ impl Database {
|
|||||||
pub fn records(&self, request: Option<&str>) -> Vec<Table> {
|
pub fn records(&self, request: Option<&str>) -> Vec<Table> {
|
||||||
let readable = self.connection.read().unwrap();
|
let readable = self.connection.read().unwrap();
|
||||||
let tx = readable.unchecked_transaction().unwrap();
|
let tx = readable.unchecked_transaction().unwrap();
|
||||||
select(&tx, self.profile_id, request).unwrap()
|
select(&tx, *self.profile_id, request).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setters
|
// Setters
|
||||||
@ -44,7 +44,7 @@ impl Database {
|
|||||||
let tx = writable.transaction().unwrap();
|
let tx = writable.transaction().unwrap();
|
||||||
|
|
||||||
// Create new record
|
// Create new record
|
||||||
insert(&tx, self.profile_id, time, request).unwrap();
|
insert(&tx, *self.profile_id, time, request).unwrap();
|
||||||
|
|
||||||
// Hold insert ID for result
|
// Hold insert ID for result
|
||||||
let id = last_insert_id(&tx);
|
let id = last_insert_id(&tx);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user