mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-24 10:21:15 +01:00
Reformat project
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
use crate::db_context::DbContext;
|
||||
use crate::error::Result;
|
||||
use crate::models::{
|
||||
GrpcRequest, HttpRequest, WebsocketRequest,
|
||||
};
|
||||
use crate::models::{GrpcRequest, HttpRequest, WebsocketRequest};
|
||||
|
||||
pub enum AnyRequest {
|
||||
HttpRequest(HttpRequest),
|
||||
|
||||
@@ -143,11 +143,7 @@ impl<'a> DbContext<'a> {
|
||||
}
|
||||
|
||||
self.upsert(
|
||||
&Environment {
|
||||
name,
|
||||
variables: cleaned_variables,
|
||||
..environment.clone()
|
||||
},
|
||||
&Environment { name, variables: cleaned_variables, ..environment.clone() },
|
||||
source,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
use crate::connection_or_tx::ConnectionOrTx;
|
||||
use crate::db_context::DbContext;
|
||||
use crate::error::Result;
|
||||
use crate::models::{Environment, EnvironmentIden, Folder, FolderIden, GrpcRequest, GrpcRequestIden, HttpRequest, HttpRequestHeader, HttpRequestIden, WebsocketRequest, WebsocketRequestIden};
|
||||
use crate::models::{
|
||||
Environment, EnvironmentIden, Folder, FolderIden, GrpcRequest, GrpcRequestIden, HttpRequest,
|
||||
HttpRequestHeader, HttpRequestIden, WebsocketRequest, WebsocketRequestIden,
|
||||
};
|
||||
use crate::util::UpdateSource;
|
||||
use serde_json::Value;
|
||||
use std::collections::BTreeMap;
|
||||
@@ -69,57 +72,35 @@ impl<'a> DbContext<'a> {
|
||||
|
||||
for m in self.find_many::<HttpRequest>(HttpRequestIden::FolderId, fid, None)? {
|
||||
self.upsert_http_request(
|
||||
&HttpRequest {
|
||||
id: "".into(),
|
||||
folder_id: Some(new_folder.id.clone()),
|
||||
..m
|
||||
},
|
||||
&HttpRequest { id: "".into(), folder_id: Some(new_folder.id.clone()), ..m },
|
||||
source,
|
||||
)?;
|
||||
}
|
||||
|
||||
for m in self.find_many::<WebsocketRequest>(WebsocketRequestIden::FolderId, fid, None)? {
|
||||
self.upsert_websocket_request(
|
||||
&WebsocketRequest {
|
||||
id: "".into(),
|
||||
folder_id: Some(new_folder.id.clone()),
|
||||
..m
|
||||
},
|
||||
&WebsocketRequest { id: "".into(), folder_id: Some(new_folder.id.clone()), ..m },
|
||||
source,
|
||||
)?;
|
||||
}
|
||||
|
||||
for m in self.find_many::<GrpcRequest>(GrpcRequestIden::FolderId, fid, None)? {
|
||||
self.upsert_grpc_request(
|
||||
&GrpcRequest {
|
||||
id: "".into(),
|
||||
folder_id: Some(new_folder.id.clone()),
|
||||
..m
|
||||
},
|
||||
&GrpcRequest { id: "".into(), folder_id: Some(new_folder.id.clone()), ..m },
|
||||
source,
|
||||
)?;
|
||||
}
|
||||
|
||||
for m in self.find_many::<Environment>(EnvironmentIden::ParentId, fid, None)? {
|
||||
self.upsert_environment(
|
||||
&Environment {
|
||||
id: "".into(),
|
||||
parent_id: Some(new_folder.id.clone()),
|
||||
..m
|
||||
},
|
||||
&Environment { id: "".into(), parent_id: Some(new_folder.id.clone()), ..m },
|
||||
source,
|
||||
)?;
|
||||
}
|
||||
|
||||
for m in self.find_many::<Folder>(FolderIden::FolderId, fid, None)? {
|
||||
// Recurse down
|
||||
self.duplicate_folder(
|
||||
&Folder {
|
||||
folder_id: Some(new_folder.id.clone()),
|
||||
..m
|
||||
},
|
||||
source,
|
||||
)?;
|
||||
self.duplicate_folder(&Folder { folder_id: Some(new_folder.id.clone()), ..m }, source)?;
|
||||
}
|
||||
|
||||
Ok(new_folder)
|
||||
|
||||
@@ -31,13 +31,9 @@ impl<'a> DbContext<'a> {
|
||||
},
|
||||
source,
|
||||
),
|
||||
Some(introspection) => self.upsert(
|
||||
&GraphQlIntrospection {
|
||||
content,
|
||||
..introspection
|
||||
},
|
||||
source,
|
||||
),
|
||||
Some(introspection) => {
|
||||
self.upsert(&GraphQlIntrospection { content, ..introspection }, source)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
use crate::db_context::DbContext;
|
||||
use crate::error::Result;
|
||||
use crate::models::{HttpResponse, HttpResponseIden, HttpResponseState};
|
||||
use crate::queries::MAX_HISTORY_ITEMS;
|
||||
use crate::util::UpdateSource;
|
||||
use log::{debug, error};
|
||||
use sea_query::{Expr, Query, SqliteQueryBuilder};
|
||||
use sea_query_rusqlite::RusqliteBinder;
|
||||
use std::fs;
|
||||
use crate::db_context::DbContext;
|
||||
use crate::queries::MAX_HISTORY_ITEMS;
|
||||
|
||||
impl<'a> DbContext<'a> {
|
||||
pub fn get_http_response(&self, id: &str) -> Result<HttpResponse> {
|
||||
@@ -101,10 +101,6 @@ impl<'a> DbContext<'a> {
|
||||
response: &HttpResponse,
|
||||
source: &UpdateSource,
|
||||
) -> Result<HttpResponse> {
|
||||
if response.id.is_empty() {
|
||||
Ok(response.clone())
|
||||
} else {
|
||||
self.upsert(response, source)
|
||||
}
|
||||
if response.id.is_empty() { Ok(response.clone()) } else { self.upsert(response, source) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use chrono::NaiveDateTime;
|
||||
use crate::db_context::DbContext;
|
||||
use crate::error::Result;
|
||||
use crate::models::{KeyValue, KeyValueIden, UpsertModelInfo};
|
||||
use crate::util::UpdateSource;
|
||||
use chrono::NaiveDateTime;
|
||||
use log::error;
|
||||
use sea_query::{Asterisk, Cond, Expr, Query, SqliteQueryBuilder};
|
||||
use sea_query_rusqlite::RusqliteBinder;
|
||||
@@ -39,7 +39,12 @@ impl<'a> DbContext<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_key_value_dte(&self, namespace: &str, key: &str, default: NaiveDateTime) -> NaiveDateTime {
|
||||
pub fn get_key_value_dte(
|
||||
&self,
|
||||
namespace: &str,
|
||||
key: &str,
|
||||
default: NaiveDateTime,
|
||||
) -> NaiveDateTime {
|
||||
match self.get_key_value_raw(namespace, key) {
|
||||
None => default,
|
||||
Some(v) => {
|
||||
@@ -139,14 +144,8 @@ impl<'a> DbContext<'a> {
|
||||
true,
|
||||
),
|
||||
Some(kv) => (
|
||||
self.upsert_key_value(
|
||||
&KeyValue {
|
||||
value: value.to_string(),
|
||||
..kv
|
||||
},
|
||||
source,
|
||||
)
|
||||
.expect("Failed to update key value"),
|
||||
self.upsert_key_value(&KeyValue { value: value.to_string(), ..kv }, source)
|
||||
.expect("Failed to update key value"),
|
||||
false,
|
||||
),
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use crate::db_context::DbContext;
|
||||
use crate::error::Result;
|
||||
use crate::models::{SyncState, SyncStateIden, UpsertModelInfo};
|
||||
use crate::util::UpdateSource;
|
||||
use sea_query::{Asterisk, Cond, Expr, Query, SqliteQueryBuilder};
|
||||
use sea_query_rusqlite::RusqliteBinder;
|
||||
use std::path::Path;
|
||||
use crate::db_context::DbContext;
|
||||
|
||||
impl<'a> DbContext<'a> {
|
||||
pub fn get_sync_state(&self, id: &str) -> Result<SyncState> {
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
use crate::db_context::DbContext;
|
||||
use crate::error::Result;
|
||||
use crate::models::{
|
||||
WebsocketEvent,
|
||||
WebsocketEventIden,
|
||||
};
|
||||
use crate::models::{WebsocketEvent, WebsocketEventIden};
|
||||
use crate::util::UpdateSource;
|
||||
|
||||
impl<'a> DbContext<'a> {
|
||||
|
||||
@@ -56,7 +56,11 @@ impl<'a> DbContext<'a> {
|
||||
websocket_request: &WebsocketRequest,
|
||||
) -> Result<(Option<String>, BTreeMap<String, Value>, String)> {
|
||||
if let Some(at) = websocket_request.authentication_type.clone() {
|
||||
return Ok((Some(at), websocket_request.authentication.clone(), websocket_request.id.clone()));
|
||||
return Ok((
|
||||
Some(at),
|
||||
websocket_request.authentication.clone(),
|
||||
websocket_request.id.clone(),
|
||||
));
|
||||
}
|
||||
|
||||
if let Some(folder_id) = websocket_request.folder_id.clone() {
|
||||
|
||||
@@ -14,10 +14,7 @@ impl<'a> DbContext<'a> {
|
||||
self.find_many(WorkspaceMetaIden::WorkspaceId, workspace_id, None)?;
|
||||
|
||||
if workspace_metas.is_empty() {
|
||||
let wm = WorkspaceMeta {
|
||||
workspace_id: workspace_id.to_string(),
|
||||
..Default::default()
|
||||
};
|
||||
let wm = WorkspaceMeta { workspace_id: workspace_id.to_string(), ..Default::default() };
|
||||
workspace_metas.push(self.upsert_workspace_meta(&wm, &UpdateSource::Background)?)
|
||||
}
|
||||
|
||||
@@ -30,10 +27,8 @@ impl<'a> DbContext<'a> {
|
||||
return Ok(workspace_meta);
|
||||
}
|
||||
|
||||
let workspace_meta = WorkspaceMeta {
|
||||
workspace_id: workspace_id.to_string(),
|
||||
..Default::default()
|
||||
};
|
||||
let workspace_meta =
|
||||
WorkspaceMeta { workspace_id: workspace_id.to_string(), ..Default::default() };
|
||||
|
||||
info!("Creating WorkspaceMeta for {workspace_id}");
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ use crate::util::ModelPayload;
|
||||
use r2d2::Pool;
|
||||
use r2d2_sqlite::SqliteConnectionManager;
|
||||
use rusqlite::TransactionBehavior;
|
||||
use std::sync::{mpsc, Arc, Mutex};
|
||||
use std::sync::{Arc, Mutex, mpsc};
|
||||
use tauri::{Manager, Runtime, State};
|
||||
|
||||
pub trait QueryManagerExt<'a, R> {
|
||||
@@ -58,10 +58,7 @@ impl QueryManager {
|
||||
pool: Pool<SqliteConnectionManager>,
|
||||
events_tx: mpsc::Sender<ModelPayload>,
|
||||
) -> Self {
|
||||
QueryManager {
|
||||
pool: Arc::new(Mutex::new(pool)),
|
||||
events_tx,
|
||||
}
|
||||
QueryManager { pool: Arc::new(Mutex::new(pool)), events_tx }
|
||||
}
|
||||
|
||||
pub fn connect(&self) -> DbContext<'_> {
|
||||
@@ -71,10 +68,7 @@ impl QueryManager {
|
||||
.expect("Failed to gain lock on DB")
|
||||
.get()
|
||||
.expect("Failed to get a new DB connection from the pool");
|
||||
DbContext {
|
||||
events_tx: self.events_tx.clone(),
|
||||
conn: ConnectionOrTx::Connection(conn),
|
||||
}
|
||||
DbContext { events_tx: self.events_tx.clone(), conn: ConnectionOrTx::Connection(conn) }
|
||||
}
|
||||
|
||||
pub fn with_conn<F, T>(&self, func: F) -> T
|
||||
@@ -88,10 +82,8 @@ impl QueryManager {
|
||||
.get()
|
||||
.expect("Failed to get new DB connection from the pool");
|
||||
|
||||
let db_context = DbContext {
|
||||
events_tx: self.events_tx.clone(),
|
||||
conn: ConnectionOrTx::Connection(conn),
|
||||
};
|
||||
let db_context =
|
||||
DbContext { events_tx: self.events_tx.clone(), conn: ConnectionOrTx::Connection(conn) };
|
||||
|
||||
func(&db_context)
|
||||
}
|
||||
@@ -113,10 +105,8 @@ impl QueryManager {
|
||||
.transaction_with_behavior(TransactionBehavior::Immediate)
|
||||
.expect("Failed to start DB transaction");
|
||||
|
||||
let db_context = DbContext {
|
||||
events_tx: self.events_tx.clone(),
|
||||
conn: ConnectionOrTx::Transaction(&tx),
|
||||
};
|
||||
let db_context =
|
||||
DbContext { events_tx: self.events_tx.clone(), conn: ConnectionOrTx::Transaction(&tx) };
|
||||
|
||||
match func(&db_context) {
|
||||
Ok(val) => {
|
||||
|
||||
@@ -62,9 +62,7 @@ pub enum UpdateSource {
|
||||
|
||||
impl UpdateSource {
|
||||
pub fn from_window<R: Runtime>(window: &WebviewWindow<R>) -> Self {
|
||||
Self::Window {
|
||||
label: window.label().to_string(),
|
||||
}
|
||||
Self::Window { label: window.label().to_string() }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user