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
63
64
// Copyright Materialize, Inc. and contributors. All rights reserved.
//
// Use of this software is governed by the Business Source License
// included in the LICENSE file.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0.

//! PostgreSQL utility library.

#[cfg(feature = "replication")]
pub mod replication;
#[cfg(feature = "replication")]
pub use replication::{
    available_replication_slots, drop_replication_slots, get_max_wal_senders, get_timeline_id,
    get_wal_level,
};
#[cfg(feature = "schemas")]
pub mod desc;
#[cfg(feature = "schemas")]
pub mod schemas;
#[cfg(feature = "schemas")]
pub use schemas::{get_schemas, publication_info};
#[cfg(feature = "tunnel")]
pub mod tunnel;
#[cfg(feature = "tunnel")]
pub use tunnel::{
    Config, TcpTimeoutConfig, TunnelConfig, DEFAULT_CONNECT_TIMEOUT, DEFAULT_KEEPALIVE_IDLE,
    DEFAULT_KEEPALIVE_INTERVAL, DEFAULT_KEEPALIVE_RETRIES, DEFAULT_SNAPSHOT_STATEMENT_TIMEOUT,
    DEFAULT_TCP_USER_TIMEOUT,
};

pub mod query;
pub use query::simple_query_opt;

/// An error representing pg, ssh, ssl, and other failures.
#[derive(Debug, thiserror::Error)]
pub enum PostgresError {
    /// Any other error we bail on.
    #[error(transparent)]
    Generic(#[from] anyhow::Error),
    /// Error using ssh.
    #[cfg(feature = "tunnel")]
    #[error("error setting up ssh: {0}")]
    Ssh(#[source] anyhow::Error),
    /// Error doing io to setup an ssh connection.
    #[error("error communicating with ssh tunnel: {0}")]
    SshIo(#[from] std::io::Error),
    /// A postgres error.
    #[error(transparent)]
    Postgres(#[from] tokio_postgres::Error),
    /// Error setting up postgres ssl.
    #[error(transparent)]
    PostgresSsl(#[from] openssl::error::ErrorStack),
    #[error("query returned more rows than expected")]
    UnexpectedRow,
    /// Cannot find publication
    ///
    /// This error is more specific than the others because its occurrence has
    /// differing semantics from other types of PG errors.
    #[error("publication {0} does not exist")]
    PublicationMissing(String),
}