libpq/
lib.rs

1#![warn(warnings)]
2#![cfg_attr(docsrs, feature(doc_cfg))]
3
4#[macro_use]
5mod ffi;
6
7pub mod connection;
8pub mod encrypt;
9pub mod errors;
10pub mod escape;
11pub mod lo;
12pub mod ping;
13#[cfg(feature = "v14")]
14pub mod pipeline;
15pub mod poll;
16#[cfg(unix)]
17pub mod print;
18pub mod result;
19pub mod ssl;
20pub mod state;
21pub mod transaction;
22pub mod types;
23
24#[cfg(feature = "v17")]
25mod cancel;
26mod control_visibility;
27mod encoding;
28mod format;
29mod oid;
30mod status;
31#[cfg(feature = "v14")]
32mod trace;
33mod verbosity;
34
35#[cfg(feature = "v17")]
36pub use cancel::Cancel;
37pub use connection::Connection;
38pub use control_visibility::ContextVisibility;
39pub use encoding::*;
40pub use format::*;
41pub use lo::LargeObject;
42pub use oid::*;
43#[deprecated(since = "4.1.0", note = "Uses PQResult instead")]
44pub use result::PQResult as Result;
45pub use result::PQResult;
46pub use state::State;
47pub use status::*;
48pub use types::Type;
49pub use verbosity::*;
50
51/**
52 * Get the version of the libpq library in use.
53 *
54 * See [PQlibVersion](https://www.postgresql.org/docs/current/libpq-misc.html#LIBPQ-PQLIBVERSION).
55 */
56pub fn version() -> i32 {
57    unsafe { pq_sys::PQlibVersion() }
58}
59
60/**
61 * Retrieves the current time, expressed as the number of microseconds since the Unix epoch (that is, time_t times 1 million).
62 *
63 * See [PQgetCurrentTimeUSec](https://www.postgresql.org/docs/current/libpq-misc.html#LIBPQ-PQGETCURRENTTIMEUSEC).
64 */
65#[cfg(feature = "v17")]
66pub fn current_time_usec() -> i64 {
67    unsafe { pq_sys::PQgetCurrentTimeUSec() }
68}
69
70#[cfg(test)]
71mod test {
72    static INIT: std::sync::Once = std::sync::Once::new();
73
74    pub fn dsn() -> String {
75        std::env::var("PQ_DSN").unwrap_or_else(|_| "host=localhost".to_string())
76    }
77
78    pub fn new_conn() -> crate::Connection {
79        INIT.call_once(|| {
80            env_logger::init();
81        });
82
83        crate::Connection::new(&dsn()).unwrap()
84    }
85
86    #[test]
87    fn version() {
88        assert!(crate::version() > 0);
89    }
90}