Skip to content

Update to Diesel 1.1 #1234

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

Merged
merged 2 commits into from
Jan 18, 2018
Merged
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
49 changes: 19 additions & 30 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 3 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ semver = "0.5"
url = "1.2.1"
tar = "0.4.13"

r2d2 = "0.8.0"
openssl = "0.9.14"
curl = "0.4"
oauth2 = "0.3"
Expand All @@ -46,8 +45,7 @@ htmlescape = "0.3.1"
license-exprs = "^1.3"
dotenv = "0.10.0"
toml = "0.4"
diesel = { version = "1.0.0", features = ["postgres", "serde_json", "chrono"] }
r2d2-diesel = "1.0.0"
diesel = { version = "1.1.0", features = ["postgres", "serde_json", "chrono", "r2d2"] }
diesel_full_text_search = "1.0.0"
serde_json = "1.0.0"
serde_derive = "1.0.0"
Expand Down Expand Up @@ -83,8 +81,8 @@ tokio-service = "0.1"

[build-dependencies]
dotenv = "0.10"
diesel = { version = "1.0.0", features = ["postgres"] }
diesel_migrations = { version = "1.0.0", features = ["postgres"] }
diesel = { version = "1.1.0", features = ["postgres"] }
diesel_migrations = { version = "1.1.0", features = ["postgres"] }

# Remove once cookie depends on ring >= 0.13.0
[patch.crates-io]
Expand Down
2 changes: 1 addition & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use std::sync::{Arc, Mutex};

use conduit::{Request, Response};
use conduit_middleware::Middleware;
use diesel::r2d2;
use git2;
use oauth2;
use r2d2;
use curl::easy::Easy;
use scheduled_thread_pool::ScheduledThreadPool;

Expand Down
2 changes: 1 addition & 1 deletion src/category.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ impl Category {
}

pub fn subcategories(&self, conn: &PgConnection) -> QueryResult<Vec<Category>> {
use diesel::types::Text;
use diesel::sql_types::Text;

sql_query(
"SELECT c.id, c.category, c.slug, c.description, \
Expand Down
3 changes: 1 addition & 2 deletions src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ use std::env;

use conduit::Request;
use diesel::prelude::{ConnectionResult, PgConnection};
use r2d2;
use r2d2_diesel::ConnectionManager;
use diesel::r2d2::{self, ConnectionManager};
use url::Url;

use app::RequestApp;
Expand Down
24 changes: 8 additions & 16 deletions src/dependency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use diesel::prelude::*;
use diesel::query_source::QueryableByName;
use diesel::row::NamedRow;
use semver;
use std::error::Error;

use git;
use krate::Crate;
Expand All @@ -30,9 +29,9 @@ pub struct Dependency {
#[derive(Debug, QueryableByName)]
pub struct ReverseDependency {
#[diesel(embed)] dependency: Dependency,
#[sql_type = "::diesel::types::Integer"] crate_downloads: i32,
#[sql_type = "::diesel::types::Text"]
#[column_name(crate_name)]
#[sql_type = "::diesel::sql_types::Integer"] crate_downloads: i32,
#[sql_type = "::diesel::sql_types::Text"]
#[column_name = "crate_name"]
name: String,
}

Expand All @@ -50,7 +49,7 @@ pub struct EncodableDependency {
pub downloads: i32,
}

#[derive(Copy, Clone, Serialize, Deserialize, Debug)]
#[derive(Copy, Clone, Serialize, Deserialize, Debug, FromSqlRow)]
#[serde(rename_all = "lowercase")]
#[repr(u32)]
pub enum Kind {
Expand Down Expand Up @@ -141,18 +140,11 @@ pub fn add_dependencies(
Ok(git_deps)
}

use diesel::types::{FromSql, FromSqlRow, Integer};
use diesel::row::Row;

// FIXME: Replace with `#[derive(FromSqlRow)]` in Diesel 1.1
impl FromSqlRow<Integer, Pg> for Kind {
fn build_from_row<R: Row<Pg>>(row: &mut R) -> Result<Self, Box<Error + Send + Sync>> {
Self::from_sql(row.take())
}
}
use diesel::deserialize::{self, FromSql};
use diesel::sql_types::Integer;

impl FromSql<Integer, Pg> for Kind {
fn from_sql(bytes: Option<&[u8]>) -> Result<Self, Box<Error + Send + Sync>> {
fn from_sql(bytes: Option<&[u8]>) -> deserialize::Result<Self> {
match <i32 as FromSql<Integer, Pg>>::from_sql(bytes)? {
0 => Ok(Kind::Normal),
1 => Ok(Kind::Build),
Expand Down Expand Up @@ -191,7 +183,7 @@ impl Queryable<dependencies::SqlType, Pg> for Dependency {
}

impl QueryableByName<Pg> for Dependency {
fn build<R: NamedRow<Pg>>(row: &R) -> Result<Self, Box<Error + Send + Sync>> {
fn build<R: NamedRow<Pg>>(row: &R) -> deserialize::Result<Self> {
use schema::dependencies::*;
use diesel::dsl::SqlTypeOf;

Expand Down
2 changes: 1 addition & 1 deletion src/krate/downloads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use super::{to_char, Crate};
/// Handles the `GET /crates/:crate_id/downloads` route.
pub fn downloads(req: &mut Request) -> CargoResult<Response> {
use diesel::dsl::*;
use diesel::types::BigInt;
use diesel::sql_types::BigInt;

let crate_name = &req.params()["crate_id"];
let conn = req.db_conn()?;
Expand Down
2 changes: 1 addition & 1 deletion src/krate/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use super::{Crate, CrateDownload, EncodableCrate, ALL_COLUMNS};
/// Handles the `GET /summary` route.
pub fn summary(req: &mut Request) -> CargoResult<Response> {
use diesel::dsl::*;
use diesel::types::{BigInt, Nullable};
use diesel::sql_types::{BigInt, Nullable};
use schema::crates::dsl::*;

let conn = req.db_conn()?;
Expand Down
4 changes: 2 additions & 2 deletions src/krate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ impl Crate {
limit: i64,
) -> QueryResult<(Vec<ReverseDependency>, i64)> {
use diesel::sql_query;
use diesel::types::{BigInt, Integer};
use diesel::sql_types::{BigInt, Integer};

let rows = sql_query(include_str!("krate_reverse_dependencies.sql"))
.bind::<Integer, _>(self.id)
Expand All @@ -551,7 +551,7 @@ pub struct Follow {
crate_id: i32,
}

use diesel::types::{Date, Text};
use diesel::sql_types::{Date, Text};
sql_function!(canon_crate_name, canon_crate_name_t, (x: Text) -> Text);
sql_function!(to_char, to_char_t, (a: Date, b: Text) -> Text);

Expand Down
2 changes: 1 addition & 1 deletion src/krate/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use super::{canon_crate_name, Crate, EncodableCrate, ALL_COLUMNS};
/// for them.
pub fn search(req: &mut Request) -> CargoResult<Response> {
use diesel::dsl::*;
use diesel::types::{BigInt, Bool, Nullable};
use diesel::sql_types::{BigInt, Bool, Nullable};

let conn = req.db_conn()?;
let (offset, limit) = req.pagination(10, 100)?;
Expand Down
4 changes: 1 addition & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ extern crate license_exprs;
extern crate log;
extern crate oauth2;
extern crate openssl;
extern crate r2d2;
extern crate r2d2_diesel;
extern crate rand;
extern crate s3;
extern crate scheduled_thread_pool;
Expand Down Expand Up @@ -329,4 +327,4 @@ pub fn env(s: &str) -> String {
::std::env::var(s).unwrap_or_else(|_| panic!("must have `{}` defined", s))
}

sql_function!(lower, lower_t, (x: ::diesel::types::Text) -> ::diesel::types::Text);
sql_function!(lower, lower_t, (x: ::diesel::sql_types::Text) -> ::diesel::sql_types::Text);
2 changes: 1 addition & 1 deletion src/pagination.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use diesel::prelude::*;
use diesel::query_builder::*;
use diesel::types::BigInt;
use diesel::sql_types::BigInt;
use diesel::pg::Pg;

pub struct Paginated<T> {
Expand Down
2 changes: 1 addition & 1 deletion src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ table! {

table! {
use diesel_full_text_search::{TsVector as Tsvector};
use diesel::types::*;
use diesel::sql_types::*;

/// Representation of the `crates` table.
///
Expand Down
6 changes: 3 additions & 3 deletions src/tests/schema_details.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use diesel::prelude::*;
use diesel::types::Text;
use diesel::sql_types::Text;

#[test]
fn all_columns_called_crate_id_have_a_cascading_foreign_key() {
Expand Down Expand Up @@ -44,15 +44,15 @@ fn all_columns_called_version_id_have_a_cascading_foreign_key() {
#[derive(QueryableByName)]
struct FkConstraint {
#[sql_type = "Text"]
#[column_name(conname)]
#[column_name = "conname"]
name: String,
#[sql_type = "Text"] definition: String,
}

#[derive(QueryableByName)]
struct TableNameAndConstraint {
#[sql_type = "Text"]
#[column_name(relname)]
#[column_name = "relname"]
table_name: String,
#[diesel(embed)] constraint: Option<FkConstraint>,
}
Expand Down
9 changes: 3 additions & 6 deletions src/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,12 @@ impl Serialize for CrateVersionReq {
}

use diesel::pg::Pg;
use diesel::types::{IsNull, Text, ToSql, ToSqlOutput};
use std::error::Error;
use diesel::serialize::{self, Output, ToSql};
use diesel::sql_types::Text;
use std::io::Write;

impl ToSql<Text, Pg> for Feature {
fn to_sql<W: Write>(
&self,
out: &mut ToSqlOutput<W, Pg>,
) -> Result<IsNull, Box<Error + Send + Sync>> {
fn to_sql<W: Write>(&self, out: &mut Output<W, Pg>) -> serialize::Result {
ToSql::<Text, Pg>::to_sql(&**self, out)
}
}
2 changes: 1 addition & 1 deletion src/user/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl<'a> NewUser<'a> {
pub fn create_or_update(&self, conn: &PgConnection) -> QueryResult<User> {
use diesel::insert_into;
use diesel::dsl::sql;
use diesel::types::Integer;
use diesel::sql_types::Integer;
use diesel::pg::upsert::excluded;
use diesel::NotFound;
use schema::users::dsl::*;
Expand Down
2 changes: 1 addition & 1 deletion src/with_count.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[derive(QueryableByName)]
pub struct WithCount<T> {
#[sql_type = "::diesel::types::BigInt"] total: i64,
#[sql_type = "::diesel::sql_types::BigInt"] total: i64,
#[diesel(embed)] record: T,
}

Expand Down