Skip to content

Commit 237ae8c

Browse files
committed
Move convenience methods to default methods
1 parent bba1f87 commit 237ae8c

1 file changed

Lines changed: 12 additions & 22 deletions

File tree

src/postgres/lib.rs

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,12 @@ pub trait PostgresStatement {
716716
/// A convenience function wrapping `try_update`.
717717
///
718718
/// Fails if there was an error executing the statement.
719-
fn update(&self, params: &[&ToSql]) -> uint;
719+
fn update(&self, params: &[&ToSql]) -> uint {
720+
match self.try_update(params) {
721+
Ok(count) => count,
722+
Err(err) => fail2!("Error running update\n{}", err.to_str())
723+
}
724+
}
720725

721726
/// Attempts to execute the prepared statement, returning an iterator over
722727
/// the resulting rows.
@@ -729,7 +734,12 @@ pub trait PostgresStatement {
729734
/// A convenience function wrapping `try_query`.
730735
///
731736
/// Fails if there was an error executing the statement.
732-
fn query<'a>(&'a self, params: &[&ToSql]) -> PostgresResult<'a>;
737+
fn query<'a>(&'a self, params: &[&ToSql]) -> PostgresResult<'a> {
738+
match self.try_query(params) {
739+
Ok(result) => result,
740+
Err(err) => fail2!("Error executing query:\n{}", err.to_str())
741+
}
742+
}
733743

734744
/// Returns the index of the first result column with the specified name,
735745
/// or `None` if not found.
@@ -850,13 +860,6 @@ impl<'self> PostgresStatement for NormalPostgresStatement<'self> {
850860
self.result_desc.as_slice()
851861
}
852862

853-
fn update(&self, params: &[&ToSql]) -> uint {
854-
match self.try_update(params) {
855-
Ok(count) => count,
856-
Err(err) => fail2!("Error running update\n{}", err.to_str())
857-
}
858-
}
859-
860863
fn try_update(&self, params: &[&ToSql])
861864
-> Result<uint, PostgresDbError> {
862865
match self.execute("", 0, params) {
@@ -895,11 +898,6 @@ impl<'self> PostgresStatement for NormalPostgresStatement<'self> {
895898
Ok(num)
896899
}
897900

898-
fn query<'a>(&'a self, params: &[&ToSql])
899-
-> PostgresResult<'a> {
900-
self.lazy_query(0, params)
901-
}
902-
903901
fn try_query<'a>(&'a self, params: &[&ToSql])
904902
-> Result<PostgresResult<'a>, PostgresDbError> {
905903
self.try_lazy_query(0, params)
@@ -947,18 +945,10 @@ impl<'self> PostgresStatement for TransactionalPostgresStatement<'self> {
947945
(**self).result_descriptions()
948946
}
949947

950-
fn update(&self, params: &[&ToSql]) -> uint {
951-
(**self).update(params)
952-
}
953-
954948
fn try_update(&self, params: &[&ToSql]) -> Result<uint, PostgresDbError> {
955949
(**self).try_update(params)
956950
}
957951

958-
fn query<'a>(&'a self, params: &[&ToSql]) -> PostgresResult<'a> {
959-
(**self).query(params)
960-
}
961-
962952
fn try_query<'a>(&'a self, params: &[&ToSql])
963953
-> Result<PostgresResult<'a>, PostgresDbError> {
964954
(**self).try_query(params)

0 commit comments

Comments
 (0)