Created
March 27, 2019 16:36
-
-
Save icefoxen/287da263a333213975762fe6472b1cfc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use diesel::pg; | |
use diesel::query_builder::BoxedSelectStatement; | |
use diesel::query_source::QuerySource; | |
use diesel::sql_types as st; | |
fn heckin_abstraction_with_diesel<QS>( | |
conn: &PgConn, | |
select: BoxedSelectStatement<(st::Text, st::BigInt), QS, pg::Pg>, | |
) -> HashMap<String, i64> | |
where | |
QS: QuerySource, | |
<QS as diesel::query_source::QuerySource>::FromClause: | |
diesel::query_builder::QueryFragment<diesel::pg::Pg>, | |
{ | |
select | |
.get_results(conn) | |
.expect("augh, diesel") | |
.into_iter() | |
.collect() | |
} | |
fn do_stuff() { | |
use crate::schema::my_table::dsl as t; | |
let query = t::my_table | |
.select((t::author, t::id)) | |
.into_boxed(); | |
let lookup_table = heckin_abstraction_with_diesel(conn, query); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment