Skip to content

Commit 2ecc9f8

Browse files
committed
update original
1 parent 39d973c commit 2ecc9f8

File tree

5 files changed

+21
-23
lines changed

5 files changed

+21
-23
lines changed

rust-cookbook/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ rayon = "1.0"
4343
regex = "1.0"
4444
reqwest = { version = "0.10", features = ["blocking", "json", "stream"] }
4545
ring = "0.16.11"
46-
rusqlite = { version = "0.22", features = ["chrono"] }
46+
rusqlite = { version = "0.25", features = ["chrono"] }
4747
same-file = "1.0"
4848
select = "0.4"
4949
semver = "0.9"

rust-cookbook/src/database/sqlite/initialization.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ Use the `rusqlite` crate to open SQLite databases. See
99

1010
```rust,edition2018,no_run
1111
use rusqlite::{Connection, Result};
12-
use rusqlite::NO_PARAMS;
1312
1413
fn main() -> Result<()> {
1514
let conn = Connection::open("cats.db")?;
@@ -19,15 +18,15 @@ fn main() -> Result<()> {
1918
id integer primary key,
2019
name text not null unique
2120
)",
22-
NO_PARAMS,
21+
[],
2322
)?;
2423
conn.execute(
2524
"create table if not exists cats (
2625
id integer primary key,
2726
name text not null,
2827
color_id integer not null references cat_colors(id)
2928
)",
30-
NO_PARAMS,
29+
[],
3130
)?;
3231
3332
Ok(())
@@ -36,4 +35,4 @@ fn main() -> Result<()> {
3635

3736
[`Connection::open`]: https://docs.rs/rusqlite/*/rusqlite/struct.Connection.html#method.open
3837

39-
[documentation]: https://github.com/jgallagher/rusqlite#user-content-notes-on-building-rusqlite-and-libsqlite3-sys
38+
[documentation]: https://github.com/rusqlite/rusqlite#user-content-notes-on-building-rusqlite-and-libsqlite3-sys

rust-cookbook/src/database/sqlite/insert_select.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ This recipe inserts data into `cat_colors` and `cats` tables using the [`execute
77

88
```rust,no_run
99
10-
use rusqlite::NO_PARAMS;
11-
use rusqlite::{Connection, Result};
10+
use rusqlite::{params, Connection, Result};
1211
use std::collections::HashMap;
1312
1413
#[derive(Debug)]
@@ -26,25 +25,25 @@ fn main() -> Result<()> {
2625
2726
for (color, catnames) in &cat_colors {
2827
conn.execute(
29-
"INSERT INTO cat_colors (name) values (?1)",
30-
&[&color.to_string()],
28+
"INSERT INTO cat_colors (name) VALUES (?1)",
29+
[color],
3130
)?;
32-
let last_id: String = conn.last_insert_rowid().to_string();
31+
let last_id = conn.last_insert_rowid();
3332
3433
for cat in catnames {
3534
conn.execute(
3635
"INSERT INTO cats (name, color_id) values (?1, ?2)",
37-
&[&cat.to_string(), &last_id],
36+
params![cat, last_id],
3837
)?;
3938
}
4039
}
4140
let mut stmt = conn.prepare(
42-
"SELECT c.name, cc.name from cats c
41+
"SELECT c.name, cc.name FROM cats c
4342
INNER JOIN cat_colors cc
4443
ON cc.id = c.color_id;",
4544
)?;
4645
47-
let cats = stmt.query_map(NO_PARAMS, |row| {
46+
let cats = stmt.query_map([], |row| {
4847
Ok(Cat {
4948
name: row.get(0)?,
5049
color: row.get(1)?,

rust-cookbook/src/database/sqlite/transactions.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ a duplicate color is made, the transaction rolls back.
1313

1414

1515
```rust,edition2018,no_run
16-
use rusqlite::{Connection, Result, NO_PARAMS};
16+
use rusqlite::{Connection, Result};
1717
1818
fn main() -> Result<()> {
1919
let mut conn = Connection::open("cats.db")?;
@@ -29,20 +29,20 @@ fn main() -> Result<()> {
2929
fn successful_tx(conn: &mut Connection) -> Result<()> {
3030
let tx = conn.transaction()?;
3131
32-
tx.execute("delete from cat_colors", NO_PARAMS)?;
33-
tx.execute("insert into cat_colors (name) values (?1)", &[&"lavender"])?;
34-
tx.execute("insert into cat_colors (name) values (?1)", &[&"blue"])?;
32+
tx.execute("delete from cat_colors", [])?;
33+
tx.execute("insert into cat_colors (name) values (?1)", ["lavender"])?;
34+
tx.execute("insert into cat_colors (name) values (?1)", ["blue"])?;
3535
3636
tx.commit()
3737
}
3838
3939
fn rolled_back_tx(conn: &mut Connection) -> Result<()> {
4040
let tx = conn.transaction()?;
4141
42-
tx.execute("delete from cat_colors", NO_PARAMS)?;
43-
tx.execute("insert into cat_colors (name) values (?1)", &[&"lavender"])?;
44-
tx.execute("insert into cat_colors (name) values (?1)", &[&"blue"])?;
45-
tx.execute("insert into cat_colors (name) values (?1)", &[&"lavender"])?;
42+
tx.execute("delete from cat_colors", [])?;
43+
tx.execute("insert into cat_colors (name) values (?1)", ["lavender"])?;
44+
tx.execute("insert into cat_colors (name) values (?1)", ["blue"])?;
45+
tx.execute("insert into cat_colors (name) values (?1)", ["lavender"])?;
4646
4747
tx.commit()
4848
}

rust-cookbook/src/web/clients/api/rest-get.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ Queries GitHub [stargazers API v3](https://developer.github.com/v3/activity/star
66
with [`reqwest::get`] to get list of all users who have marked a GitHub project with a star.
77
[`reqwest::Response`] is deserialized with [`Response::json`] into `User` objects implementing [`serde::Deserialize`].
88

9-
[tokio::main] is used to set up the async executor and the process waits for [`reqwet::get`] to complete before
10-
processing the response into User instances.
9+
[tokio::main] is used to set up the async executor and the process waits for [`reqwest::get`] to complete before
10+
processing the response into User instances.
1111

1212
```rust,edition2018,no_run
1313
use serde::Deserialize;

0 commit comments

Comments
 (0)