Skip to content

Instantly share code, notes, and snippets.

@sbeckeriv
Created January 2, 2017 00:09
Show Gist options
  • Save sbeckeriv/91992673fde5f2dd557ca5c30ee79695 to your computer and use it in GitHub Desktop.
Save sbeckeriv/91992673fde5f2dd557ca5c30ee79695 to your computer and use it in GitHub Desktop.
use diesel;
use diesel::prelude::*;
use diesel::pg::PgConnection;
use dotenv::dotenv;
use std::env;
use schema::inspections;
use schema::inspections::dsl::inspections as all_inspections;
use schema::places;
use schema::places::dsl::places as all_places;
fn db() -> PgConnection {
dotenv().ok();
let database_url = env::var("DATABASE_URL").expect("DATABASE_URL must be set");
PgConnection::establish(&database_url).expect(&format!("Error connecting to {}", database_url))
}
#[table_name = "places"]
#[derive(Serialize, Queryable, Insertable, FromForm, Debug, Clone)]
pub struct Place {
pub id: i32,
pub name: String,
pub program_identifier: String,
pub description: Option<String>,
pub phone: Option<String>,
pub address: String,
pub longitude: f64,
pub latitude: f64,
pub published: bool,
}
impl Place {
pub fn all() -> Vec<Place> {
all_places.order(places::id.desc()).load::<Place>(&db()).unwrap()
}
}
error[E0277]: the trait bound `std::string::String: diesel::types::FromSqlRow<diesel::types::Double, diesel::pg::Pg>` is not satisfied
--> src/models.rs:57:45
|
57 | all_places.order(places::id.desc()).load::<Place>(&db()).unwrap()
| ^^^^ the trait `diesel::types::FromSqlRow<diesel::types::Double, diesel::pg::Pg>` is not implemented for `std::string::String`
|
= help: the following implementations were found:
= help: <std::string::String as diesel::types::FromSqlRow<diesel::types::Text, DB>>
= note: required because of the requirements on the impl of `diesel::types::FromSqlRow<(diesel::types::Integer, diesel::types::Text, diesel::types::Text, diesel::types::Nullable<diesel::types::Text>, diesel::types::Nullable<diesel::types::Text>, diesel::types::Double, diesel::types::Double, diesel::types::Text, diesel::types::Bool), diesel::pg::Pg>` for `(i32, std::string::String, std::string::String, std::option::Option<std::string::String>, std::option::Option<std::string::String>, std::string::String, f64, f64, bool)`
= note: required because of the requirements on the impl of `diesel::Queryable<(diesel::types::Integer, diesel::types::Text, diesel::types::Text, diesel::types::Nullable<diesel::types::Text>, diesel::types::Nullable<diesel::types::Text>, diesel::types::Double, diesel::types::Double, diesel::types::Text, diesel::types::Bool), diesel::pg::Pg>` for `models::Place`
error[E0277]: the trait bound `f64: diesel::types::FromSqlRow<diesel::types::Text, diesel::pg::Pg>` is not satisfied
--> src/models.rs:57:45
|
57 | all_places.order(places::id.desc()).load::<Place>(&db()).unwrap()
| ^^^^ the trait `diesel::types::FromSqlRow<diesel::types::Text, diesel::pg::Pg>` is not implemented for `f64`
|
= help: the following implementations were found:
= help: <f64 as diesel::types::FromSqlRow<diesel::types::Double, DB>>
= note: required because of the requirements on the impl of `diesel::types::FromSqlRow<(diesel::types::Integer, diesel::types::Text, diesel::types::Text, diesel::types::Nullable<diesel::types::Text>, diesel::types::Nullable<diesel::types::Text>, diesel::types::Double, diesel::types::Double, diesel::types::Text, diesel::types::Bool), diesel::pg::Pg>` for `(i32, std::string::String, std::string::String, std::option::Option<std::string::String>, std::option::Option<std::string::String>, std::string::String, f64, f64, bool)`
= note: required because of the requirements on the impl of `diesel::Queryable<(diesel::types::Integer, diesel::types::Text, diesel::types::Text, diesel::types::Nullable<diesel::types::Text>, diesel::types::Nullable<diesel::types::Text>, diesel::types::Double, diesel::types::Double, diesel::types::Text, diesel::types::Bool), diesel::pg::Pg>` for `models::Place`
error: aborting due to 2 previous errors
Table "public.places"
Column | Type | Modifiers
--------------------+-------------------+-----------------------------------------------------
id | integer | not null default nextval('places_id_seq'::regclass)
name | character varying | not null
program_identifier | character varying | not null
description | character varying |
phone | character varying |
longitude | double precision | not null
latitude | double precision | not null
address | character varying | not null
published | boolean | not null default false
Indexes:
"places_pkey" PRIMARY KEY, btree (id)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment