|
1 | 1 | //! A crate providing access to the Postgres large object API. |
| 2 | +//! |
| 3 | +//! # Example |
| 4 | +//! |
| 5 | +//! ```rust,no_run |
| 6 | +//! extern crate postgres; |
| 7 | +//! extern crate postgres_large_object; |
| 8 | +//! |
| 9 | +//! use std::old_path::Path; |
| 10 | +//! use std::old_io::fs::File; |
| 11 | +//! use std::old_io::util; |
| 12 | +//! |
| 13 | +//! use postgres::{Connection, SslMode}; |
| 14 | +//! use postgres_large_object::{LargeObjectExt, LargeObjectTransactionExt, Mode}; |
| 15 | +//! |
| 16 | +//! fn main() { |
| 17 | +//! let conn = Connection::connect("postgres://postgres@localhost", &SslMode::None).unwrap(); |
| 18 | +//! |
| 19 | +//! let mut file = File::open(&Path::new("vacation_photos.tar.gz")).unwrap(); |
| 20 | +//! let trans = conn.transaction().unwrap(); |
| 21 | +//! let oid = trans.create_large_object().unwrap(); |
| 22 | +//! { |
| 23 | +//! let mut large_object = trans.open_large_object(oid, Mode::Write).unwrap(); |
| 24 | +//! util::copy(&mut file, &mut large_object).unwrap(); |
| 25 | +//! } |
| 26 | +//! trans.commit().unwrap(); |
| 27 | +//! |
| 28 | +//! let mut file = File::create(&Path::new("vacation_photos_copy.tar.gz")).unwrap(); |
| 29 | +//! let trans = conn.transaction().unwrap(); |
| 30 | +//! let mut large_object = trans.open_large_object(oid, Mode::Read).unwrap(); |
| 31 | +//! util::copy(&mut large_object, &mut file).unwrap(); |
| 32 | +//! } |
| 33 | +//! ``` |
2 | 34 | #![feature(unsafe_destructor, io, core)] |
3 | 35 | #![doc(html_root_url="https://sfackler.github.io/rust-postgres-large-object/doc")] |
4 | 36 |
|
|
0 commit comments