mz_postgres_util/
lib.rs

1// Copyright Materialize, Inc. and contributors. All rights reserved.
2//
3// Use of this software is governed by the Business Source License
4// included in the LICENSE file.
5//
6// As of the Change Date specified in that file, in accordance with
7// the Business Source License, use of this software will be governed
8// by the Apache License, Version 2.0.
9
10//! PostgreSQL utility library.
11
12#[cfg(feature = "replication")]
13pub mod replication;
14#[cfg(feature = "replication")]
15pub use replication::{
16    available_replication_slots, drop_replication_slots, get_current_wal_lsn, get_max_wal_senders,
17    get_timeline_id, get_wal_level,
18};
19#[cfg(feature = "schemas")]
20pub mod desc;
21#[cfg(feature = "schemas")]
22pub mod schemas;
23#[cfg(feature = "schemas")]
24pub use schemas::{get_schemas, publication_info};
25#[cfg(feature = "tunnel")]
26pub mod tunnel;
27#[cfg(feature = "tunnel")]
28pub use tunnel::{Client, Config, DEFAULT_SNAPSHOT_STATEMENT_TIMEOUT, TunnelConfig};
29
30pub mod query;
31pub use query::simple_query_opt;
32
33/// An error representing pg, ssh, ssl, and other failures.
34#[derive(Debug, thiserror::Error)]
35pub enum PostgresError {
36    /// Any other error we bail on.
37    #[error(transparent)]
38    Generic(#[from] anyhow::Error),
39    /// Error using ssh.
40    #[cfg(feature = "tunnel")]
41    #[error("error setting up ssh: {0}")]
42    Ssh(#[source] anyhow::Error),
43    /// Error doing io to setup an ssh connection.
44    #[error("error communicating with ssh tunnel: {0}")]
45    SshIo(std::io::Error),
46    /// Error doing io to setup a connection.
47    #[error("IO error in connection: {0}")]
48    Io(#[from] std::io::Error),
49    /// A postgres error.
50    #[error(transparent)]
51    Postgres(#[from] tokio_postgres::Error),
52    /// Error setting up postgres ssl.
53    #[error(transparent)]
54    PostgresSsl(#[from] openssl::error::ErrorStack),
55    #[error("query returned more rows than expected")]
56    UnexpectedRow,
57    /// Cannot find publication
58    ///
59    /// This error is more specific than the others because its occurrence has
60    /// differing semantics from other types of PG errors.
61    #[error("publication {0} does not exist")]
62    PublicationMissing(String),
63}