use crate::dialect::Dialect;
pub(crate) fn create_virtual_table_sql(name: &str, module: &str, args: &[String]) -> String {
let name = quote_ident(name);
let module = quote_ident(module);
if args.is_empty() {
return format!("CREATE VIRTUAL TABLE IF NOT EXISTS {name} USING {module};");
}
format!(
"CREATE VIRTUAL TABLE IF NOT EXISTS {name} USING {module}({});",
args.join(", ")
)
}
fn quote_ident(ident: &str) -> String {
format!("\"{}\"", ident.replace('"', "\"\""))
}
pub(crate) fn unsupported_dialect_comment(name: &str, module: &str, dialect: Dialect) -> String {
format!(
"-- virtual table {} USING {} is SQLite-only; skipped for {}",
single_line("e_ident(name)),
single_line("e_ident(module)),
dialect.as_str()
)
}
fn single_line(text: &str) -> String {
text.replace(['\n', '\r'], " ")
}