qlext 0.1.0

extension traits for Rust General-Purpose data queries
Documentation
//! extension traits for Rust `General-Purpose` data queries

#![cfg_attr(docsrs, feature(doc_cfg))]

/// A query builder that supports integrated queries across data sources.
///
/// Data source should implement this trait.
pub trait Query {
    type FromQuery: FromQuery;

    /// Create a query from `source`
    fn from(from: Self) -> Self::FromQuery;
}

#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Hash)]
pub enum Join {
    Inner,
    Left,
    Right,
    Outer,
    Cross,
}

/// An extension trait that support `join` operation.
pub trait JoinQuery: Query {
    /// on clause.
    type On;

    /// Create a `join` query.
    fn join(from: Self, join: Join, to: Self, on: Self::On) -> Self::FromQuery;
}

/// A query builder that support `where` and `select` clauses.
pub trait FromQuery {
    type WhereClause;
    type WhereQuery;

    type SelectClause;
    type SelectQuery;

    /// Create a `where` query.
    fn where_(self, cond: Self::WhereClause) -> Self::WhereQuery;

    /// Create a `select` query.
    fn select(&self, clause: Self::SelectClause) -> Self::SelectQuery;
}

/// A query builder that support `select` clause.
pub trait WhereQuery {
    type SelectClause;
    type SelectQuery;

    /// Create a `select` query.
    fn select(&self, clause: Self::SelectClause) -> Self::SelectQuery;
}

/// An final query builder that support `exec` clause.
pub trait SelectQuery {
    /// Result interator.
    type Result;

    /// Execute query.
    fn exec(self) -> Self::Result;
}