use std::borrow::Cow;
mod parsers;
mod scanner;
#[cfg(test)]
mod tests;
mod translate;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PlaceholderStyle {
Postgres,
Sqlite,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum TranslationMode {
PoolDefault,
ForceOn,
ForceOff,
}
impl TranslationMode {
#[must_use]
pub fn resolve(self, pool_default: bool) -> bool {
match self {
TranslationMode::PoolDefault => pool_default,
TranslationMode::ForceOn => true,
TranslationMode::ForceOff => false,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum PrepareMode {
#[default]
Direct,
Prepared,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct QueryOptions {
pub translation: TranslationMode,
pub prepare: PrepareMode,
}
impl Default for QueryOptions {
fn default() -> Self {
Self {
translation: TranslationMode::PoolDefault,
prepare: PrepareMode::default(),
}
}
}
impl QueryOptions {
#[must_use]
pub fn with_translation(mut self, translation: TranslationMode) -> Self {
self.translation = translation;
self
}
#[must_use]
pub fn with_prepare(mut self, prepare: PrepareMode) -> Self {
self.prepare = prepare;
self
}
}
#[must_use]
pub fn translate_placeholders(sql: &str, target: PlaceholderStyle, enabled: bool) -> Cow<'_, str> {
translate::translate_sql(sql, target, enabled)
}