Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making a type Queryable and Insertable in diesel 0.10 #640

Closed
jimmycuadra opened this issue Feb 8, 2017 · 2 comments
Closed

Making a type Queryable and Insertable in diesel 0.10 #640

jimmycuadra opened this issue Feb 8, 2017 · 2 comments

Comments

@jimmycuadra
Copy link
Contributor

ruma-identifiers has some code to make a few custom types Insertable and Queryable. This previously worked in diesel 0.9: https://github.com/ruma/ruma-identifiers/blob/29f76ca95d295bca36ec53cd8da72217c5aa0f75/src/lib.rs#L689

This is being used in structs like this:

#[derive(AsChangeset, Debug, Clone, Identifiable, Insertable, Queryable)]
#[table_name = "profiles"]
pub struct Profile {
    pub id: ruma_identifiers::UserId,
    pub avatar_url: Option<String>,
    pub displayname: Option<String>,
}

In diesel 0.10, this now results in compiler errors:

error[E0277]: the trait bound `ruma_identifiers::UserId: diesel::Expression` is not satisfied
  --> src/models/profile.rs:18:1
   |
18 | #[derive(AsChangeset, Debug, Clone, Identifiable, Insertable, Queryable)]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `ruma_identifiers::UserId`
   |
   = note: required because of the requirements on the impl of `diesel::Expression` for `&'insert ruma_identifiers::UserId`
   = note: required because of the requirements on the impl of `diesel::expression::AsExpression<diesel::types::Nullable<diesel::types::Text>>` for `&'insert ruma_identifiers::UserId`
   = note: this error originates in a macro outside of the current crate

error[E0277]: the trait bound `ruma_identifiers::UserId: diesel::Expression` is not satisfied
  --> src/models/profile.rs:18:1
   |
18 | #[derive(AsChangeset, Debug, Clone, Identifiable, Insertable, Queryable)]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `ruma_identifiers::UserId`
   |
   = note: required because of the requirements on the impl of `diesel::Expression` for `&'insert ruma_identifiers::UserId`
   = note: required because of the requirements on the impl of `diesel::expression::AsExpression<diesel::types::Nullable<diesel::types::Text>>` for `&'insert ruma_identifiers::UserId`
   = note: this error originates in a macro outside of the current crate

error[E0277]: the trait bound `ruma_identifiers::UserId: diesel::Expression` is not satisfied
  --> src/models/profile.rs:18:1
   |
18 | #[derive(AsChangeset, Debug, Clone, Identifiable, Insertable, Queryable)]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `ruma_identifiers::UserId`
   |
   = note: required because of the requirements on the impl of `diesel::Expression` for `&'insert ruma_identifiers::UserId`
   = note: required because of the requirements on the impl of `diesel::expression::AsExpression<diesel::types::Nullable<diesel::types::Text>>` for `&'insert ruma_identifiers::UserId`
   = note: this error originates in a macro outside of the current crate

error[E0277]: the trait bound `&'insert models::profile::Profile: diesel::Insertable<schema::profiles::table, DB>` is not satisfied
  --> src/models/profile.rs:18:1
   |
18 | #[derive(AsChangeset, Debug, Clone, Identifiable, Insertable, Queryable)]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `diesel::Insertable<schema::profiles::table, DB>` is not implemented for `&'insert models::profile::Profile`
   |
   = help: the following implementations were found:
             <&'insert models::profile::Profile as diesel::Insertable<schema::profiles::table, DB>>
   = note: this error originates in a macro outside of the current crate

error[E0277]: the trait bound `ruma_identifiers::UserId: diesel::Expression` is not satisfied
  --> src/models/profile.rs:18:1
   |
18 | #[derive(AsChangeset, Debug, Clone, Identifiable, Insertable, Queryable)]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `ruma_identifiers::UserId`
   |
   = note: required because of the requirements on the impl of `diesel::Expression` for `&'insert ruma_identifiers::UserId`
   = note: required because of the requirements on the impl of `diesel::expression::AsExpression<diesel::types::Nullable<diesel::types::Text>>` for `&'insert ruma_identifiers::UserId`
   = note: this error originates in a macro outside of the current crate

error[E0277]: the trait bound `DB: diesel::backend::SupportsDefaultKeyword` is not satisfied
  --> src/models/profile.rs:18:1
   |
18 | #[derive(AsChangeset, Debug, Clone, Identifiable, Insertable, Queryable)]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `diesel::backend::SupportsDefaultKeyword` is not implemented for `DB`
   |
   = help: consider adding a `where DB: diesel::backend::SupportsDefaultKeyword` bound
   = note: required because of the requirements on the impl of `diesel::insertable::InsertValues<DB>` for `(diesel::insertable::ColumnInsertValue<schema::profiles::columns::id, &'insert ruma_identifiers::UserId>, diesel::insertable::ColumnInsertValue<schema::profiles::columns::avatar_url, diesel::expression::bound::Bound<diesel::types::Nullable<diesel::types::Text>, &std::option::Option<std::string::String>>>, diesel::insertable::ColumnInsertValue<schema::profiles::columns::displayname, diesel::expression::bound::Bound<diesel::types::Nullable<diesel::types::Text>, &std::option::Option<std::string::String>>>)`
   = note: required by `diesel::insertable::InsertValues`
   = note: this error originates in a macro outside of the current crate

error[E0277]: the trait bound `ruma_identifiers::UserId: diesel::query_builder::QueryFragment<DB>` is not satisfied
  --> src/models/profile.rs:18:1
   |
18 | #[derive(AsChangeset, Debug, Clone, Identifiable, Insertable, Queryable)]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `diesel::query_builder::QueryFragment<DB>` is not implemented for `ruma_identifiers::UserId`
   |
   = note: required because of the requirements on the impl of `diesel::query_builder::QueryFragment<DB>` for `&'insert ruma_identifiers::UserId`
   = note: required because of the requirements on the impl of `diesel::insertable::InsertValues<DB>` for `(diesel::insertable::ColumnInsertValue<schema::profiles::columns::id, &'insert ruma_identifiers::UserId>, diesel::insertable::ColumnInsertValue<schema::profiles::columns::avatar_url, diesel::expression::bound::Bound<diesel::types::Nullable<diesel::types::Text>, &std::option::Option<std::string::String>>>, diesel::insertable::ColumnInsertValue<schema::profiles::columns::displayname, diesel::expression::bound::Bound<diesel::types::Nullable<diesel::types::Text>, &std::option::Option<std::string::String>>>)`
   = note: required by `diesel::insertable::InsertValues`
   = note: this error originates in a macro outside of the current crate

I played around with it for a while but wasn't able to figure out what changed and how to account for those changes. Any suggestions?

@sgrif
Copy link
Member

sgrif commented Feb 8, 2017

According to that error message, you're missing impl<'a> AsExpression<Nullable<Text>> for &'a UserId

@sgrif
Copy link
Member

sgrif commented Feb 8, 2017

I expanded on this in #429 (comment). Feel free to comment here, open a new issue, or ping in gitter if this hasn't been sufficiently answered.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants