serde_postgres/lib.rs
1//! # Serde Postgres
2//!
3//! Easily deserialize rows from postgres into
4//! arbitrary structs. (Only deserialization is supported).
5//!
6//! This works with following postgres client libraries:
7//!
8//! - [`postgres`](//docs.rs/postgres)
9//! - [`tokio_postgres`](//docs.rs/postgres/tokio_postgres)
10//!
11//! ```rust,no_run
12//! use std::error::Error;
13//! use serde::Deserialize;
14//! use tokio_postgres::{connect, NoTls};
15//!
16//! #[derive(Clone, Debug, Deserialize)]
17//! struct Person {
18//! name: String,
19//! age: i32,
20//! }
21//! #[tokio::main]
22//! async fn main() -> Result<(), Box<dyn Error>> {
23//! let (client, conn) = connect("postgres://postgres@localhost:5432", NoTls).await?;
24//! tokio::spawn(async move { conn.await.unwrap() });
25//!
26//! client.execute(
27//! "CREATE TABLE IF NOT EXISTS Person (
28//! name VARCHAR NOT NULL,
29//! age INT NOT NULL
30//! )",
31//! &[]
32//! ).await?;
33//!
34//! client.execute("INSERT INTO Person (name, age) VALUES ($1, $2)", &[&"Jane", &23]).await?;
35//!
36//! client.execute("INSERT INTO Person (name, age) VALUES ($1, $2)", &[&"Alice", &32]).await?;
37//!
38//! let rows = client.query("SELECT name, age FROM Person", &[]).await?;
39//!
40//! let people: Vec<Person> = serde_postgres::from_rows(&rows)?;
41//!
42//! for person in people {
43//! println!("{:?}", person);
44//! }
45//!
46//! Ok(())
47//! }
48//! ```
49#![deny(missing_docs)]
50
51pub mod de;
52mod raw;
53
54pub use de::{from_row, from_rows, Deserializer, DeError, DeResult};