From 877b312b34f371e6a3f6b7780290797d557a70a8 Mon Sep 17 00:00:00 2001 From: Dmitriy Pleshevskiy Date: Fri, 22 Oct 2021 00:54:47 +0300 Subject: [PATCH] chore: add example to readme --- README.md | 18 +++++++++++++++++- src/lib.rs | 22 +++++++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 275c010..065af28 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,23 @@ In stable rust channel you can use only connection interface, but if you use nig ## Usage -See examples directory. +```rust +fn main() -> Result<(), Box> { + // create pool to our database + let pool = create_postgres_pool(); + // initialize persistence + let persistence = ood_persistence::r2d2_postgres::new(&pool); + // get connection to database + let mut conn = persistence.get_connection()?; + // we can query something + let res: i32 = conn.inner().query_one("select 1", &[])?.get(0); + assert_eq!(res, 1); + + Ok(()) +} +``` + +See examples directory for more information. ## Contributors diff --git a/src/lib.rs b/src/lib.rs index 9f1ea48..9468b36 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -25,7 +25,27 @@ //! //! ## Usage //! -//! See examples directory. +//! ```rust +//! fn main() -> Result<(), Box> { +//! // create pool to our database +//! let pool = create_postgres_pool(); +//! // initialize persistence +//! let persistence = ood_persistence::r2d2_postgres::new(&pool); +//! // get connection to database +//! let mut conn = persistence.get_connection()?; +//! // we can query something +//! let res: i32 = conn.inner().query_one("select 1", &[])?.get(0); +//! assert_eq!(res, 1); +//! +//! Ok(()) +//! } +//! ``` +//! +//! See examples directory for more information. +//! +//! ## Contributors +//! +//! [pleshevskiy](https://github.com/pleshevskiy) (Dmitriy Pleshevskiy) – creator, maintainer. //! #![forbid(unsafe_code, non_ascii_idents)] #![deny(clippy::pedantic)]