1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//! Database identifier quoting utilities.
//!
//! This module provides database-specific identifier quoting functions that handle
//! schema-qualified identifiers (e.g., `schema.table`, `catalog.schema.table`).
//!
//! Each function splits on `.` and quotes each component with the appropriate syntax
//! for the target database.
/// Quote a PostgreSQL identifier.
///
/// PostgreSQL uses double quotes for identifiers. Schema-qualified names
/// (e.g., `schema.table`) are split and quoted per component.
///
/// # Examples
///
/// ```rust
/// use fraiseql_db::quote_postgres_identifier;
/// assert_eq!(quote_postgres_identifier("v_user"), "\"v_user\"");
/// assert_eq!(quote_postgres_identifier("benchmark.v_user"), "\"benchmark\".\"v_user\"");
/// assert_eq!(
/// quote_postgres_identifier("catalog.schema.table"),
/// "\"catalog\".\"schema\".\"table\""
/// );
/// ```
/// The SQL expression for the relation `schema` and `name` name, as a `regclass`, or `NULL`
/// when the current role cannot use `schema`.
///
/// `schema` and `name` are SQL expressions, such as the columns of a catalog row
/// (`g.schema`, `g.name`). `to_regclass` raises `permission denied for schema` for a schema
/// without `USAGE`, rather than returning `NULL`. A query resolving every row of a catalog
/// such as `tviews.registry` would then fail as a whole because of one relation the role
/// cannot read anyway. `CASE` decides first, so `to_regclass` never sees such a schema.
///
/// # Examples
///
/// ```rust
/// use fraiseql_db::usable_relation;
/// let sql = usable_relation("g.schema", "g.name");
/// assert!(sql.starts_with("CASE WHEN EXISTS"));
/// assert!(sql.ends_with("pg_catalog.format('%I.%I', g.schema, g.name)) END"));
/// ```