Instantly share code, notes, and snippets.

Embed
What would you like to do?
pub trait HasAcs {
fn valid(&self) -> bool;
fn from_row(row: &HashMap<&str, &str>) -> Self;
fn file() -> &'static str;
}
fn process_acs<T: HasAcs + diesel::query_builder::AsChangeset>() {
use schema::locations::dsl::*;
let conn = establish_connection();
let mut reader = Reader::from_file(T::file())
.unwrap()
.has_headers(true);
let headers = reader.headers().unwrap();
for row in reader.records() {
// ... extra processing elided like populating map, zip and loc_id variables or whatever
let it = T::from_row(&map);
if it.valid() {
let _ = diesel::update(locations.find(loc_id))
.set(&it) // <- here
.returning(id)
.get_result::<i32>(&conn)
.expect(&format!("Couldn't update zip {}", &zip));
} else {
println!("Error on {:?}", &zip);
}
}
}
Compiling import v0.1.0 (file:///Users/jeff/dev/car-insurance/database/import)
error[E0277]: the trait bound `&T: diesel::query_builder::AsChangeset` is not satisfied
--> src/lib.rs:380:18
|
380 | .set(&it)
| ^^^ trait `&T: diesel::query_builder::AsChangeset` not satisfied
|
= help: consider adding a `where &T: diesel::query_builder::AsChangeset` bound
error[E0277]: the trait bound `models::Demographics: diesel::query_builder::AsChangeset` is not satisfied
--> src/lib.rs:391:5
|
391 | process_acs::<Demographics>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait `models::Demographics: diesel::query_builder::AsChangeset` not satisfied
|
= help: the following implementations were found:
= help: <&'update models::Demographics as diesel::query_builder::AsChangeset>
= note: required by `process_acs`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment