Skip to content

Commit c0a948c

Browse files
committed
Update deps, primarily postgres
1 parent d226657 commit c0a948c

14 files changed

+313
-236
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ git2 = "0.2"
4747
flate2 = "0.2"
4848
semver = "0.1.3"
4949
url = "0.2.0"
50-
postgres = { version = "0.9", features = ["time"] }
50+
postgres = { version = "0.10", features = ["time"] }
5151
r2d2 = "0.6.0"
5252
r2d2_postgres = "0.9"
5353
openssl = "0.6"

src/db.rs

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::mem;
44
use std::sync::Arc;
55

66
use pg;
7-
use pg::types::ToSql;
7+
use pg::GenericConnection;
88
use r2d2;
99
use r2d2_postgres;
1010
use r2d2_postgres::PostgresConnectionManager as PCM;
@@ -59,7 +59,7 @@ impl Transaction {
5959
Ok(&**self.slot.borrow().unwrap())
6060
}
6161

62-
fn tx<'a>(&'a self) -> CargoResult<&'a (Connection + 'a)> {
62+
fn tx<'a>(&'a self) -> CargoResult<&'a (GenericConnection + 'a)> {
6363
// Similar to above, the transaction for this request is actually tied
6464
// to the connection in the request itself, not 'static. We transmute it
6565
// to static as its paired with the inner connection to achieve the
@@ -116,7 +116,7 @@ pub trait RequestTransaction {
116116
///
117117
/// The transaction will live for the duration of the request, and it will
118118
/// only be set to commit() if a successful response code of 200 is seen.
119-
fn tx(&self) -> CargoResult<&Connection>;
119+
fn tx(&self) -> CargoResult<&GenericConnection>;
120120

121121
/// Flag the transaction to not be committed
122122
fn rollback(&self);
@@ -131,7 +131,7 @@ impl<'a> RequestTransaction for Request + 'a {
131131
.conn()
132132
}
133133

134-
fn tx(&self) -> CargoResult<&Connection> {
134+
fn tx(&self) -> CargoResult<&GenericConnection> {
135135
self.extensions().find::<Transaction>()
136136
.expect("Transaction not present in request")
137137
.tx()
@@ -149,28 +149,3 @@ impl<'a> RequestTransaction for Request + 'a {
149149
.commit()
150150
}
151151
}
152-
153-
pub trait Connection {
154-
fn prepare(&self, query: &str) -> pg::Result<pg::Statement>;
155-
fn execute(&self, query: &str, params: &[&ToSql]) -> pg::Result<u64>;
156-
}
157-
158-
impl Connection for pg::Connection {
159-
fn prepare(&self, query: &str) -> pg::Result<pg::Statement> {
160-
self.prepare(query)
161-
}
162-
fn execute(&self, query: &str, params: &[&ToSql]) -> pg::Result<u64> {
163-
self.execute(query, params)
164-
}
165-
}
166-
167-
impl<'a> Connection for pg::Transaction<'a> {
168-
fn prepare(&self, query: &str) -> pg::Result<pg::Statement> {
169-
trace!("prepare: {}", query);
170-
self.prepare(query)
171-
}
172-
fn execute(&self, query: &str, params: &[&ToSql]) -> pg::Result<u64> {
173-
trace!("execute: {}", query);
174-
self.execute(query, params)
175-
}
176-
}

src/dependency.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
use pg::GenericConnection;
2+
use pg::rows::Row;
13
use semver;
24

3-
use pg::rows::Row;
45
use Model;
56
use git;
6-
use db::Connection;
77
use util::{CargoResult};
88

99
pub struct Dependency {
@@ -43,7 +43,7 @@ pub enum Kind {
4343
}
4444

4545
impl Dependency {
46-
pub fn insert(conn: &Connection, version_id: i32, crate_id: i32,
46+
pub fn insert(conn: &GenericConnection, version_id: i32, crate_id: i32,
4747
req: &semver::VersionReq, kind: Kind,
4848
optional: bool, default_features: bool,
4949
features: &[String], target: &Option<String>)

src/download.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
use pg::GenericConnection;
2+
use pg::rows::Row;
13
use time::Timespec;
24

3-
use pg::rows::Row;
45
use Model;
5-
use db::Connection;
66
use util::CargoResult;
77

88
pub struct VersionDownload {
@@ -22,7 +22,8 @@ pub struct EncodableVersionDownload {
2222
}
2323

2424
impl VersionDownload {
25-
pub fn find(conn: &Connection, id: i32) -> CargoResult<VersionDownload> {
25+
pub fn find(conn: &GenericConnection,
26+
id: i32) -> CargoResult<VersionDownload> {
2627
Model::find(conn, id)
2728
}
2829

@@ -60,7 +61,7 @@ pub struct CrateDownload {
6061
}
6162

6263
impl CrateDownload {
63-
pub fn find(conn: &Connection, id: i32) -> CargoResult<CrateDownload> {
64+
pub fn find(conn: &GenericConnection, id: i32) -> CargoResult<CrateDownload> {
6465
Model::find(conn, id)
6566
}
6667
}

src/keyword.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ use time::Timespec;
44

55
use conduit::{Request, Response};
66
use conduit_router::RequestParams;
7+
use pg::GenericConnection;
78
use pg::rows::Row;
89
use pg::types::Slice;
910

1011
use {Model, Crate};
11-
use db::{Connection, RequestTransaction};
12+
use db::RequestTransaction;
1213
use util::{RequestUtils, CargoResult, ChainError, internal};
1314
use util::errors::NotFound;
1415

@@ -29,19 +30,19 @@ pub struct EncodableKeyword {
2930
}
3031

3132
impl Keyword {
32-
pub fn find(conn: &Connection, id: i32) -> CargoResult<Keyword> {
33+
pub fn find(conn: &GenericConnection, id: i32) -> CargoResult<Keyword> {
3334
Model::find(conn, id)
3435
}
3536

36-
pub fn find_by_keyword(conn: &Connection, name: &str)
37+
pub fn find_by_keyword(conn: &GenericConnection, name: &str)
3738
-> CargoResult<Option<Keyword>> {
3839
let stmt = try!(conn.prepare("SELECT * FROM keywords \
3940
WHERE keyword = $1"));
4041
let rows = try!(stmt.query(&[&name]));
4142
Ok(rows.iter().next().map(|r| Model::from_row(&r)))
4243
}
4344

44-
pub fn find_or_insert(conn: &Connection, name: &str)
45+
pub fn find_or_insert(conn: &GenericConnection, name: &str)
4546
-> CargoResult<Keyword> {
4647
// TODO: racy (the select then insert is not atomic)
4748
let stmt = try!(conn.prepare("SELECT * FROM keywords
@@ -78,7 +79,8 @@ impl Keyword {
7879
}
7980
}
8081

81-
pub fn update_crate(conn: &Connection, krate: &Crate,
82+
pub fn update_crate(conn: &GenericConnection,
83+
krate: &Crate,
8284
keywords: &[String]) -> CargoResult<()> {
8385
let old_kws = try!(krate.keywords(conn));
8486
let old_kws = old_kws.iter().map(|kw| {

src/krate.rs

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use conduit::{Request, Response};
1111
use conduit_router::RequestParams;
1212
use curl::http;
1313
use license_exprs;
14+
use pg::GenericConnection;
1415
use pg::rows::Row;
1516
use pg::types::{ToSql, Slice};
1617
use pg;
@@ -22,7 +23,7 @@ use url::{self, Url};
2223

2324
use {Model, User, Keyword, Version};
2425
use app::{App, RequestApp};
25-
use db::{Connection, RequestTransaction};
26+
use db::RequestTransaction;
2627
use dependency::{Dependency, EncodableDependency};
2728
use download::{VersionDownload, EncodableVersionDownload};
2829
use git;
@@ -80,11 +81,12 @@ pub struct CrateLinks {
8081
}
8182

8283
impl Crate {
83-
pub fn find(conn: &Connection, id: i32) -> CargoResult<Crate> {
84+
pub fn find(conn: &GenericConnection, id: i32) -> CargoResult<Crate> {
8485
Model::find(conn, id)
8586
}
8687

87-
pub fn find_by_name(conn: &Connection, name: &str) -> CargoResult<Crate> {
88+
pub fn find_by_name(conn: &GenericConnection,
89+
name: &str) -> CargoResult<Crate> {
8890
let stmt = try!(conn.prepare("SELECT * FROM crates \
8991
WHERE canon_crate_name(name) =
9092
canon_crate_name($1) LIMIT 1"));
@@ -93,7 +95,8 @@ impl Crate {
9395
Ok(Model::from_row(&row))
9496
}
9597

96-
pub fn find_or_insert(conn: &Connection, name: &str,
98+
pub fn find_or_insert(conn: &GenericConnection,
99+
name: &str,
97100
user_id: i32,
98101
description: &Option<String>,
99102
homepage: &Option<String>,
@@ -271,7 +274,7 @@ impl Crate {
271274
}
272275
}
273276

274-
pub fn versions(&self, conn: &Connection) -> CargoResult<Vec<Version>> {
277+
pub fn versions(&self, conn: &GenericConnection) -> CargoResult<Vec<Version>> {
275278
let stmt = try!(conn.prepare("SELECT * FROM versions \
276279
WHERE crate_id = $1"));
277280
let rows = try!(stmt.query(&[&self.id]));
@@ -282,7 +285,7 @@ impl Crate {
282285
Ok(ret)
283286
}
284287

285-
pub fn owners(&self, conn: &Connection) -> CargoResult<Vec<Owner>> {
288+
pub fn owners(&self, conn: &GenericConnection) -> CargoResult<Vec<Owner>> {
286289
let stmt = try!(conn.prepare("SELECT * FROM users
287290
INNER JOIN crate_owners
288291
ON crate_owners.owner_id = users.id
@@ -305,7 +308,7 @@ impl Crate {
305308
Ok(owners)
306309
}
307310

308-
pub fn owner_add(&self, app: &App, conn: &Connection, req_user: &User,
311+
pub fn owner_add(&self, app: &App, conn: &GenericConnection, req_user: &User,
309312
login: &str) -> CargoResult<()> {
310313
let owner = match Owner::find_by_login(conn, login) {
311314
Ok(owner @ Owner::User(_)) => { owner }
@@ -343,7 +346,9 @@ impl Crate {
343346
Ok(())
344347
}
345348

346-
pub fn owner_remove(&self, conn: &Connection, _req_user: &User,
349+
pub fn owner_remove(&self,
350+
conn: &GenericConnection,
351+
_req_user: &User,
347352
login: &str) -> CargoResult<()> {
348353
let owner = try!(Owner::find_by_login(conn, login).map_err(|_| {
349354
human(format!("could not find owner with login `{}`", login))
@@ -360,7 +365,9 @@ impl Crate {
360365
format!("/crates/{}/{}-{}.crate", self.name, self.name, version)
361366
}
362367

363-
pub fn add_version(&mut self, conn: &Connection, ver: &semver::Version,
368+
pub fn add_version(&mut self,
369+
conn: &GenericConnection,
370+
ver: &semver::Version,
364371
features: &HashMap<String, Vec<String>>,
365372
authors: &[String])
366373
-> CargoResult<Version> {
@@ -383,7 +390,7 @@ impl Crate {
383390
Version::insert(conn, self.id, ver, features, authors)
384391
}
385392

386-
pub fn keywords(&self, conn: &Connection) -> CargoResult<Vec<Keyword>> {
393+
pub fn keywords(&self, conn: &GenericConnection) -> CargoResult<Vec<Keyword>> {
387394
let stmt = try!(conn.prepare("SELECT keywords.* FROM keywords
388395
LEFT JOIN crates_keywords
389396
ON keywords.id = crates_keywords.keyword_id
@@ -393,7 +400,10 @@ impl Crate {
393400
}
394401

395402
/// Returns (dependency, dependent crate name)
396-
pub fn reverse_dependencies(&self, conn: &Connection, offset: i64, limit: i64)
403+
pub fn reverse_dependencies(&self,
404+
conn: &GenericConnection,
405+
offset: i64,
406+
limit: i64)
397407
-> CargoResult<(Vec<(Dependency, String)>, i64)> {
398408
let select_sql = "
399409
FROM dependencies
@@ -589,7 +599,7 @@ pub fn summary(req: &mut Request) -> CargoResult<Response> {
589599
rows.iter().next().unwrap().get("total_downloads")
590600
};
591601

592-
let to_crates = |stmt: pg::Statement| -> CargoResult<Vec<EncodableCrate>> {
602+
let to_crates = |stmt: pg::stmt::Statement| -> CargoResult<Vec<_>> {
593603
let rows = try!(stmt.query(&[]));
594604
Ok(rows.iter().map(|r| {
595605
let krate: Crate = Model::from_row(&r);

src/migrate/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ name = "migrate"
88
path = "lib.rs"
99

1010
[dependencies]
11-
postgres = "0.9"
11+
postgres = "0.10"

src/model.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
use pg::rows::Row;
2-
use db::Connection;
2+
use pg::GenericConnection;
3+
34
use util::{CargoResult, ChainError};
45
use util::errors::NotFound;
56

67
pub trait Model: Sized {
78
fn from_row(row: &Row) -> Self;
89
fn table_name(_: Option<Self>) -> &'static str;
910

10-
fn find(conn: &Connection, id: i32) -> CargoResult<Self> {
11+
fn find(conn: &GenericConnection, id: i32) -> CargoResult<Self> {
1112
let sql = format!("SELECT * FROM {} WHERE id = $1",
1213
Model::table_name(None::<Self>));
1314
let stmt = try!(conn.prepare(&sql));

src/owner.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
use pg::GenericConnection;
2+
use pg::rows::Row;
3+
14
use {Model, User};
25
use util::{RequestUtils, CargoResult, ChainError, human};
3-
use db::Connection;
4-
use pg::rows::Row;
56
use util::errors::NotFound;
67
use http;
78
use app::App;
@@ -58,7 +59,8 @@ pub enum Rights {
5859

5960
impl Team {
6061
/// Just gets the Team from the database by name.
61-
pub fn find_by_login(conn: &Connection, login: &str) -> CargoResult<Self> {
62+
pub fn find_by_login(conn: &GenericConnection,
63+
login: &str) -> CargoResult<Self> {
6264
let stmt = try!(conn.prepare("SELECT * FROM teams
6365
WHERE login = $1"));
6466
let rows = try!(stmt.query(&[&login]));
@@ -69,8 +71,11 @@ impl Team {
6971
}
7072

7173
/// Tries to create the Team in the DB (assumes a `:` has already been found).
72-
pub fn create(app: &App, conn: &Connection, login: &str, req_user: &User)
73-
-> CargoResult<Self> {
74+
pub fn create(app: &App,
75+
conn: &GenericConnection,
76+
login: &str,
77+
req_user: &User)
78+
-> CargoResult<Self> {
7479
// must look like system:xxxxxxx
7580
let mut chunks = login.split(":");
7681
match chunks.next().unwrap() {
@@ -94,7 +99,7 @@ impl Team {
9499
/// Tries to create a Github Team from scratch. Assumes `org` and `team` are
95100
/// correctly parsed out of the full `name`. `name` is passed as a
96101
/// convenience to avoid rebuilding it.
97-
pub fn create_github_team(app: &App, conn: &Connection, login: &str,
102+
pub fn create_github_team(app: &App, conn: &GenericConnection, login: &str,
98103
org_name: &str, team_name: &str, req_user: &User)
99104
-> CargoResult<Self> {
100105
// GET orgs/:org/teams
@@ -150,7 +155,7 @@ impl Team {
150155
Team::insert(conn, login, team.id, team.name, org.avatar_url)
151156
}
152157

153-
pub fn insert(conn: &Connection,
158+
pub fn insert(conn: &GenericConnection,
154159
login: &str,
155160
github_id: i32,
156161
name: Option<String>,
@@ -219,7 +224,8 @@ impl Owner {
219224
/// Finds the owner by name, failing out if it doesn't exist.
220225
/// May be a user's GH login, or a full team name. This is case
221226
/// sensitive.
222-
pub fn find_by_login(conn: &Connection, name: &str) -> CargoResult<Owner> {
227+
pub fn find_by_login(conn: &GenericConnection,
228+
name: &str) -> CargoResult<Owner> {
223229
let owner = if name.contains(":") {
224230
Owner::Team(try!(Team::find_by_login(conn, name).map_err(|_|
225231
human(format!("could not find team with name {}", name))

0 commit comments

Comments
 (0)