Skip to content

Commit

Permalink
refactor: removed redundant KeyValue struct
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikBjare committed Oct 19, 2023
1 parent 2fb9a80 commit 1903d7b
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 44 deletions.
8 changes: 2 additions & 6 deletions aw-datastore/src/datastore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use serde_json::value::Value;
use aw_models::Bucket;
use aw_models::BucketMetadata;
use aw_models::Event;
use aw_models::KeyValue;

use rusqlite::params;
use rusqlite::types::ToSql;
Expand Down Expand Up @@ -897,7 +896,7 @@ impl DatastoreInstance {
Ok(())
}

pub fn get_key_value(&self, conn: &Connection, key: &str) -> Result<KeyValue, DatastoreError> {
pub fn get_key_value(&self, conn: &Connection, key: &str) -> Result<String, DatastoreError> {
let mut stmt = match conn.prepare(
"
SELECT * FROM key_value WHERE KEY = ?1",
Expand All @@ -911,10 +910,7 @@ impl DatastoreInstance {
};

match stmt.query_row([key], |row| {
Ok(KeyValue {
key: row.get(0)?,
value: row.get(1)?,
})
Ok(row.get(1)?)
}) {
Ok(result) => Ok(result),
Err(err) => match err {
Expand Down
5 changes: 2 additions & 3 deletions aw-datastore/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use rusqlite::TransactionBehavior;

use aw_models::Bucket;
use aw_models::Event;
use aw_models::KeyValue;

use crate::DatastoreError;
use crate::DatastoreInstance;
Expand Down Expand Up @@ -51,7 +50,7 @@ pub enum Response {
Event(Event),
EventList(Vec<Event>),
Count(i64),
KeyValue(KeyValue),
KeyValue(String),
KeyValues(HashMap<String, String>)
}

Expand Down Expand Up @@ -488,7 +487,7 @@ impl Datastore {
}
}

pub fn get_key_value(&self, key: &str) -> Result<KeyValue, DatastoreError> {
pub fn get_key_value(&self, key: &str) -> Result<String, DatastoreError> {
let cmd = Command::GetKeyValue(key.to_string());
let receiver = self.requester.request(cmd).unwrap();

Expand Down
28 changes: 0 additions & 28 deletions aw-models/src/key_value.rs

This file was deleted.

3 changes: 0 additions & 3 deletions aw-models/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ mod bucket;
mod duration;
mod event;
mod info;
mod key_value;
mod query;
mod timeinterval;
mod tryvec;
Expand All @@ -30,8 +29,6 @@ pub use self::bucket::BucketMetadata;
pub use self::bucket::BucketsExport;
pub use self::event::Event;
pub use self::info::Info;
pub use self::key_value::Key;
pub use self::key_value::KeyValue;
pub use self::query::Query;
pub use self::timeinterval::TimeInterval;
pub use self::tryvec::TryVec;
3 changes: 1 addition & 2 deletions aw-server/src/endpoints/settings.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::endpoints::ServerState;
use aw_query::query;
use rocket::http::Status;
use rocket::serde::json::Json;
use rocket::State;
Expand Down Expand Up @@ -54,7 +53,7 @@ pub fn setting_get(
let datastore = endpoints_get_lock!(state.datastore);

match datastore.get_key_value(&setting_key) {
Ok(kv) => Ok(Json(kv.value)),
Ok(value) => Ok(Json(serde_json::from_str(&value).unwrap())),
Err(err) => Err(err.into()),
}
}
Expand Down
2 changes: 0 additions & 2 deletions aw-server/tests/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@ mod api_tests {
use std::path::PathBuf;
use std::sync::Mutex;

use chrono::{DateTime, Utc};
use rocket::http::{ContentType, Header, Status};
use serde_json::{json, Value};

use aw_server::config;
use aw_server::endpoints;

use aw_models::KeyValue;
use aw_models::{Bucket, BucketsExport};
use rocket::local::blocking::Client;

Expand Down

0 comments on commit 1903d7b

Please sign in to comment.