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