Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade rusqlite #647

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 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 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 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 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