Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Commit

Permalink
Preliminary visitor
Browse files Browse the repository at this point in the history
  • Loading branch information
Julius de Bruijn committed May 7, 2020
1 parent 805326d commit 923832b
Show file tree
Hide file tree
Showing 3 changed files with 591 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,17 @@ features = [ "full", "serde-support", "json-1", "uuid-0_8", "chrono-0_4", "array
[features]
default = []

full = ["pooled", "sqlite", "json-1", "postgresql", "uuid-0_8", "chrono-0_4", "mysql"]
full = ["pooled", "sqlite", "json-1", "postgresql", "uuid-0_8", "chrono-0_4", "mysql", "mssql"]
full-postgresql = ["pooled", "postgresql", "json-1", "uuid-0_8", "chrono-0_4", "array"]
full-mysql = ["pooled", "mysql", "json-1", "uuid-0_8", "chrono-0_4"]
full-sqlite = ["pooled", "sqlite", "json-1", "uuid-0_8", "chrono-0_4"]
full-mssql = ["pooled", "mssql", "uuid-0_8", "chrono-0_4"]

single = ["sqlite", "json-1", "postgresql", "uuid-0_8", "chrono-0_4", "mysql"]
single-postgresql = ["postgresql", "json-1", "uuid-0_8", "chrono-0_4", "array"]
single-mysql = ["mysql", "json-1", "uuid-0_8", "chrono-0_4"]
single-sqlite = ["sqlite", "json-1", "uuid-0_8", "chrono-0_4"]
single-mssql = ["mssql", "uuid-0_8", "chrono-0_4"]

pooled = ["mobc", "async-trait"]
sqlite = ["rusqlite", "libsqlite3-sys", "tokio/sync"]
Expand All @@ -41,6 +43,7 @@ postgresql = ["rust_decimal/postgres", "native-tls", "tokio-postgres", "postgres
uuid-0_8 = ["uuid"]
chrono-0_4 = ["chrono"]
mysql = ["mysql_async", "tokio"]
mssql = ["tiberius"]
tracing-log = ["tracing", "tracing-core"]
array = []
serde-support = ["serde", "chrono/serde"]
Expand Down Expand Up @@ -69,6 +72,8 @@ native-tls = { version = "0.2", optional = true }

mysql_async = { version = "0.23", optional = true }

tiberius = { git = "https://github.com/prisma/tiberius", optional = true }

log = { version = "0.4", features = ["release_max_level_trace"] }
tracing = { version = "0.1", optional = true }
tracing-core = { version = "0.1", optional = true }
Expand Down
30 changes: 30 additions & 0 deletions src/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
//! [ast](../ast/index.html) module.
//!
//! For prelude, all important imports are in `quaint::visitor::*`;
mod mssql;
mod mysql;
mod postgres;
mod sqlite;

pub use self::mssql::Mssql;
pub use self::mysql::Mysql;
pub use self::postgres::Postgres;
pub use self::sqlite::Sqlite;
Expand Down Expand Up @@ -341,6 +343,12 @@ pub trait Visitor<'a> {
Ok(())
}

fn visit_multiple_tuple_comparison(&mut self, left: Row<'a>, right: Values<'a>, negate: bool) -> fmt::Result {
self.visit_row(left)?;
self.write(if negate { " NOT IN " } else { " IN " })?;
self.visit_values(right)
}

fn visit_values(&mut self, values: Values<'a>) -> fmt::Result {
self.surround_with("(", ")", |ref mut s| {
let len = values.len();
Expand Down Expand Up @@ -538,6 +546,17 @@ pub trait Visitor<'a> {
self.visit_parameterized(pv)
}

(
Expression {
kind: ExpressionKind::Row(row),
..
},
Expression {
kind: ExpressionKind::Values(values),
..
},
) => self.visit_multiple_tuple_comparison(row, *values, false),

// expr IN (..)
(left, right) => {
self.visit_expression(left)?;
Expand Down Expand Up @@ -599,6 +618,17 @@ pub trait Visitor<'a> {
self.visit_parameterized(pv)
}

(
Expression {
kind: ExpressionKind::Row(row),
..
},
Expression {
kind: ExpressionKind::Values(values),
..
},
) => self.visit_multiple_tuple_comparison(row, *values, true),

// expr IN (..)
(left, right) => {
self.visit_expression(left)?;
Expand Down
Loading

0 comments on commit 923832b

Please sign in to comment.