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
65
66
67
68
69
70
71
72
73
74
75
//!
//! [`postrpc`](https://github.com/boilerplatter/postgrpc) is a [gRPC](https://grpc.io/) wrapper around Postgres
//! databases that provides a dynamically-typed, JSON-compatible query interface.
//!
//! While most users will use [`postgrpc`](https://github.com/boilerplatter/postgrpc) in its standalone,
//! executable form, this library provides all of the building blocks needed to build your own gRPC server.
//! Customization can be done through feature-based conditional compilation and by implementing
//! [`pools::Pool`] and [`pools::Connection`] traits over customized connection management systems.
//!
//! ## How to use `postgrpc`
//!
//! By default, this crate ships with all of the features required by its executable. If you're
//! using `postgrpc` as a library, you will probably only want to enable a subset of those
//! features. A few of those uses are discussed below.
//!
//! #### gRPC handling as a `tonic::server::NamedService`
//!
//! By default, `postgrpc` ships a connection-pool-agnostic, [`tonic`](https://docs.rs/tonic/)-compatible gRPC Postgres service in
//! [`services::postgres`]. To use this service as a part of a [`tonic`](https://docs.rs/tonic)
//! app without needing to implement your own pool, be sure to enable the `deadpool` feature in
//! your `Cargo.toml`.
//!
//! ##### [`tonic`](https://docs.rs/tonic/latest/tonic/) Example
//! ```rust
//! use postgrpc::{pools::deadpool, services::postgres};
//! use std::sync::Arc;
//! use tonic::transport::Server;
//! // deadpool::Configuration implements serde::Deserialize,
//! // so envy can be used to deserialize it from environment variables
//! use envy::from_env;
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // create the connection pool from environment variables
//! let pool = from_env::<deadpool::Configuration>()?
//! .create_pool()
//! .map(Arc::new)?;
//!
//! // configure and run the tonic server on port 8675
//! Server::builder()
//! .add_service(services::postgres::new(pool))
//! .serve(([127, 0, 0, 1], 8675).into())
//! .await?;
//!
//! Ok(())
//! }
//! ```
//!
//! #### Custom connection pooling
//! See the documentation of [`pools::Pool`] and [`pools::Connection`] for how to implement your
//! own connection pools for [`services`]. Custom pools can be implemented without any default
//! features from this library.
/// Pool implementations and pooling traits for custom connection pools.
/// [`tonic`](https://docs.rs/tonic/latest/tonic/)-compatible gRPC Service implementations for Postgres features.
/// [Interceptors](https://docs.rs/tonic/latest/tonic/service/trait.Interceptor.html) for adding
/// [`tonic::Extensions`] to gRPC requests.
/// Re-export of the [`async_trait`](https://docs.rs/async-trait) macro for implementing
/// [`pools::Pool`] and [`pools::Connection`]
pub use async_trait;
/// Compiled file descriptors for implementing [gRPC
/// reflection](https://github.com/grpc/grpc/blob/master/doc/server-reflection.md) with e.g.
/// [`tonic_reflection`](https://docs.rs/tonic-reflection).
pub const FILE_DESCRIPTOR_SET: & = include_file_descriptor_set!;