chore: add example to readme
This commit is contained in:
parent
f3ab9f4e46
commit
877b312b34
2 changed files with 38 additions and 2 deletions
18
README.md
18
README.md
|
@ -29,7 +29,23 @@ In stable rust channel you can use only connection interface, but if you use nig
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
See examples directory.
|
```rust
|
||||||
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
// 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
|
## Contributors
|
||||||
|
|
22
src/lib.rs
22
src/lib.rs
|
@ -25,7 +25,27 @@
|
||||||
//!
|
//!
|
||||||
//! ## Usage
|
//! ## Usage
|
||||||
//!
|
//!
|
||||||
//! See examples directory.
|
//! ```rust
|
||||||
|
//! fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
//! // 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)]
|
#![forbid(unsafe_code, non_ascii_idents)]
|
||||||
#![deny(clippy::pedantic)]
|
#![deny(clippy::pedantic)]
|
||||||
|
|
Reference in a new issue