@@ -32,22 +32,22 @@ fn main() {
32
32
let conn = PostgresConnection :: connect (" postgres://postgres@localhost" ,
33
33
& NoSsl );
34
34
35
- conn . update (" CREATE TABLE person (
35
+ conn . execute (" CREATE TABLE person (
36
36
id SERIAL PRIMARY KEY,
37
37
name VARCHAR NOT NULL,
38
38
time_created TIMESTAMP NOT NULL,
39
39
data BYTEA
40
- )" , []);
40
+ )" , []);
41
41
let me = Person {
42
42
id : 0 ,
43
43
name : ~" Steven" ,
44
44
time_created : time :: get_time (),
45
45
data : None
46
46
};
47
- conn . update (" INSERT INTO person (name, time_created, data)
47
+ conn . execute (" INSERT INTO person (name, time_created, data)
48
48
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 ]);
51
51
52
52
let stmt = conn . prepare (" SELECT id, name, time_created, data FROM person" );
53
53
for row in stmt . query ([]) {
@@ -97,13 +97,13 @@ let stmt = conn.prepare("SELECT * FROM foo WHERE bar = $1 AND baz = $2");
97
97
98
98
Querying
99
99
--------
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.
101
101
Both 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
103
103
query (or 0 if not applicable):
104
104
``` rust
105
105
let 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 ]);
107
107
println! (" {} rows were updated" , updates );
108
108
```
109
109
` query ` returns an iterator over the rows returned from the database. The
@@ -118,10 +118,10 @@ for row in stmt.query([]) {
118
118
println! (" bar: {}, baz: {}" , bar , baz );
119
119
}
120
120
```
121
- In addition, ` PostgresConnection ` has a utility ` update ` method which is useful
121
+ In addition, ` PostgresConnection ` has a utility ` execute ` method which is useful
122
122
if a statement is only going to be executed once:
123
123
``` 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" ,
125
125
[& 1i32 as & ToSql , & & " biz" as & ToSql ]);
126
126
println! (" {} rows were updated" , updates );
127
127
```
@@ -134,7 +134,7 @@ The `transaction` method will start a new transaction. It returns a
134
134
transaction:
135
135
``` rust
136
136
let trans = conn . transaction ();
137
- trans . update (... );
137
+ trans . execute (... );
138
138
let stmt = trans . prepare (... );
139
139
140
140
if a_bad_thing_happened {
@@ -157,7 +157,7 @@ The methods described above will fail if there is an error. For each of these
157
157
methods, there is a second variant prefixed with ` try_ ` which returns a
158
158
` Result ` :
159
159
``` rust
160
- match conn . try_update (query , params ) {
160
+ match conn . try_execute (query , params ) {
161
161
Ok (updates ) => println! (" {} rows were updated" , updates ),
162
162
Err (err ) => match err . code {
163
163
NotNullViolation => println! (" Something was NULL that shouldn't be" ),
0 commit comments