mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-01-15 17:20:08 +00:00
remove profile_id relationship as profile_identity_gemini_id already has it
This commit is contained in:
parent
d9a6c88c1c
commit
3348e30d80
@ -21,7 +21,7 @@ impl Gemini {
|
||||
/// Create new `Self`
|
||||
pub fn new(connection: Rc<RwLock<Connection>>, profile_id: Rc<i64>) -> Self {
|
||||
Self {
|
||||
auth: Rc::new(Auth::new(connection.clone(), profile_id.clone())),
|
||||
auth: Rc::new(Auth::new(connection.clone())),
|
||||
database: Rc::new(Database::new(connection, profile_id)),
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ use database::Database;
|
||||
use sqlite::{Connection, Transaction};
|
||||
use std::{rc::Rc, sync::RwLock};
|
||||
|
||||
/// API for `gemini_id` + `request` auth pairs operations
|
||||
/// API for `profile_identity_gemini_id` + `url` auth pairs operations
|
||||
pub struct Auth {
|
||||
pub database: Rc<Database>,
|
||||
}
|
||||
@ -14,9 +14,9 @@ impl Auth {
|
||||
// Constructors
|
||||
|
||||
/// Create new `Self`
|
||||
pub fn new(connection: Rc<RwLock<Connection>>, profile_id: Rc<i64>) -> Self {
|
||||
pub fn new(connection: Rc<RwLock<Connection>>) -> Self {
|
||||
Self {
|
||||
database: Rc::new(Database::new(connection, profile_id)),
|
||||
database: Rc::new(Database::new(connection)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,25 +4,20 @@ use sqlite::{Connection, Error, Transaction};
|
||||
|
||||
pub struct Table {
|
||||
//pub id: i64,
|
||||
//pub profile_id: i64,
|
||||
pub profile_identity_gemini_id: i64,
|
||||
}
|
||||
|
||||
/// Storage for `profile_identity_gemini_id` + `url` auth pairs
|
||||
pub struct Database {
|
||||
connection: Rc<RwLock<Connection>>,
|
||||
profile_id: Rc<i64>, // multi-profile relationship
|
||||
}
|
||||
|
||||
impl Database {
|
||||
// Constructors
|
||||
|
||||
/// Create new `Self`
|
||||
pub fn new(connection: Rc<RwLock<Connection>>, profile_id: Rc<i64>) -> Self {
|
||||
Self {
|
||||
connection,
|
||||
profile_id,
|
||||
}
|
||||
pub fn new(connection: Rc<RwLock<Connection>>) -> Self {
|
||||
Self { connection }
|
||||
}
|
||||
|
||||
// Getters
|
||||
@ -31,7 +26,7 @@ impl Database {
|
||||
pub fn records(&self, url: Option<&str>) -> Result<Vec<Table>, Error> {
|
||||
let readable = self.connection.read().unwrap(); // @TODO
|
||||
let tx = readable.unchecked_transaction()?;
|
||||
select(&tx, *self.profile_id, url)
|
||||
select(&tx, url)
|
||||
}
|
||||
}
|
||||
|
||||
@ -42,16 +37,13 @@ pub fn init(tx: &Transaction) -> Result<usize, Error> {
|
||||
"CREATE TABLE IF NOT EXISTS `profile_identity_gemini_auth`
|
||||
(
|
||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
`profile_id` INTEGER NOT NULL,
|
||||
`profile_identity_gemini_id` INTEGER NOT NULL,
|
||||
`is_active` INTEGER NOT NULL,
|
||||
`url` VARCHAR(1024) NOT NULL,
|
||||
|
||||
FOREIGN KEY (`profile_id`) REFERENCES `profile`(`id`),
|
||||
FOREIGN KEY (`profile_identity_gemini_id`) REFERENCES `profile_identity_gemini`(`id`),
|
||||
|
||||
UNIQUE (
|
||||
`profile_id`,
|
||||
`profile_identity_gemini_id`,
|
||||
`is_active`,
|
||||
`url`
|
||||
@ -61,21 +53,19 @@ pub fn init(tx: &Transaction) -> Result<usize, Error> {
|
||||
)
|
||||
}
|
||||
|
||||
pub fn select(tx: &Transaction, profile_id: i64, url: Option<&str>) -> Result<Vec<Table>, Error> {
|
||||
pub fn select(tx: &Transaction, url: Option<&str>) -> Result<Vec<Table>, Error> {
|
||||
let mut stmt = tx.prepare(
|
||||
"SELECT `id`,
|
||||
`profile_id`,
|
||||
`profile_identity_gemini_id`
|
||||
|
||||
FROM `profile_identity_gemini_auth`
|
||||
WHERE `profile_id` = ? AND `url` LIKE ?",
|
||||
WHERE `url` LIKE ?",
|
||||
)?;
|
||||
|
||||
let result = stmt.query_map((profile_id, url.unwrap_or("%")), |row| {
|
||||
let result = stmt.query_map([url.unwrap_or("%")], |row| {
|
||||
Ok(Table {
|
||||
//id: row.get(0)?,
|
||||
//profile_id: row.get(1)?,
|
||||
profile_identity_gemini_id: row.get(2)?,
|
||||
profile_identity_gemini_id: row.get(1)?,
|
||||
})
|
||||
})?;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user