Skip to content

Commit c11cbd6

Browse files
committed
PostgresConnection -> Connection
1 parent d886665 commit c11cbd6

5 files changed

Lines changed: 136 additions & 136 deletions

File tree

src/lib.rs

Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
//!
99
//! use time::Timespec;
1010
//!
11-
//! use postgres::{PostgresConnection, NoSsl};
11+
//! use postgres::{Connection, NoSsl};
1212
//!
1313
//! struct Person {
1414
//! id: i32,
@@ -18,7 +18,7 @@
1818
//! }
1919
//!
2020
//! fn main() {
21-
//! let conn = PostgresConnection::connect("postgresql://postgres@localhost",
21+
//! let conn = Connection::connect("postgresql://postgres@localhost",
2222
//! &NoSsl).unwrap();
2323
//!
2424
//! conn.execute("CREATE TABLE person (
@@ -182,7 +182,7 @@ pub struct ConnectParams {
182182
pub port: Option<Port>,
183183
/// The user to login as.
184184
///
185-
/// `PostgresConnection::connect` requires a user but `cancel_query` does
185+
/// `Connection::connect` requires a user but `cancel_query` does
186186
/// not.
187187
pub user: Option<UserInfo>,
188188
/// The database to connect to. Defaults the value of `user`.
@@ -261,7 +261,7 @@ pub trait NoticeHandler {
261261

262262
/// A notice handler which logs at the `info` level.
263263
///
264-
/// This is the default handler used by a `PostgresConnection`.
264+
/// This is the default handler used by a `Connection`.
265265
pub struct DefaultNoticeHandler;
266266

267267
impl NoticeHandler for DefaultNoticeHandler {
@@ -282,7 +282,7 @@ pub struct Notification {
282282

283283
/// An iterator over asynchronous notifications
284284
pub struct Notifications<'conn> {
285-
conn: &'conn PostgresConnection
285+
conn: &'conn Connection
286286
}
287287

288288
impl<'conn> Iterator<Notification> for Notifications<'conn> {
@@ -312,18 +312,18 @@ pub struct CancelData {
312312
/// unable to connect to the database.
313313
///
314314
/// A `CancelData` object can be created via
315-
/// `PostgresConnection::cancel_data`. The object can cancel any query made on
315+
/// `Connection::cancel_data`. The object can cancel any query made on
316316
/// that connection.
317317
///
318318
/// Only the host and port of the connection info are used. See
319-
/// `PostgresConnection::connect` for details of the `params` argument.
319+
/// `Connection::connect` for details of the `params` argument.
320320
///
321321
/// ## Example
322322
///
323323
/// ```rust,no_run
324-
/// # use postgres::{PostgresConnection, NoSsl};
324+
/// # use postgres::{Connection, NoSsl};
325325
/// # let url = "";
326-
/// let conn = PostgresConnection::connect(url, &NoSsl).unwrap();
326+
/// let conn = Connection::connect(url, &NoSsl).unwrap();
327327
/// let cancel_data = conn.cancel_data();
328328
/// spawn(proc() {
329329
/// conn.execute("SOME EXPENSIVE QUERY", []).unwrap();
@@ -346,7 +346,7 @@ pub fn cancel_query<T>(params: T, ssl: &SslMode, data: CancelData)
346346
Ok(())
347347
}
348348

349-
struct InnerPostgresConnection {
349+
struct InnerConnection {
350350
stream: BufferedStream<MaybeSslStream<InternalStream>>,
351351
next_stmt_id: uint,
352352
notice_handler: Box<NoticeHandler+Send>,
@@ -359,17 +359,17 @@ struct InnerPostgresConnection {
359359
canary: u32,
360360
}
361361

362-
impl Drop for InnerPostgresConnection {
362+
impl Drop for InnerConnection {
363363
fn drop(&mut self) {
364364
if !self.finished {
365365
let _ = self.finish_inner();
366366
}
367367
}
368368
}
369369

370-
impl InnerPostgresConnection {
370+
impl InnerConnection {
371371
fn connect<T>(params: T, ssl: &SslMode)
372-
-> result::Result<InnerPostgresConnection, PostgresConnectError>
372+
-> result::Result<InnerConnection, PostgresConnectError>
373373
where T: IntoConnectParams {
374374
let params = try!(params.into_connect_params());
375375
let stream = try!(io::initialize_stream(&params, ssl));
@@ -383,7 +383,7 @@ impl InnerPostgresConnection {
383383

384384
let user = try!(user.ok_or(MissingUser));
385385

386-
let mut conn = InnerPostgresConnection {
386+
let mut conn = InnerConnection {
387387
stream: BufferedStream::new(stream),
388388
next_stmt_id: 0,
389389
notice_handler: box DefaultNoticeHandler,
@@ -567,7 +567,7 @@ impl InnerPostgresConnection {
567567
Ok((stmt_name, param_types, result_desc))
568568
}
569569

570-
fn prepare<'a>(&mut self, query: &str, conn: &'a PostgresConnection)
570+
fn prepare<'a>(&mut self, query: &str, conn: &'a Connection)
571571
-> Result<PostgresStatement<'a>> {
572572
let (stmt_name, param_types, result_desc) = try!(self.raw_prepare(query));
573573
Ok(PostgresStatement {
@@ -580,7 +580,7 @@ impl InnerPostgresConnection {
580580
})
581581
}
582582

583-
fn prepare_copy_in<'a>(&mut self, table: &str, rows: &[&str], conn: &'a PostgresConnection)
583+
fn prepare_copy_in<'a>(&mut self, table: &str, rows: &[&str], conn: &'a Connection)
584584
-> Result<PostgresCopyInStatement<'a>> {
585585
let mut query = MemWriter::new();
586586
let _ = write!(query, "SELECT ");
@@ -703,11 +703,11 @@ impl InnerPostgresConnection {
703703
}
704704

705705
/// A connection to a Postgres database.
706-
pub struct PostgresConnection {
707-
conn: RefCell<InnerPostgresConnection>
706+
pub struct Connection {
707+
conn: RefCell<InnerConnection>
708708
}
709709

710-
impl PostgresConnection {
710+
impl Connection {
711711
/// Creates a new connection to a Postgres database.
712712
///
713713
/// Most applications can use a URL string in the normal format:
@@ -730,23 +730,23 @@ impl PostgresConnection {
730730
/// ## Examples
731731
///
732732
/// ```rust,no_run
733-
/// # use postgres::{PostgresConnection, NoSsl};
733+
/// # use postgres::{Connection, NoSsl};
734734
/// # let _ = || {
735735
/// let url = "postgresql://postgres:hunter2@localhost:2994/foodb";
736-
/// let conn = try!(PostgresConnection::connect(url, &NoSsl));
736+
/// let conn = try!(Connection::connect(url, &NoSsl));
737737
/// # Ok(()) };
738738
/// ```
739739
///
740740
/// ```rust,no_run
741-
/// # use postgres::{PostgresConnection, NoSsl};
741+
/// # use postgres::{Connection, NoSsl};
742742
/// # let _ = || {
743743
/// let url = "postgresql://postgres@%2Frun%2Fpostgres";
744-
/// let conn = try!(PostgresConnection::connect(url, &NoSsl));
744+
/// let conn = try!(Connection::connect(url, &NoSsl));
745745
/// # Ok(()) };
746746
/// ```
747747
///
748748
/// ```rust,no_run
749-
/// # use postgres::{PostgresConnection, UserInfo, ConnectParams, NoSsl, TargetUnix};
749+
/// # use postgres::{Connection, UserInfo, ConnectParams, NoSsl, TargetUnix};
750750
/// # let _ = || {
751751
/// # let some_crazy_path = Path::new("");
752752
/// let params = ConnectParams {
@@ -759,14 +759,14 @@ impl PostgresConnection {
759759
/// database: None,
760760
/// options: vec![],
761761
/// };
762-
/// let conn = try!(PostgresConnection::connect(params, &NoSsl));
762+
/// let conn = try!(Connection::connect(params, &NoSsl));
763763
/// # Ok(()) };
764764
/// ```
765765
pub fn connect<T>(params: T, ssl: &SslMode)
766-
-> result::Result<PostgresConnection, PostgresConnectError>
766+
-> result::Result<Connection, PostgresConnectError>
767767
where T: IntoConnectParams {
768-
InnerPostgresConnection::connect(params, ssl).map(|conn| {
769-
PostgresConnection { conn: RefCell::new(conn) }
768+
InnerConnection::connect(params, ssl).map(|conn| {
769+
Connection { conn: RefCell::new(conn) }
770770
})
771771
}
772772

@@ -794,8 +794,8 @@ impl PostgresConnection {
794794
/// ## Example
795795
///
796796
/// ```rust,no_run
797-
/// # use postgres::{PostgresConnection, NoSsl};
798-
/// # let conn = PostgresConnection::connect("", &NoSsl).unwrap();
797+
/// # use postgres::{Connection, NoSsl};
798+
/// # let conn = Connection::connect("", &NoSsl).unwrap();
799799
/// let maybe_stmt = conn.prepare("SELECT foo FROM bar WHERE baz = $1");
800800
/// let stmt = match maybe_stmt {
801801
/// Ok(stmt) => stmt,
@@ -817,10 +817,10 @@ impl PostgresConnection {
817817
/// ## Example
818818
///
819819
/// ```rust,no_run
820-
/// # use postgres::{PostgresConnection, NoSsl};
820+
/// # use postgres::{Connection, NoSsl};
821821
/// # use postgres::types::ToSql;
822822
/// # let _ = || {
823-
/// # let conn = PostgresConnection::connect("", &NoSsl).unwrap();
823+
/// # let conn = Connection::connect("", &NoSsl).unwrap();
824824
/// try!(conn.execute("CREATE TABLE foo (
825825
/// bar INT PRIMARY KEY,
826826
/// baz VARCHAR
@@ -854,9 +854,9 @@ impl PostgresConnection {
854854
/// ## Example
855855
///
856856
/// ```rust,no_run
857-
/// # use postgres::{PostgresConnection, NoSsl};
857+
/// # use postgres::{Connection, NoSsl};
858858
/// # fn foo() -> Result<(), postgres::error::PostgresError> {
859-
/// # let conn = PostgresConnection::connect("", &NoSsl).unwrap();
859+
/// # let conn = Connection::connect("", &NoSsl).unwrap();
860860
/// let trans = try!(conn.transaction());
861861
/// try!(trans.execute("UPDATE foo SET bar = 10", []));
862862
/// // ...
@@ -908,8 +908,8 @@ impl PostgresConnection {
908908
/// ## Example
909909
///
910910
/// ```rust,no_run
911-
/// # use postgres::{PostgresConnection, Result};
912-
/// fn init_db(conn: &PostgresConnection) -> Result<()> {
911+
/// # use postgres::{Connection, Result};
912+
/// fn init_db(conn: &Connection) -> Result<()> {
913913
/// conn.batch_execute("
914914
/// CREATE TABLE person (
915915
/// id SERIAL PRIMARY KEY,
@@ -954,7 +954,7 @@ impl PostgresConnection {
954954
/// Consumes the connection, closing it.
955955
///
956956
/// Functionally equivalent to the `Drop` implementation for
957-
/// `PostgresConnection` except that it returns any error encountered to
957+
/// `Connection` except that it returns any error encountered to
958958
/// the caller.
959959
pub fn finish(self) -> Result<()> {
960960
let mut conn = self.conn.borrow_mut();
@@ -985,7 +985,7 @@ pub enum SslMode {
985985
///
986986
/// The transaction will roll back by default.
987987
pub struct PostgresTransaction<'conn> {
988-
conn: &'conn PostgresConnection,
988+
conn: &'conn Connection,
989989
commit: Cell<bool>,
990990
depth: u32,
991991
finished: bool,
@@ -1014,7 +1014,7 @@ impl<'conn> PostgresTransaction<'conn> {
10141014
conn.quick_query(query).map(|_| ())
10151015
}
10161016

1017-
/// Like `PostgresConnection::prepare`.
1017+
/// Like `Connection::prepare`.
10181018
pub fn prepare<'a>(&'a self, query: &str) -> Result<PostgresStatement<'a>> {
10191019
let mut conn = self.conn.conn.borrow_mut();
10201020
if conn.trans_depth != self.depth {
@@ -1023,7 +1023,7 @@ impl<'conn> PostgresTransaction<'conn> {
10231023
conn.prepare(query, self.conn)
10241024
}
10251025

1026-
/// Like `PostgresConnection::prepare_copy_in`.
1026+
/// Like `Connection::prepare_copy_in`.
10271027
pub fn prepare_copy_in<'a>(&'a self, table: &str, cols: &[&str])
10281028
-> Result<PostgresCopyInStatement<'a>> {
10291029
let mut conn = self.conn.conn.borrow_mut();
@@ -1033,12 +1033,12 @@ impl<'conn> PostgresTransaction<'conn> {
10331033
conn.prepare_copy_in(table, cols, self.conn)
10341034
}
10351035

1036-
/// Like `PostgresConnection::execute`.
1036+
/// Like `Connection::execute`.
10371037
pub fn execute(&self, query: &str, params: &[&ToSql]) -> Result<uint> {
10381038
self.prepare(query).and_then(|s| s.execute(params))
10391039
}
10401040

1041-
/// Like `PostgresConnection::batch_execute`.
1041+
/// Like `Connection::batch_execute`.
10421042
pub fn batch_execute(&self, query: &str) -> Result<()> {
10431043
let mut conn = self.conn.conn.borrow_mut();
10441044
if conn.trans_depth != self.depth {
@@ -1047,7 +1047,7 @@ impl<'conn> PostgresTransaction<'conn> {
10471047
conn.quick_query(query).map(|_| ())
10481048
}
10491049

1050-
/// Like `PostgresConnection::transaction`.
1050+
/// Like `Connection::transaction`.
10511051
pub fn transaction<'a>(&'a self) -> Result<PostgresTransaction<'a>> {
10521052
let mut conn = self.conn.conn.borrow_mut();
10531053
check_desync!(conn);
@@ -1121,7 +1121,7 @@ impl<'conn> PostgresTransaction<'conn> {
11211121

11221122
/// A prepared statement
11231123
pub struct PostgresStatement<'conn> {
1124-
conn: &'conn PostgresConnection,
1124+
conn: &'conn Connection,
11251125
name: String,
11261126
param_types: Vec<PostgresType>,
11271127
result_desc: Vec<ResultDescription>,
@@ -1224,8 +1224,8 @@ impl<'conn> PostgresStatement<'conn> {
12241224
/// ## Example
12251225
///
12261226
/// ```rust,no_run
1227-
/// # use postgres::{PostgresConnection, NoSsl};
1228-
/// # let conn = PostgresConnection::connect("", &NoSsl).unwrap();
1227+
/// # use postgres::{Connection, NoSsl};
1228+
/// # let conn = Connection::connect("", &NoSsl).unwrap();
12291229
/// # let bar = 1i32;
12301230
/// # let baz = true;
12311231
/// let stmt = conn.prepare("UPDATE foo SET bar = $1 WHERE baz = $2").unwrap();
@@ -1278,8 +1278,8 @@ impl<'conn> PostgresStatement<'conn> {
12781278
/// ## Example
12791279
///
12801280
/// ```rust,no_run
1281-
/// # use postgres::{PostgresConnection, NoSsl};
1282-
/// # let conn = PostgresConnection::connect("", &NoSsl).unwrap();
1281+
/// # use postgres::{Connection, NoSsl};
1282+
/// # let conn = Connection::connect("", &NoSsl).unwrap();
12831283
/// let stmt = conn.prepare("SELECT foo FROM bar WHERE baz = $1").unwrap();
12841284
/// # let baz = true;
12851285
/// let mut rows = match stmt.query(&[&baz]) {
@@ -1484,8 +1484,8 @@ impl<'stmt> PostgresRow<'stmt> {
14841484
/// ## Example
14851485
///
14861486
/// ```rust,no_run
1487-
/// # use postgres::{PostgresConnection, NoSsl};
1488-
/// # let conn = PostgresConnection::connect("", &NoSsl).unwrap();
1487+
/// # use postgres::{Connection, NoSsl};
1488+
/// # let conn = Connection::connect("", &NoSsl).unwrap();
14891489
/// # let stmt = conn.prepare("").unwrap();
14901490
/// # let mut result = stmt.query([]).unwrap();
14911491
/// # let row = result.next().unwrap();
@@ -1554,7 +1554,7 @@ impl<'trans, 'stmt> Iterator<Result<PostgresRow<'stmt>>>
15541554

15551555
/// A prepared COPY FROM STDIN statement
15561556
pub struct PostgresCopyInStatement<'a> {
1557-
conn: &'a PostgresConnection,
1557+
conn: &'a Connection,
15581558
name: String,
15591559
column_types: Vec<PostgresType>,
15601560
finished: bool,
@@ -1712,26 +1712,26 @@ impl<'a> PostgresCopyInStatement<'a> {
17121712

17131713
/// A trait allowing abstraction over connections and transactions
17141714
pub trait GenericConnection {
1715-
/// Like `PostgresConnection::prepare`.
1715+
/// Like `Connection::prepare`.
17161716
fn prepare<'a>(&'a self, query: &str) -> Result<PostgresStatement<'a>>;
17171717

1718-
/// Like `PostgresConnection::execute`.
1718+
/// Like `Connection::execute`.
17191719
fn execute(&self, query: &str, params: &[&ToSql]) -> Result<uint> {
17201720
self.prepare(query).and_then(|s| s.execute(params))
17211721
}
17221722

1723-
/// Like `PostgresConnection::prepare_copy_in`.
1723+
/// Like `Connection::prepare_copy_in`.
17241724
fn prepare_copy_in<'a>(&'a self, table: &str, columns: &[&str])
17251725
-> Result<PostgresCopyInStatement<'a>>;
17261726

1727-
/// Like `PostgresConnection::transaction`.
1727+
/// Like `Connection::transaction`.
17281728
fn transaction<'a>(&'a self) -> Result<PostgresTransaction<'a>>;
17291729

1730-
/// Like `PostgresConnection::batch_execute`.
1730+
/// Like `Connection::batch_execute`.
17311731
fn batch_execute(&self, query: &str) -> Result<()>;
17321732
}
17331733

1734-
impl GenericConnection for PostgresConnection {
1734+
impl GenericConnection for Connection {
17351735
fn prepare<'a>(&'a self, query: &str) -> Result<PostgresStatement<'a>> {
17361736
self.prepare(query)
17371737
}

0 commit comments

Comments
 (0)