Skip to content

Commit

Permalink
refactor: reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
edytapawlak committed Mar 27, 2024
1 parent 9cce0f4 commit d9d61f6
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 21 deletions.
2 changes: 1 addition & 1 deletion oca/src/facade/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ use oca_bundle::state::oca::{capture_base::CaptureBase, DynOverlay, OCABundle};
use said::SelfAddressingIdentifier;

use serde::Serialize;
use std::borrow::Borrow;
#[cfg(feature = "local-references")]
use std::collections::HashMap;
use std::str::FromStr;
use std::borrow::Borrow;

#[derive(Debug, Serialize)]
#[serde(untagged)]
Expand Down
14 changes: 9 additions & 5 deletions oca/src/facade/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,23 @@ mod fetch;

#[derive(Clone)]
pub struct Connection {
pub connection: Arc<Mutex<rusqlite::Connection>>
pub connection: Arc<Mutex<rusqlite::Connection>>,
}

impl Connection {
pub fn new(path: &str) -> Self {
let conn = rusqlite::Connection::open(path).unwrap();
Self {connection: Arc::new(Mutex::new(conn))}
Self {
connection: Arc::new(Mutex::new(conn)),
}
}

pub fn execute<P>(&self, sql: &str, params: P) where P: Params {
pub fn execute<P>(&self, sql: &str, params: P) -> rusqlite::Result<usize>
where
P: Params,
{
let connection = self.connection.lock().unwrap();
connection.execute(sql, params).unwrap();

connection.execute(sql, params)
}
}

Expand Down
8 changes: 3 additions & 5 deletions oca/src/repositories/capture_base_cache_repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,9 @@ impl CaptureBaseCacheRepo {
said TEXT PRIMARY KEY,
capture_base TEXT
)"#;
connection.execute(create_table_query, ());
let _ = connection.execute(create_table_query, ());

Self {
connection,
}
Self { connection }
}

pub fn insert(&self, model: CaptureBaseCacheRecord) {
Expand Down Expand Up @@ -68,7 +66,7 @@ impl CaptureBaseCacheRepo {
) AS results
ON true
GROUP BY said";

let connection = self.connection.connection.lock().unwrap();
let mut statement = connection.prepare(query).unwrap();

Expand Down
8 changes: 3 additions & 5 deletions oca/src/repositories/oca_bundle_cache_repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,9 @@ impl OCABundleCacheRepo {
said TEXT PRIMARY KEY,
oca_bundle TEXT
)"#;
connection.execute(create_table_query, ());
connection.execute(create_table_query, ()).unwrap();

Self {
connection,
}
Self { connection }
}

pub fn insert(&self, model: OCABundleCacheRecord) {
Expand Down Expand Up @@ -68,7 +66,7 @@ impl OCABundleCacheRepo {
) AS results
ON true
GROUP BY said";

let connection = self.connection.connection.lock().unwrap();
let mut statement = connection.prepare(query).unwrap();
let models = statement
Expand Down
7 changes: 2 additions & 5 deletions oca/src/repositories/oca_bundle_fts_repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,9 @@ impl OCABundleFTSRepo {
oca_bundle_said UNINDEXED,
tokenize="trigram"
)"#;
connection.execute(create_table_query, ());
connection.execute(create_table_query, ()).unwrap();

Self {
connection,
}
Self { connection }
}

pub fn insert(&self, model: OCABundleFTSRecord) {
Expand Down Expand Up @@ -166,7 +164,6 @@ meta_overlay:{}
}
}


let connection = self.connection.connection.lock().unwrap();
let mut statement = connection.prepare(sql_query).unwrap();

Expand Down

0 comments on commit d9d61f6

Please sign in to comment.