mouse_db 0.1.0

Extracted database types and schemaless table implementation for mouse-lang
Documentation
/*
mouse-db crate root

This crate contains the extracted database types and modules previously
located under `crate::db` in the main workspace.

Modules:
- `query_engine` (query evaluation & inference)
- `row_schemaless` (schemaless table implementation)

The top-level types `DBValue`, `DBValueType`, and `FilterEntity` are defined
here and used by the modules.
*/

#![allow(clippy::large_enum_variant)]

use bincode::{Decode, Encode};
use serde::{Deserialize, Serialize};

pub mod query_engine;
pub mod row_schemaless;

/// Value type stored in the database
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Encode, Decode)]
pub enum DBValue {
    String(String),
    Number(f64),
    Timestamp(i64),
    Null,
}

impl DBValue {
    /// Return the type of this value as a `DBValueType`
    pub fn vtype(&self) -> DBValueType {
        match self {
            DBValue::String(_) => DBValueType::String,
            DBValue::Number(_) => DBValueType::Number,
            DBValue::Timestamp(_) => DBValueType::Timestamp,
            DBValue::Null => DBValueType::Null,
        }
    }
}

/// The "type" of a `DBValue`
#[derive(Debug, Clone, Serialize, Eq, PartialEq, Hash, Deserialize, Encode, Decode)]
pub enum DBValueType {
    String,
    Number,
    Timestamp,
    Null,
}

/// Filter expression used to query rows
#[derive(Debug, Clone, Serialize, Deserialize, Encode, Decode)]
pub enum FilterEntity {
    Equals(Box<FilterEntity>, Box<FilterEntity>),
    GreaterThan(Box<FilterEntity>, Box<FilterEntity>),
    LessThan(Box<FilterEntity>, Box<FilterEntity>),
    FuzzyMatch(Box<FilterEntity>, Box<FilterEntity>, u8), // threshold

    Not(Box<FilterEntity>),
    And(Box<FilterEntity>, Box<FilterEntity>),
    Or(Box<FilterEntity>, Box<FilterEntity>),
    Xor(Box<FilterEntity>, Box<FilterEntity>),

    Value(DBValue),
    Column(String),
    Null,
}

// Re-export commonly used items from the crate root for convenience
pub use query_engine::*;
pub use row_schemaless::*;