@@ -32,22 +32,22 @@ fn main() {
3232 let conn = PostgresConnection :: connect (" postgres://postgres@localhost" ,
3333 & NoSsl );
3434
35- conn . update (" CREATE TABLE person (
35+ conn . execute (" CREATE TABLE person (
3636 id SERIAL PRIMARY KEY,
3737 name VARCHAR NOT NULL,
3838 time_created TIMESTAMP NOT NULL,
3939 data BYTEA
40- )" , []);
40+ )" , []);
4141 let me = Person {
4242 id : 0 ,
4343 name : ~" Steven" ,
4444 time_created : time :: get_time (),
4545 data : None
4646 };
47- conn . update (" INSERT INTO person (name, time_created, data)
47+ conn . execute (" INSERT INTO person (name, time_created, data)
4848 VALUES ($1, $2, $3)" ,
49- [& me . name as & ToSql , & me . time_created as & ToSql ,
50- & me . data as & ToSql ]);
49+ [& me . name as & ToSql , & me . time_created as & ToSql ,
50+ & me . data as & ToSql ]);
5151
5252 let stmt = conn . prepare (" SELECT id, name, time_created, data FROM person" );
5353 for row in stmt . query ([]) {
@@ -97,13 +97,13 @@ let stmt = conn.prepare("SELECT * FROM foo WHERE bar = $1 AND baz = $2");
9797
9898Querying
9999--------
100- A prepared statement can be executed with the ` query ` and ` update ` methods.
100+ A prepared statement can be executed with the ` query ` and ` execute ` methods.
101101Both methods take an array of parameters to bind to the query represented as
102- ` &ToSql ` trait objects. ` update ` returns the number of rows affected by the
102+ ` &ToSql ` trait objects. ` execute ` returns the number of rows affected by the
103103query (or 0 if not applicable):
104104``` rust
105105let stmt = conn . prepare (" UPDATE foo SET bar = $1 WHERE baz = $2" );
106- let updates = stmt . update ([& 1i32 as & ToSql , & & " biz" as & ToSql ]);
106+ let updates = stmt . execute ([& 1i32 as & ToSql , & & " biz" as & ToSql ]);
107107println! (" {} rows were updated" , updates );
108108```
109109` query ` returns an iterator over the rows returned from the database. The
@@ -118,10 +118,10 @@ for row in stmt.query([]) {
118118 println! (" bar: {}, baz: {}" , bar , baz );
119119}
120120```
121- In addition, ` PostgresConnection ` has a utility ` update ` method which is useful
121+ In addition, ` PostgresConnection ` has a utility ` execute ` method which is useful
122122if a statement is only going to be executed once:
123123``` rust
124- let updates = conn . update (" UPDATE foo SET bar = $1 WHERE baz = $2" ,
124+ let updates = conn . execute (" UPDATE foo SET bar = $1 WHERE baz = $2" ,
125125 [& 1i32 as & ToSql , & & " biz" as & ToSql ]);
126126println! (" {} rows were updated" , updates );
127127```
@@ -134,7 +134,7 @@ The `transaction` method will start a new transaction. It returns a
134134transaction:
135135``` rust
136136let trans = conn . transaction ();
137- trans . update (... );
137+ trans . execute (... );
138138let stmt = trans . prepare (... );
139139
140140if a_bad_thing_happened {
@@ -157,7 +157,7 @@ The methods described above will fail if there is an error. For each of these
157157methods, there is a second variant prefixed with ` try_ ` which returns a
158158` Result ` :
159159``` rust
160- match conn . try_update (query , params ) {
160+ match conn . try_execute (query , params ) {
161161 Ok (updates ) => println! (" {} rows were updated" , updates ),
162162 Err (err ) => match err . code {
163163 NotNullViolation => println! (" Something was NULL that shouldn't be" ),
0 commit comments