mod builder;
mod parts;
mod query;
mod stream;
#[cfg(test)]
mod tests;
pub use builder::Sql;
pub use query::Query;
pub use stream::FromRowStream;
pub fn query(initial_sql: impl Into<String>) -> Query {
Query::new(initial_sql)
}
pub fn sql(initial_sql: impl Into<String>) -> Sql {
Sql::new(initial_sql)
}
fn strip_sql_prefix(sql: &str) -> &str {
let mut s = sql;
loop {
let before = s;
s = s.trim_start();
if s.starts_with("--") {
if let Some(pos) = s.find('\n') {
s = &s[pos + 1..];
continue;
}
return ""; }
if s.starts_with("/*") {
if let Some(pos) = s.find("*/") {
s = &s[pos + 2..];
continue;
}
return ""; }
if s.starts_with('(') {
s = &s[1..];
continue;
}
if s == before {
break;
}
}
s
}
fn starts_with_keyword(s: &str, keyword: &str) -> bool {
match s.get(0..keyword.len()) {
Some(prefix) => prefix.eq_ignore_ascii_case(keyword),
None => false,
}
}