From 6e3f1dab07b3cd370547454d1ceed05eca612f70 Mon Sep 17 00:00:00 2001 From: Magnus Hoff Date: Fri, 15 Dec 2017 16:43:10 +0100 Subject: [PATCH] Upgrade to Diesel 1.0.0-beta1 --- Cargo.lock | 63 +++++++++++++++++++++++++-------------------------- Cargo.toml | 12 +++++----- src/models.rs | 8 ++++++- src/state.rs | 14 ++++++------ 4 files changed, 51 insertions(+), 46 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6fd63b8..be3ef36 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -159,18 +159,18 @@ dependencies = [ [[package]] name = "diesel" -version = "0.99.0" +version = "1.0.0-beta1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "chrono 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "diesel_derives 0.99.0 (registry+https://github.com/rust-lang/crates.io-index)", + "diesel_derives 1.0.0-beta1 (registry+https://github.com/rust-lang/crates.io-index)", "libsqlite3-sys 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "diesel_derives" -version = "0.99.0" +version = "1.0.0-beta1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", @@ -179,19 +179,19 @@ dependencies = [ [[package]] name = "diesel_infer_schema" -version = "0.99.0" +version = "1.0.0-beta1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "infer_schema_macros 0.99.0 (registry+https://github.com/rust-lang/crates.io-index)", + "infer_schema_macros 1.0.0-beta1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "diesel_migrations" -version = "0.99.0" +version = "1.0.0-beta1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "migrations_internals 0.99.0 (registry+https://github.com/rust-lang/crates.io-index)", - "migrations_macros 0.99.0 (registry+https://github.com/rust-lang/crates.io-index)", + "migrations_internals 1.0.0-beta1 (registry+https://github.com/rust-lang/crates.io-index)", + "migrations_macros 1.0.0-beta1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -321,20 +321,19 @@ dependencies = [ [[package]] name = "infer_schema_internals" -version = "0.99.0" +version = "1.0.0-beta1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "diesel 0.99.0 (registry+https://github.com/rust-lang/crates.io-index)", + "diesel 1.0.0-beta1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "infer_schema_macros" -version = "0.99.0" +version = "1.0.0-beta1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "diesel 0.99.0 (registry+https://github.com/rust-lang/crates.io-index)", "dotenv 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", - "infer_schema_internals 0.99.0 (registry+https://github.com/rust-lang/crates.io-index)", + "infer_schema_internals 1.0.0-beta1 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", "syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -430,18 +429,18 @@ dependencies = [ [[package]] name = "migrations_internals" -version = "0.99.0" +version = "1.0.0-beta1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "diesel 0.99.0 (registry+https://github.com/rust-lang/crates.io-index)", + "diesel 1.0.0-beta1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "migrations_macros" -version = "0.99.0" +version = "1.0.0-beta1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "migrations_internals 0.99.0 (registry+https://github.com/rust-lang/crates.io-index)", + "migrations_internals 1.0.0-beta1 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", "syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -580,10 +579,10 @@ dependencies = [ [[package]] name = "r2d2-diesel" -version = "0.99.0" +version = "1.0.0-beta1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "diesel 0.99.0 (registry+https://github.com/rust-lang/crates.io-index)", + "diesel 1.0.0-beta1 (registry+https://github.com/rust-lang/crates.io-index)", "r2d2 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -657,9 +656,9 @@ dependencies = [ "chrono 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "clap 2.29.0 (registry+https://github.com/rust-lang/crates.io-index)", "codegen 0.1.0", - "diesel 0.99.0 (registry+https://github.com/rust-lang/crates.io-index)", - "diesel_infer_schema 0.99.0 (registry+https://github.com/rust-lang/crates.io-index)", - "diesel_migrations 0.99.0 (registry+https://github.com/rust-lang/crates.io-index)", + "diesel 1.0.0-beta1 (registry+https://github.com/rust-lang/crates.io-index)", + "diesel_infer_schema 1.0.0-beta1 (registry+https://github.com/rust-lang/crates.io-index)", + "diesel_migrations 1.0.0-beta1 (registry+https://github.com/rust-lang/crates.io-index)", "diff 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)", "futures-cpupool 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", @@ -673,7 +672,7 @@ dependencies = [ "pulldown-cmark 0.1.0 (git+https://github.com/maghoff/pulldown-cmark.git)", "quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", "r2d2 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", - "r2d2-diesel 0.99.0 (registry+https://github.com/rust-lang/crates.io-index)", + "r2d2-diesel 1.0.0-beta1 (registry+https://github.com/rust-lang/crates.io-index)", "regex 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.24 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.24 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1048,10 +1047,10 @@ dependencies = [ "checksum chrono 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7c20ebe0b2b08b0aeddba49c609fe7957ba2e33449882cb186a180bc60682fa9" "checksum clap 2.29.0 (registry+https://github.com/rust-lang/crates.io-index)" = "110d43e343eb29f4f51c1db31beb879d546db27998577e5715270a54bcf41d3f" "checksum derive-error-chain 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3c9ca9ade651388daad7c993f005d0d20c4f6fe78c1cdc93e95f161c6f5ede4a" -"checksum diesel 0.99.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0b97bd43f72d4819fac99f24d0030184c64c5ebdee96f94c7a7d4215c50506a7" -"checksum diesel_derives 0.99.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ad228b6fd05c86050b95f56e497a8135073ffce28602e2200e63a21047eb474d" -"checksum diesel_infer_schema 0.99.0 (registry+https://github.com/rust-lang/crates.io-index)" = "87731d00bc7b4585cde88ebd84edfe7c856b6d322e706c205d3909a59f70fc27" -"checksum diesel_migrations 0.99.0 (registry+https://github.com/rust-lang/crates.io-index)" = "745dcfe39e3043c267e46dbe4f2ebbc9917039bdf4d81b108950be61244dfc89" +"checksum diesel 1.0.0-beta1 (registry+https://github.com/rust-lang/crates.io-index)" = "8cefa934d89d472eab3a8f8dd8e6cb78b78bd10f4f2b9a316d3b21f5fc92f94e" +"checksum diesel_derives 1.0.0-beta1 (registry+https://github.com/rust-lang/crates.io-index)" = "d17adb754297df2557f86b7bfaf479e6e5d6433f6c551a01628e5ceed13ba240" +"checksum diesel_infer_schema 1.0.0-beta1 (registry+https://github.com/rust-lang/crates.io-index)" = "5d0a245c96000569e55467fc861529c993c694b33ffb8edf4202d4384f57387c" +"checksum diesel_migrations 1.0.0-beta1 (registry+https://github.com/rust-lang/crates.io-index)" = "4dff84c1913d62b24921e569f200ca74eb568a1dbf601483131af18fc119de04" "checksum diff 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "3c2b69f912779fbb121ceb775d74d51e915af17aaebc38d28a592843a2dd0a3a" "checksum digest 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e5b29bf156f3f4b3c4f610a25ff69370616ae6e0657d416de22645483e72af0a" "checksum dotenv 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d6f0e2bb24d163428d8031d3ebd2d2bd903ad933205a97d0f18c7c1aade380f3" @@ -1068,8 +1067,8 @@ dependencies = [ "checksum httparse 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "af2f2dd97457e8fb1ae7c5a420db346af389926e36f43768b96f101546b04a07" "checksum hyper 0.11.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e0594792d2109069d0caffd176f674d770a84adf024c5bb48e686b1ee5ac7659" "checksum idna 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "014b298351066f1512874135335d62a789ffe78a9974f94b43ed5621951eaf7d" -"checksum infer_schema_internals 0.99.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb18c12a2b6ed321318b84567cad75a6a8409f67691e7a5247bcfa554adf65a4" -"checksum infer_schema_macros 0.99.0 (registry+https://github.com/rust-lang/crates.io-index)" = "31586f241395ae8b56e190fe7acd0b2d41bae13a1391ff3ecdb78e4b63287ff4" +"checksum infer_schema_internals 1.0.0-beta1 (registry+https://github.com/rust-lang/crates.io-index)" = "612223b7e3f3d91f2e37007140001c110611672024ffa20e8d0a2e650e01fb3d" +"checksum infer_schema_macros 1.0.0-beta1 (registry+https://github.com/rust-lang/crates.io-index)" = "ee7447ac27f01f224a6fae696480a803a5c5779971b254d728c3486885198677" "checksum iovec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b6e8b9c2247fcf6c6a1151f1156932be5606c9fd6f55a2d7f9fc1cb29386b2f7" "checksum itertools 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "d3f2be4da1690a039e9ae5fd575f706a63ad5a2120f161b1d653c9da3930dd21" "checksum itoa 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8324a32baf01e2ae060e9de58ed0bc2320c9a2833491ee36cd3b4c414de4db8c" @@ -1084,8 +1083,8 @@ dependencies = [ "checksum maplit 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5ed95049d40b8a1a7691adbabca028ad481f7e6a2921ce4846e1ee168b4e4ca5" "checksum matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "100aabe6b8ff4e4a7e32c1c13523379802df0772b82466207ac25b013f193376" "checksum memchr 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "796fba70e76612589ed2ce7f45282f5af869e0fdd7cc6199fa1aa1f1d591ba9d" -"checksum migrations_internals 0.99.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f9ac1d17f6f161f4d91cb7e5a72cce5b24a60b80f96580a8ac94351c56b8606a" -"checksum migrations_macros 0.99.0 (registry+https://github.com/rust-lang/crates.io-index)" = "dc767420eac6b718cd593aaa09c06a31d4ed228291c8538b274737e28a29939b" +"checksum migrations_internals 1.0.0-beta1 (registry+https://github.com/rust-lang/crates.io-index)" = "b34ea7bb052a19ae3c1efae055ded41b591647fdc6a4c9f4d47673c7a5f72151" +"checksum migrations_macros 1.0.0-beta1 (registry+https://github.com/rust-lang/crates.io-index)" = "9fbf064205a75b00cbc82be9aad299bc09460d6437e9c210667e2be84d5f090c" "checksum mime 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e2e00e17be181010a91dbfefb01660b17311059dc8c7f48b9017677721e732bd" "checksum mio 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)" = "0e8411968194c7b139e9105bc4ae7db0bae232af087147e72f0616ebf5fdb9cb" "checksum miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919" @@ -1102,7 +1101,7 @@ dependencies = [ "checksum pulldown-cmark 0.1.0 (git+https://github.com/maghoff/pulldown-cmark.git)" = "" "checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a" "checksum r2d2 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "59611202bee496c586ecd84e3ed149b4ec75981b0fc10d7f60e878fa23ae16e9" -"checksum r2d2-diesel 0.99.0 (registry+https://github.com/rust-lang/crates.io-index)" = "77aaed149a82720f4b664427f359e1b2a34d8787c1bc3fb1d167b104a1ddd866" +"checksum r2d2-diesel 1.0.0-beta1 (registry+https://github.com/rust-lang/crates.io-index)" = "923c345fa4c2267a07589524b003ec1a17be8dc6150d45a3f69b199efedf7832" "checksum rand 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)" = "6475140dfd8655aeb72e1fd4b7a1cc1c202be65d71669476e392fe62532b9edd" "checksum redox_syscall 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)" = "ab105df655884ede59d45b7070c8a65002d921461ee813a024558ca16030eea0" "checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" diff --git a/Cargo.toml b/Cargo.toml index 191127b..c47c48f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,7 @@ lazy_static = "0.2" maplit = "1" percent-encoding = "1.0.0" r2d2 = "0.8" -r2d2-diesel = "0.99" +r2d2-diesel = "1.0.0-beta1" regex = "0.2" serde = "1.0.0" serde_derive = "1.0.0" @@ -43,17 +43,17 @@ version = "0.8" [dependencies.diesel] default-features = false features = ["sqlite", "chrono"] -version = "0.99" +version = "1.0.0-beta1" [dependencies.diesel_migrations] default-features = false features = ["sqlite"] -version = "0.99" +version = "1.0.0-beta1" [dependencies.diesel_infer_schema] default-features = false features = ["sqlite"] -version = "0.99" +version = "1.0.0-beta1" [dependencies.num] default-features = false @@ -73,11 +73,11 @@ walkdir = "1" [build-dependencies.diesel] default-features = false features = ["sqlite", "chrono"] -version = "0.99" +version = "1.0.0-beta1" [build-dependencies.diesel_migrations] default-features = false features = ["sqlite"] -version = "0.99" +version = "1.0.0-beta1" [workspace] diff --git a/src/models.rs b/src/models.rs index 9a2acf2..4d35b17 100644 --- a/src/models.rs +++ b/src/models.rs @@ -49,10 +49,16 @@ impl ArticleRevisionStub { pub fn link(&self) -> &str { slug_link(&self.slug) } } -#[derive(Debug, Queryable, Serialize)] +use diesel::types::Text; +#[derive(Debug, QueryableByName, Serialize)] pub struct SearchResult { + #[sql_type = "Text"] pub title: String, + + #[sql_type = "Text"] pub snippet: String, + + #[sql_type = "Text"] pub slug: String, } diff --git a/src/state.rs b/src/state.rs index d043176..e148675 100644 --- a/src/state.rs +++ b/src/state.rs @@ -295,7 +295,8 @@ impl<'a> SyncState<'a> { .set(article_revisions::latest.eq(false)) .execute(self.db_connection)?; - diesel::insert(&NewRevision { + diesel::insert_into(article_revisions::table) + .values(&NewRevision { article_id, revision: new_revision, slug: &slug, @@ -304,7 +305,6 @@ impl<'a> SyncState<'a> { author: author.as_ref().map(|x| &**x), latest: true, }) - .into(article_revisions::table) .execute(self.db_connection)?; Ok(UpdateResult::Success(article_revisions::table @@ -343,7 +343,8 @@ impl<'a> SyncState<'a> { let new_revision = 1; - diesel::insert(&NewRevision { + diesel::insert_into(article_revisions::table) + .values(&NewRevision { article_id, revision: new_revision, slug: &slug, @@ -352,7 +353,6 @@ impl<'a> SyncState<'a> { author: author.as_ref().map(|x| &**x), latest: true, }) - .into(article_revisions::table) .execute(self.db_connection)?; Ok(article_revisions::table @@ -364,7 +364,7 @@ impl<'a> SyncState<'a> { } pub fn search_query(&self, query_string: String, limit: i32, offset: i32, snippet_size: i32) -> Result, Error> { - use diesel::expression::sql_literal::sql; + use diesel::sql_query; use diesel::types::{Integer, Text}; fn fts_quote(src: &str) -> String { @@ -385,8 +385,8 @@ impl<'a> SyncState<'a> { }; Ok( - sql::<(Text, Text, Text)>( - "SELECT title, snippet(article_search, 1, '', '', '\u{2026}', ?), slug \ + sql_query( + "SELECT title, snippet(article_search, 1, '', '', '\u{2026}', ?) AS snippet, slug \ FROM article_search \ WHERE article_search MATCH ? \ ORDER BY rank \