Skip to content

Commit

Permalink
update query.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
giuseppe-g-gelardi committed Dec 23, 2024
1 parent e807a27 commit ee889b7
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 26 deletions.
3 changes: 3 additions & 0 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,7 @@ pub enum DatabaseError {

#[error("")] // could expand to specify serialization/deserialization error
JSONError(#[from] serde_json::Error),

#[error("")] // could expand to specify serialization/deserialization Error
InvalidOperation(String),
}
12 changes: 6 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
pub mod query;
pub mod util;
pub mod view;
pub use util::setup_temp_db;

pub mod errors;
pub use errors::DatabaseError;

pub mod database_components;
pub use database_components::{Column, Columns, Row, Table};

pub mod query_operations;
pub use query_operations::{Operation, Query};

pub mod database_operations;
pub use database_operations::Database;

pub use errors::DatabaseError;

pub use query::{Operation, Query};
pub use util::setup_temp_db;
pub mod view;
pub use view::View;
24 changes: 24 additions & 0 deletions src/query_operations/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
pub mod query;

pub use query as query_operations;

use serde::{Deserialize, Serialize};
use serde_json::Value;
use std::path::PathBuf;

#[derive(Debug, PartialEq, Serialize, Deserialize, Clone, Copy)]
pub enum Operation {
Create,
Read,
Update,
Delete,
}

#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
pub struct Query {
pub db_file_name: PathBuf,
pub table_name: Option<String>,
pub operation: Operation,
pub update_data: Option<Value>,
pub row_data: Option<Value>,
}
23 changes: 3 additions & 20 deletions src/query.rs → src/query_operations/query.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,10 @@
use std::collections::HashMap;
use std::path::PathBuf;

use serde::de::DeserializeOwned;
use serde::{Deserialize, Serialize};
use serde::Serialize;
use serde_json::Value;

use crate::{Database, DatabaseError, Row, Table};

#[derive(Debug, PartialEq, Serialize, Deserialize, Clone, Copy)]
pub enum Operation {
Create,
Read,
Update,
Delete,
}

#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
pub struct Query {
pub db_file_name: PathBuf,
pub table_name: Option<String>,
pub operation: Operation,
pub update_data: Option<Value>,
pub row_data: Option<Value>,
}
use crate::{Database, DatabaseError, Operation, Query, Row, Table};

impl Query {
pub fn from(mut self, table_name: &str) -> Self {
Expand Down Expand Up @@ -271,6 +253,7 @@ impl Query {
#[cfg(test)]
mod tests {
use super::*;
use serde::Deserialize;
use serde_json::json;

use crate::setup_temp_db;
Expand Down

0 comments on commit ee889b7

Please sign in to comment.