From 8de03f883f1374afd589a56b0fe3b8cb3249aaa1 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Thu, 11 Apr 2019 17:27:05 -0400 Subject: [PATCH] More docs --- src/query_builder.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/query_builder.rs b/src/query_builder.rs index c2b9cd6..a910491 100644 --- a/src/query_builder.rs +++ b/src/query_builder.rs @@ -52,6 +52,13 @@ impl QueryBuilder { // -------------------------------------------------------------------------- /// Set the fields to select from the database as a string + /// + /// ```ignore + /// let mut qb = QueryBuilder::new(Driver::new()); + /// + /// // You can also alias field names + /// qb.select("foo as bar") + /// ``` pub fn select(&mut self, fields: &str) -> &mut Self { lazy_static! { static ref RE: Regex = Regex::new(r"(?i) as ").unwrap(); @@ -77,6 +84,13 @@ impl QueryBuilder { } /// Set the fields to select from the database as a Vector + /// + /// ``` + /// # let mut qb = stringqb::QueryBuilder::default(); + /// // You can also alias via a vector of fields + /// qb.select_vec(vec!["foo as bar", "baz"]); + /// # assert_eq!(qb.state.get_select_string(), r#""foo" as "bar","baz""#); + /// ``` pub fn select_vec(&mut self, fields: Vec<&str>) -> &mut Self { let fields = fields.join(","); self.select(&fields) @@ -90,6 +104,13 @@ impl QueryBuilder { } /// Specify the database table to select from + /// + /// ```ignore + /// let mut qb = QueryBuilder::new(Driver::new()); + /// + /// // Specifiy an alias for the table + /// qb.from("products p"); + /// ``` pub fn from(&mut self, table_name: &str) -> &mut Self { let from_str = split_map_join(table_name, " ", |s| self.driver.quote_identifier(s));