Skip to main content

gobby_code/db/
mod.rs

1use postgres::Client;
2
3use crate::schema;
4
5mod queries;
6mod resolution;
7
8pub use queries::*;
9pub use resolution::*;
10
11/// Open a connection for command paths that may write to the hub.
12///
13/// This currently shares the same connection logic as read-only callers, but
14/// keeping the intent explicit preserves a routing point for future pools,
15/// permissions, or replicas.
16pub fn connect_readwrite(database_url: &str) -> anyhow::Result<Client> {
17    let mut client = gobby_core::postgres::connect_readwrite(database_url)?;
18    schema::validate_runtime_schema(&mut client)?;
19    Ok(client)
20}
21
22/// Open a connection for command paths that only read from the hub.
23///
24/// This currently shares the same connection logic as read-write callers, but
25/// keeping the intent explicit preserves a routing point for future pools,
26/// permissions, or replicas.
27pub fn connect_readonly(database_url: &str) -> anyhow::Result<Client> {
28    let mut client = gobby_core::postgres::connect_readonly(database_url)?;
29    schema::validate_runtime_schema(&mut client)?;
30    Ok(client)
31}
32
33pub fn read_config_value(conn: &mut Client, key: &str) -> anyhow::Result<Option<String>> {
34    gobby_core::postgres::read_config_value(conn, key)
35}