migratrom 0.2.0

Declarative, self-verifying database migrations (core engine).
Documentation
//! Identifier and literal quoting. Standard SQL: double-quote identifiers,
//! single-quote literals, doubling embedded quotes.

/// Double-quote an identifier, escaping embedded double-quotes by doubling.
pub fn quote_ident(name: &str) -> String {
    format!("\"{}\"", name.replace('"', "\"\""))
}

/// Single-quote a string literal, escaping embedded single-quotes by doubling.
pub fn quote_literal(value: &str) -> String {
    format!("'{}'", value.replace('\'', "''"))
}

/// Fully-qualified relation name: `"schema"."name"`.
pub fn qualified(schema: &str, name: &str) -> String {
    format!("{}.{}", quote_ident(schema), quote_ident(name))
}

/// A string literal usable inside `to_regclass(...)`: `'"schema"."name"'`.
pub fn regclass_literal(schema: &str, name: &str) -> String {
    quote_literal(&qualified(schema, name))
}

/// Comma-joined quoted column list: `"a", "b"`.
pub fn quote_ident_list(names: &[String]) -> String {
    names
        .iter()
        .map(|n| quote_ident(n))
        .collect::<Vec<_>>()
        .join(", ")
}