From 88bcd5f0fbca35ab2197252168493705f6b44edb Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Wed, 3 Apr 2019 13:29:08 -0400 Subject: [PATCH] Add public method signatures, subject to change --- src/query_builder.rs | 202 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 196 insertions(+), 6 deletions(-) diff --git a/src/query_builder.rs b/src/query_builder.rs index b0caefc..aa58f5a 100644 --- a/src/query_builder.rs +++ b/src/query_builder.rs @@ -6,6 +6,27 @@ use std::collections::HashMap; use crate::drivers::DatabaseDriver; +#[derive(Debug)] +pub enum LikeWildcard { + Before, + After, + Both, +} + +#[derive(Debug)] +pub enum JoinType { + Inner, + Outer, + Left, + Right, +} + +#[derive(Debug)] +pub enum OrderDirection { + Asc, + Desc, +} + #[derive(Debug)] enum QueryClauseType { AndGroupStart, @@ -80,11 +101,97 @@ impl QueryBuilder { } } + // -------------------------------------------------------------------------- + // ! Select Queries + // -------------------------------------------------------------------------- + /// Set the fields to select from the database pub fn select(mut self, fields: &str) -> Self { unimplemented!(); } + // Adds the 'distinct' keyword to a query + pub fn distinct(mut self) -> Self { + unimplemented!(); + } + + /// Specify the database table to select from + pub fn from(mut self, table_name: &str) -> Self { + // @TODO properly escape the table name + self.state.from_string = table_name.to_string(); + + self + } + + // -------------------------------------------------------------------------- + // ! 'Like' methods + // -------------------------------------------------------------------------- + + // Creates a like clause in the sql statement + pub fn like(mut self, field: &str, value: Box, position: LikeWildcard) -> Self { + unimplemented!(); + } + + // Generates an OR Like clause + pub fn or_like(mut self, field: &str, value: Box, position: LikeWildcard) -> Self { + unimplemented!(); + } + + // Generates a NOI Like clause + pub fn not_like(mut self, field: &str, value: Box, position: LikeWildcard) -> Self { + unimplemented!(); + } + + // Generates an OR NOT Like clause + pub fn or_not_like(mut self, field: &str, value: Box, position: LikeWildcard) -> Self { + unimplemented!(); + } + + // -------------------------------------------------------------------------- + // ! Having methods + // -------------------------------------------------------------------------- + + pub fn having(mut self, key:&str, value: Box) -> Self { + unimplemented!(); + } + + pub fn or_having(mut self, key:&str, value: Box) -> Self { + unimplemented!(); + } + + // -------------------------------------------------------------------------- + // ! 'Where' methods + // -------------------------------------------------------------------------- + + /// Specify a condition for the where clause of the query + pub fn r#where(mut self, key: &str, value: Box) -> Self { + unimplemented!(); + } + + pub fn or_where(mut self, key: &str, value: Box) -> Self { + unimplemented!(); + } + + pub fn where_in(mut self, key: &str, value: Vec>) -> Self { + unimplemented!(); + } + + pub fn or_where_in(mut self, key: &str, value: Vec>) -> Self { + unimplemented!(); + } + + pub fn where_not_in(mut self, key: &str, value: Vec>) -> Self { + unimplemented!(); + } + + pub fn or_where_not_in(mut self, key: &str, value: Vec>) -> Self { + unimplemented!(); + } + + // -------------------------------------------------------------------------- + // ! Other Query Modifier methods + // -------------------------------------------------------------------------- + /// Set a key and value for an insert or update query pub fn set(mut self, key: &str, value: Box) -> Self { // @TODO figure a way to make this easier to use @@ -103,18 +210,101 @@ impl QueryBuilder { self } - /// Specify the database table to select from - pub fn from(mut self, table_name: &str) -> Self { - // @TODO properly escape the table name - self.state.from_string = table_name.to_string(); - - self + // Add a table join to the query + pub fn join(mut self, table: &str, condition: &str, join_type: JoinType) -> Self { + unimplemented!(); } + pub fn group_by(mut self, field: &str) -> Self { + unimplemented!(); + } + + pub fn order_by(mut self, field: &str, direction: OrderDirection) -> Self { + unimplemented!(); + } + + pub fn limit(mut self, limit: u32, offset: u32) -> Self { + unimplemented!(); + } + + // -------------------------------------------------------------------------- + // ! Query Grouping Methods + // -------------------------------------------------------------------------- + + pub fn group_start(mut self) -> Self { + unimplemented!(); + } + + pub fn not_group_start(mut self) -> Self { + unimplemented!(); + } + + pub fn or_group_start(mut self) -> Self { + unimplemented!(); + } + + pub fn or_not_group_start(mut self) -> Self { + unimplemented!(); + } + + pub fn group_end(mut self) -> Self { + unimplemented!(); + } + + // -------------------------------------------------------------------------- + // ! Query execution methods + // -------------------------------------------------------------------------- + /// Execute the built query pub fn get(self) -> Box { unimplemented!(); } + + pub fn count_all(self, table: &str) -> u32 { + unimplemented!(); + } + + pub fn insert(mut self, table: &str) { + // @TODO determine query result type + unimplemented!(); + } + + pub fn update(mut self, table: &str) { + // @TODO determine query result type + unimplemented!(); + } + + pub fn delete(mut self, table: &str, where_clause: &str) { + unimplemented!(); + } + + // -------------------------------------------------------------------------- + // ! SQL Returning Methods + // -------------------------------------------------------------------------- + + pub fn get_compiled_select(self) -> String { + unimplemented!(); + } + + pub fn get_compiled_insert(self) -> String { + unimplemented!(); + } + + pub fn get_compiled_update(self) -> String { + unimplemented!(); + } + + pub fn get_compiled_delete(self) -> String { + unimplemented!(); + } + + // -------------------------------------------------------------------------- + // ! Miscellaneous Methods + // -------------------------------------------------------------------------- + + pub fn reset_query(mut self) -> Self { + unimplemented!(); + } } #[cfg(test)]