Skip to content

Commit b0c3cde

Browse files
Merge #1118
1118: Update to Diesel master r=carols10cents Diesel's current master branch is likely to be reasonably representative of what 1.0 will look like from an API perspective. If there's any other parts of the code that we dislike and want to improve the API for, now is the time to speak up! The test changes are due to some deadlocks that I'm seeing now (which should have always been happening, I suspect some perf characteristic has changed somewhere)
2 parents 64d0e48 + 57ae2d7 commit b0c3cde

28 files changed

+366
-438
lines changed

Cargo.lock

Lines changed: 16 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,7 @@ diesel = { version = "0.16.0", features = ["postgres"] }
8787
[features]
8888
unstable = []
8989
lint = ["clippy"]
90+
91+
[replace]
92+
"diesel:0.16.0" = { git = "https://github.com/diesel-rs/diesel.git" }
93+
"diesel_codegen:0.16.0" = { git = "https://github.com/diesel-rs/diesel.git" }

src/badge.rs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,7 @@ impl Badge {
8181
krate: &Crate,
8282
badges: Option<&'a HashMap<String, HashMap<String, String>>>,
8383
) -> QueryResult<Vec<&'a str>> {
84-
use diesel::{delete, insert};
85-
86-
#[derive(Insertable, Debug)]
87-
#[table_name = "badges"]
88-
struct NewBadge<'a> {
89-
crate_id: i32,
90-
badge_type: &'a str,
91-
attributes: serde_json::Value,
92-
}
84+
use diesel::{delete, insert_into};
9385

9486
let mut invalid_badges = vec![];
9587
let mut new_badges = vec![];
@@ -100,20 +92,22 @@ impl Badge {
10092

10193
let json = json!({"badge_type": k, "attributes": attributes_json});
10294
if serde_json::from_value::<Badge>(json).is_ok() {
103-
new_badges.push(NewBadge {
104-
crate_id: krate.id,
105-
badge_type: &**k,
106-
attributes: attributes_json,
107-
});
95+
new_badges.push((
96+
badges::crate_id.eq(krate.id),
97+
badges::badge_type.eq(k),
98+
badges::attributes.eq(attributes_json),
99+
));
108100
} else {
109101
invalid_badges.push(&**k);
110102
}
111103
}
112104
}
113105

114106
conn.transaction(|| {
115-
delete(badges::table.filter(badges::crate_id.eq(krate.id))).execute(conn)?;
116-
insert(&new_badges).into(badges::table).execute(conn)?;
107+
delete(badges::table)
108+
.filter(badges::crate_id.eq(krate.id))
109+
.execute(conn)?;
110+
insert_into(badges::table).values(&new_badges).execute(conn)?;
117111
Ok(invalid_badges)
118112
})
119113
}

src/bin/populate.rs

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,9 @@
77
#![deny(warnings)]
88

99
extern crate cargo_registry;
10-
extern crate chrono;
11-
#[macro_use]
1210
extern crate diesel;
13-
#[macro_use]
14-
extern crate diesel_codegen;
1511
extern crate rand;
1612

17-
use chrono::{Duration, NaiveDate, Utc};
1813
use diesel::prelude::*;
1914
use rand::{Rng, StdRng};
2015
use std::env;
@@ -27,6 +22,8 @@ fn main() {
2722
}
2823

2924
fn update(conn: &PgConnection) -> QueryResult<()> {
25+
use diesel::dsl::*;
26+
3027
let ids = env::args()
3128
.skip(1)
3229
.filter_map(|arg| arg.parse::<i32>().ok());
@@ -35,26 +32,16 @@ fn update(conn: &PgConnection) -> QueryResult<()> {
3532
let mut dls = rng.gen_range(5000i32, 10000);
3633

3734
for day in 0..90 {
38-
let moment = Utc::now().date().naive_utc() + Duration::days(-day);
3935
dls += rng.gen_range(-100, 100);
4036

41-
let version_download = VersionDownload {
42-
version_id: id,
43-
downloads: dls,
44-
date: moment,
45-
};
46-
diesel::insert(&version_download)
47-
.into(version_downloads::table)
37+
diesel::insert_into(version_downloads::table)
38+
.values((
39+
version_downloads::version_id.eq(id),
40+
version_downloads::downloads.eq(dls),
41+
version_downloads::date.eq(date(now - day.days())),
42+
))
4843
.execute(conn)?;
4944
}
5045
}
5146
Ok(())
5247
}
53-
54-
#[derive(Insertable)]
55-
#[table_name = "version_downloads"]
56-
struct VersionDownload {
57-
version_id: i32,
58-
downloads: i32,
59-
date: NaiveDate,
60-
}

src/bin/render-readmes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ extern crate url;
2222
use curl::easy::{Easy, List};
2323
use chrono::{TimeZone, Utc};
2424
use diesel::prelude::*;
25-
use diesel::expression::any;
25+
use diesel::dsl::any;
2626
use docopt::Docopt;
2727
use flate2::read::GzDecoder;
2828
use itertools::Itertools;

0 commit comments

Comments
 (0)