More docs

This commit is contained in:
Timothy Warren 2019-04-11 17:27:05 -04:00
parent 0b93246cc5
commit 8de03f883f

View File

@ -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));