Reformat code

This commit is contained in:
Timothy Warren 2019-04-17 12:58:05 -04:00
parent b4a21d189f
commit 1e7644108b
3 changed files with 10 additions and 42 deletions

View File

@ -26,12 +26,7 @@ pub mod prelude {
//! This includes enum types, traits, //! This includes enum types, traits,
//! the Query Builder, and individual database drivers. //! the Query Builder, and individual database drivers.
pub use crate::drivers::DatabaseDriver; pub use crate::drivers::DatabaseDriver;
pub use crate::query_builder::{ pub use crate::query_builder::{JoinType, LikeWildcard, OrderDirection, QueryBuilder};
LikeWildcard,
JoinType,
OrderDirection,
QueryBuilder
};
#[cfg(feature = "postgres")] #[cfg(feature = "postgres")]
/// Postgres Driver /// Postgres Driver

View File

@ -226,22 +226,12 @@ impl QueryBuilder {
} }
/// Generates an OR Like clause /// Generates an OR Like clause
pub fn or_like( pub fn or_like(&mut self, field: &str, value: impl Any, position: LikeWildcard) -> &mut Self {
&mut self,
field: &str,
value: impl Any,
position: LikeWildcard,
) -> &mut Self {
self._like(field, value, position, "LIKE", "OR") self._like(field, value, position, "LIKE", "OR")
} }
/// Generates a NOI Like clause /// Generates a NOI Like clause
pub fn not_like( pub fn not_like(&mut self, field: &str, value: impl Any, position: LikeWildcard) -> &mut Self {
&mut self,
field: &str,
value: impl Any,
position: LikeWildcard,
) -> &mut Self {
self._like(field, value, position, "NOT LIKE", "AND") self._like(field, value, position, "NOT LIKE", "AND")
} }
@ -339,7 +329,9 @@ impl QueryBuilder {
pub fn set(&mut self, key: &str, value: impl Any) -> &mut Self { pub fn set(&mut self, key: &str, value: impl Any) -> &mut Self {
// @TODO figure a way to make this easier to use // @TODO figure a way to make this easier to use
let key = self.driver.quote_identifier(key); let key = self.driver.quote_identifier(key);
self.state.append_set_array_keys(&key).append_values(Box::new(value)); self.state
.append_set_array_keys(&key)
.append_values(Box::new(value));
self self
} }
@ -1013,14 +1005,8 @@ mod tests {
let mut qb = QueryBuilder::default(); let mut qb = QueryBuilder::default();
let mut authors = HashMap::new(); let mut authors = HashMap::new();
authors.insert( authors.insert(String::from("Chinua Achebe"), String::from("Nigeria"));
String::from("Chinua Achebe"), authors.insert(String::from("Rabindranath Tagore"), String::from("India"));
String::from("Nigeria"),
);
authors.insert(
String::from("Rabindranath Tagore"),
String::from("India"),
);
authors.insert(String::from("Anita Nair"), String::from("India")); authors.insert(String::from("Anita Nair"), String::from("India"));
qb.set_map(authors); qb.set_map(authors);
@ -1034,17 +1020,7 @@ mod tests {
fn set_where_in() { fn set_where_in() {
let mut qb = QueryBuilder::default(); let mut qb = QueryBuilder::default();
qb.from("test").where_in( qb.from("test").where_in("foo", vec![0, 1, 2, 3, 4, 5]);
"foo",
vec![
0,
1,
2,
3,
4,
5,
],
);
let sql = qb.get_compiled_select(); let sql = qb.get_compiled_select();
let expected = "SELECT *\nFROM \"test\" WHERE \"foo\" IN (?,?,?,?,?,?) "; let expected = "SELECT *\nFROM \"test\" WHERE \"foo\" IN (?,?,?,?,?,?) ";

View File

@ -51,10 +51,7 @@ fn select_without_from() {
fn select_where_in() { fn select_where_in() {
let mut qb = QueryBuilder::default(); let mut qb = QueryBuilder::default();
qb.from("test").where_in( qb.from("test").where_in("foo", vec![0, 1, 2, 3, 4, 5]);
"foo",
vec![0, 1, 2, 3, 4, 5],
);
let sql = qb.get_compiled_select(); let sql = qb.get_compiled_select();
let expected = "SELECT *\nFROM \"test\" WHERE \"foo\" IN (?,?,?,?,?,?) "; let expected = "SELECT *\nFROM \"test\" WHERE \"foo\" IN (?,?,?,?,?,?) ";