rustyx 0.2.0

A Rust web framework inspired by ExpressJS with ORM support for MongoDB, MySQL, SQLite, and PostgreSQL
Documentation
//! SQL Database Module (MySQL, PostgreSQL, SQLite)

use crate::error::Result;
use async_trait::async_trait;
use serde::{de::DeserializeOwned, Serialize};

/// SQL Repository trait for CRUD operations
#[async_trait]
pub trait SqlRepository<T>: Send + Sync
where
    T: Send + Sync + Serialize + DeserializeOwned,
{
    /// Find a record by ID
    async fn find_by_id(&self, id: &str) -> Result<Option<T>>;

    /// Find all records
    async fn find_all(&self) -> Result<Vec<T>>;

    /// Find records matching criteria
    async fn find_where(&self, field: &str, value: &str) -> Result<Vec<T>>;

    /// Create a new record
    async fn create(&self, entity: &T) -> Result<T>;

    /// Update a record
    async fn update(&self, id: &str, entity: &T) -> Result<T>;

    /// Delete a record
    async fn delete(&self, id: &str) -> Result<bool>;

    /// Count all records
    async fn count(&self) -> Result<u64>;
}

/// SQL query executor
pub struct SqlExecutor;

impl SqlExecutor {
    /// Execute a raw SQL query
    pub async fn query<T: DeserializeOwned>(_sql: &str) -> Result<Vec<T>> {
        // Implementation would use sqlx
        Ok(Vec::new())
    }

    /// Execute a raw SQL command
    pub async fn execute(_sql: &str) -> Result<u64> {
        // Implementation would use sqlx
        Ok(0)
    }
}

/// Migration helper
pub struct Migration {
    pub version: String,
    pub name: String,
    pub up: String,
    pub down: String,
}

impl Migration {
    pub fn new(version: &str, name: &str, up: &str, down: &str) -> Self {
        Self {
            version: version.to_string(),
            name: name.to_string(),
            up: up.to_string(),
            down: down.to_string(),
        }
    }
}