Skip to content
This repository has been archived by the owner on Sep 26, 2024. It is now read-only.

benthillerkus/diesel-enum-trouble

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Fix

In the generated schema you need to import {YourEnumName}Mapping instead of {YourEnumName}.

To prevent having to edit the schema.rs manually, you can re-export the Mapping type to just be called {YourEnumName}. Then add that re-export to the diesel.toml.

Old: problem description

This example is abridged from the Diesel getting started guide.

It tries to make the following (postgres) SQL

up.sql

create type level as enum ('error', 'warn', 'info', 'debug', 'trace');

create table logs (
  id serial primary key,
  severity level not null default 'info'
);

work with Diesel using the diesel-derive-enum crate.

Unfortunately, it will not compile 😢

error[E0277]: the trait bound `types::Level: diesel::Expression` is not satisfied
 --> src\models.rs:4:17
  |
4 | #[derive(Debug, Insertable)]
  |                 ^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `types::Level`
  |
  = note: required because of the requirements on the impl of `AsExpression<types::Level>` for `types::Level`
  = note: this error originates in the derive macro `Insertable` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `types::Level: diesel::Expression` is not satisfied
 --> src\models.rs:4:17
  |
4 | #[derive(Debug, Insertable)]
  |                 ^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `types::Level`
  |
  = note: required because of the requirements on the impl of `diesel::Expression` for `&'insert types::Level`
  = note: required because of the requirements on the impl of `AsExpression<types::Level>` for `&'insert types::Level`
  = note: this error originates in the derive macro `Insertable` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `types::Level: diesel::Expression` is not satisfied
 --> src\models.rs:4:17
  |
4 | #[derive(Debug, Insertable)]
  |                 ^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `types::Level`
  |
  = note: required because of the requirements on the impl of `diesel::Expression` for `&types::Level`
  = note: required because of the requirements on the impl of `AsExpression<types::Level>` for `&types::Level`
  = note: this error originates in the derive macro `Insertable` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0277`.
error: could not compile `db_enums_test` due to 3 previous errors

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks