Skip to content

Commit 920d7d5

Browse files
committed
Update README for update -> execute change
1 parent 219d10f commit 920d7d5

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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

9898
Querying
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.
101101
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
103103
query (or 0 if not applicable):
104104
```rust
105105
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]);
107107
println!("{} 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
122122
if 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]);
126126
println!("{} rows were updated", updates);
127127
```
@@ -134,7 +134,7 @@ The `transaction` method will start a new transaction. It returns a
134134
transaction:
135135
```rust
136136
let trans = conn.transaction();
137-
trans.update(...);
137+
trans.execute(...);
138138
let stmt = trans.prepare(...);
139139

140140
if a_bad_thing_happened {
@@ -157,7 +157,7 @@ The methods described above will fail if there is an error. For each of these
157157
methods, 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

Comments
 (0)