Skip to content

Instantly share code, notes, and snippets.

@icefoxen
Created March 27, 2019 16:36
Show Gist options
  • Save icefoxen/287da263a333213975762fe6472b1cfc to your computer and use it in GitHub Desktop.
Save icefoxen/287da263a333213975762fe6472b1cfc to your computer and use it in GitHub Desktop.
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