Implement from and distinct methods
This commit is contained in:
parent
6281b671ec
commit
35c0683891
@ -26,9 +26,14 @@ version="15.1.0"
|
||||
optional=true
|
||||
package="mysql"
|
||||
|
||||
[dependencies.ms]
|
||||
version="0.3.2"
|
||||
optional=true
|
||||
package="tiberius"
|
||||
|
||||
[features]
|
||||
default=['postgres']
|
||||
postgres=['pg']
|
||||
sqlite=['slite']
|
||||
mysql=['my']
|
||||
mssql=[]
|
||||
mssql=['ms']
|
||||
|
@ -49,11 +49,11 @@ pub trait DatabaseDriver: fmt::Debug {
|
||||
}
|
||||
|
||||
/// Vector version of `quote_identifier`
|
||||
fn quote_identifiers(&self, identifiers: Vec<&str>) -> Vec<String> {
|
||||
fn quote_identifiers(&self, identifiers: Vec<String>) -> Vec<String> {
|
||||
let mut output: Vec<String> = vec![];
|
||||
|
||||
for identifier in identifiers {
|
||||
output.push(self.quote_identifier(identifier).to_string());
|
||||
output.push(self.quote_identifier(&identifier).to_string());
|
||||
}
|
||||
|
||||
output
|
||||
@ -120,7 +120,11 @@ mod tests {
|
||||
let driver = DefaultDriver::new();
|
||||
|
||||
assert_eq!(
|
||||
driver.quote_identifiers(vec!["\tfoo. bar", "baz", "fizz.\n\tbuzz.baz",]),
|
||||
driver.quote_identifiers(vec![
|
||||
"\tfoo. bar".to_string(),
|
||||
"baz".to_string(),
|
||||
"fizz.\n\tbuzz.baz".to_string(),
|
||||
]),
|
||||
vec![
|
||||
r#""foo"."bar""#.to_string(),
|
||||
r#""baz""#.to_string(),
|
||||
|
@ -45,7 +45,11 @@ mod tests {
|
||||
let driver = MSSQL::new();
|
||||
|
||||
assert_eq!(
|
||||
driver.quote_identifiers(vec!["\tfoo. bar", "baz", "fizz.\n\tbuzz.baz",]),
|
||||
driver.quote_identifiers(vec![
|
||||
"\tfoo. bar".to_string(),
|
||||
"baz".to_string(),
|
||||
"fizz.\n\tbuzz.baz".to_string(),
|
||||
]),
|
||||
vec![
|
||||
"[foo].[bar]".to_string(),
|
||||
"[baz]".to_string(),
|
||||
|
@ -45,7 +45,11 @@ mod tests {
|
||||
let driver = MySQL::new();
|
||||
|
||||
assert_eq!(
|
||||
driver.quote_identifiers(vec!["\tfoo. bar", "baz", "fizz.\n\tbuzz.baz",]),
|
||||
driver.quote_identifiers(vec![
|
||||
"\tfoo. bar".to_string(),
|
||||
"baz".to_string(),
|
||||
"fizz.\n\tbuzz.baz".to_string(),
|
||||
]),
|
||||
vec![
|
||||
"`foo`.`bar`".to_string(),
|
||||
"`baz`".to_string(),
|
||||
|
@ -232,13 +232,20 @@ impl QueryBuilder {
|
||||
|
||||
/// Adds the `distinct` keyword to a query
|
||||
pub fn distinct(&mut self) -> &mut Self {
|
||||
unimplemented!();
|
||||
self.state.select_string = String::from(" DISTINCT") + &self.state.select_string;
|
||||
|
||||
self
|
||||
}
|
||||
|
||||
/// Specify the database table to select from
|
||||
pub fn from(&mut self, table_name: &str) -> &mut Self {
|
||||
// @TODO properly escape the table name
|
||||
self.state.from_string = table_name.to_string();
|
||||
let ident_vec = String::from(table_name)
|
||||
.split(" ")
|
||||
.into_iter()
|
||||
.map(|s| self.driver.quote_identifier(s))
|
||||
.collect::<Vec<String>>();
|
||||
|
||||
self.state.from_string = ident_vec.join(" ");
|
||||
|
||||
self
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user