1
0
Fork 0
forked from 2sys/phonograph
phonograph/phono-backends/src/lib.rs
2025-11-19 09:15:11 +00:00

35 lines
1.6 KiB
Rust

// Phonograph - A friendly PostgreSQL wrapper for nerds of all stripes.
// Copyright (C) 2025 Second System Technologies LLC
//
// This program is free software: you can redistribute it and/or modify it
// under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or (at your
// option) any later version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.
//
// See the GNU Affero General Public License for more details. You should have
// received a copy of the GNU Affero General Public License along with this
// program. If not, see <http://www.gnu.org/licenses/>.
pub mod client;
pub mod pg_acl;
pub mod pg_attribute;
pub mod pg_class;
pub mod pg_database;
pub mod pg_namespace;
pub mod pg_role;
pub mod rolnames;
/// Given a raw identifier (such as a table name, column name, etc.), format it
/// so that it may be safely interpolated into a SQL query.
pub fn escape_identifier(identifier: &str) -> String {
// Escaping identifiers for Postgres is fairly easy, provided that the input is
// already known to contain no invalid multi-byte sequences. Backslashes may
// remain as-is, and embedded double quotes are escaped simply by doubling
// them (`"` becomes `""`). Refer to the PQescapeInternal() function in
// libpq (fe-exec.c) and Diesel's PgQueryBuilder::push_identifier().
format!("\"{}\"", identifier.replace('"', "\"\""))
}