reasonkit-web 0.1.7

High-performance MCP server for browser automation, web capture, and content extraction. Rust-powered CDP client for AI agents.
Documentation
//! # Portal Database Module
//!
//! PostgreSQL database layer for user portal.
//!
//! ## Features
//!
//! - Connection pool management
//! - User/Session/ApiKey models
//! - CRUD operations with sqlx
//!
//! ## Usage
//!
//! Enable with `--features portal` flag.

#[cfg(feature = "portal")]
pub mod models;

#[cfg(feature = "portal")]
pub mod pool;

#[cfg(feature = "portal")]
pub mod queries;

#[cfg(feature = "portal")]
pub use pool::DatabasePool;

use thiserror::Error;

/// Database errors
#[derive(Debug, Error)]
pub enum DbError {
    #[error("Record not found")]
    NotFound,

    #[error("Duplicate entry: {0}")]
    DuplicateEntry(String),

    #[error("Invalid data: {0}")]
    ValidationError(String),

    #[error("Connection error: {0}")]
    ConnectionError(String),

    #[error("Query error: {0}")]
    QueryError(String),

    #[error("Migration error: {0}")]
    MigrationError(String),
}

#[cfg(feature = "portal")]
impl From<sqlx::Error> for DbError {
    fn from(err: sqlx::Error) -> Self {
        match err {
            sqlx::Error::RowNotFound => DbError::NotFound,
            sqlx::Error::Database(db_err) => {
                if db_err.is_unique_violation() {
                    DbError::DuplicateEntry(db_err.message().to_string())
                } else {
                    DbError::QueryError(db_err.message().to_string())
                }
            }
            _ => DbError::QueryError(err.to_string()),
        }
    }
}