Skip to content

Commit

Permalink
update original
Browse files Browse the repository at this point in the history
  • Loading branch information
funkill committed Nov 27, 2024
1 parent 39d973c commit 2ecc9f8
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 23 deletions.
2 changes: 1 addition & 1 deletion rust-cookbook/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ rayon = "1.0"
regex = "1.0"
reqwest = { version = "0.10", features = ["blocking", "json", "stream"] }
ring = "0.16.11"
rusqlite = { version = "0.22", features = ["chrono"] }
rusqlite = { version = "0.25", features = ["chrono"] }
same-file = "1.0"
select = "0.4"
semver = "0.9"
Expand Down
7 changes: 3 additions & 4 deletions rust-cookbook/src/database/sqlite/initialization.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ Use the `rusqlite` crate to open SQLite databases. See

```rust,edition2018,no_run
use rusqlite::{Connection, Result};
use rusqlite::NO_PARAMS;
fn main() -> Result<()> {
let conn = Connection::open("cats.db")?;
Expand All @@ -19,15 +18,15 @@ fn main() -> Result<()> {
id integer primary key,
name text not null unique
)",
NO_PARAMS,
[],
)?;
conn.execute(
"create table if not exists cats (
id integer primary key,
name text not null,
color_id integer not null references cat_colors(id)
)",
NO_PARAMS,
[],
)?;
Ok(())
Expand All @@ -36,4 +35,4 @@ fn main() -> Result<()> {

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

[documentation]: https://github.com/jgallagher/rusqlite#user-content-notes-on-building-rusqlite-and-libsqlite3-sys
[documentation]: https://github.com/rusqlite/rusqlite#user-content-notes-on-building-rusqlite-and-libsqlite3-sys
15 changes: 7 additions & 8 deletions rust-cookbook/src/database/sqlite/insert_select.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ This recipe inserts data into `cat_colors` and `cats` tables using the [`execute

```rust,no_run
use rusqlite::NO_PARAMS;
use rusqlite::{Connection, Result};
use rusqlite::{params, Connection, Result};
use std::collections::HashMap;
#[derive(Debug)]
Expand All @@ -26,25 +25,25 @@ fn main() -> Result<()> {
for (color, catnames) in &cat_colors {
conn.execute(
"INSERT INTO cat_colors (name) values (?1)",
&[&color.to_string()],
"INSERT INTO cat_colors (name) VALUES (?1)",
[color],
)?;
let last_id: String = conn.last_insert_rowid().to_string();
let last_id = conn.last_insert_rowid();
for cat in catnames {
conn.execute(
"INSERT INTO cats (name, color_id) values (?1, ?2)",
&[&cat.to_string(), &last_id],
params![cat, last_id],
)?;
}
}
let mut stmt = conn.prepare(
"SELECT c.name, cc.name from cats c
"SELECT c.name, cc.name FROM cats c
INNER JOIN cat_colors cc
ON cc.id = c.color_id;",
)?;
let cats = stmt.query_map(NO_PARAMS, |row| {
let cats = stmt.query_map([], |row| {
Ok(Cat {
name: row.get(0)?,
color: row.get(1)?,
Expand Down
16 changes: 8 additions & 8 deletions rust-cookbook/src/database/sqlite/transactions.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ a duplicate color is made, the transaction rolls back.


```rust,edition2018,no_run
use rusqlite::{Connection, Result, NO_PARAMS};
use rusqlite::{Connection, Result};
fn main() -> Result<()> {
let mut conn = Connection::open("cats.db")?;
Expand All @@ -29,20 +29,20 @@ fn main() -> Result<()> {
fn successful_tx(conn: &mut Connection) -> Result<()> {
let tx = conn.transaction()?;
tx.execute("delete from cat_colors", NO_PARAMS)?;
tx.execute("insert into cat_colors (name) values (?1)", &[&"lavender"])?;
tx.execute("insert into cat_colors (name) values (?1)", &[&"blue"])?;
tx.execute("delete from cat_colors", [])?;
tx.execute("insert into cat_colors (name) values (?1)", ["lavender"])?;
tx.execute("insert into cat_colors (name) values (?1)", ["blue"])?;
tx.commit()
}
fn rolled_back_tx(conn: &mut Connection) -> Result<()> {
let tx = conn.transaction()?;
tx.execute("delete from cat_colors", NO_PARAMS)?;
tx.execute("insert into cat_colors (name) values (?1)", &[&"lavender"])?;
tx.execute("insert into cat_colors (name) values (?1)", &[&"blue"])?;
tx.execute("insert into cat_colors (name) values (?1)", &[&"lavender"])?;
tx.execute("delete from cat_colors", [])?;
tx.execute("insert into cat_colors (name) values (?1)", ["lavender"])?;
tx.execute("insert into cat_colors (name) values (?1)", ["blue"])?;
tx.execute("insert into cat_colors (name) values (?1)", ["lavender"])?;
tx.commit()
}
Expand Down
4 changes: 2 additions & 2 deletions rust-cookbook/src/web/clients/api/rest-get.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ Queries GitHub [stargazers API v3](https://developer.github.com/v3/activity/star
with [`reqwest::get`] to get list of all users who have marked a GitHub project with a star.
[`reqwest::Response`] is deserialized with [`Response::json`] into `User` objects implementing [`serde::Deserialize`].

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

```rust,edition2018,no_run
use serde::Deserialize;
Expand Down

0 comments on commit 2ecc9f8

Please sign in to comment.