Diesel: No support for some MySQL data types

Created on 29 Mar 2017  路  7Comments  路  Source: diesel-rs/diesel

Diesel currently supports only the main MySQL data types, defined here. In that documentation page the MySQL documentation is linked, were it can be seen that there are more types (MEDIUMINT, DECIMAL, VARCHAR, VARBINARY, TINYBLOB, TINYTEXT, MEDIUMBLOB, MEDIUMTEXT, LONGBLOB, LONGTEXT and BIT) that are not supported by the current implementation.

Trying to use these types gives these errors:

error[E0412]: cannot find type `Mediumint` in this scope
 --> src/db/schema.rs:3:1
  |
3 | infer_schema!("dotenv:DATABASE_URL");
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope
  |
  = note: this error originates in a macro outside of the current crate

error[E0412]: cannot find type `Decimal` in this scope
 --> src/db/schema.rs:3:1
  |
3 | infer_schema!("dotenv:DATABASE_URL");
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope
  |
  = note: this error originates in a macro outside of the current crate

Reported in Rust user's forum here.

help wanted mysql

Most helpful comment

The only type left is mediumint which we aren't going to support. Closing this.

All 7 comments

Since the diesel_infer_schema seems to only work off of the default SQL types, this might require some direction on how a maintainer can help out.

edit: I have a custom U24 struct for Mediumint, and BIT is the same as TINYINT(1), which is already handled by the code so a pub type could be used there to finish that one.

The Decimal type is currently being implemented for postgres in #837. I'll probably implement it for MySQL once it's done for pg.

mediumint cannot be deserialized as is since there is not i24 type. Would considering it as an integer be ok ? @sgrif

I figured primitives were the only acceptable types. If mediumint could just be a i32, that would solve a lot of problems at the expense of one byte per use.

We can implement FromSql<MediumInt> for i32, but not ToSql. It'd be similar to the situation with Timestamptz where we allow things like DateTime<Local> in ToSql but not FromSql. I think the situation for MediumInt would be significantly more painful however, since there would be no type which would implement both ToSql and FromSql for it.

Task list, to keep track:

  • [x] DECIMAL #1019
  • [ ] MEDIUMINT
  • [x] VARCHAR #1012
  • [x] VARBINARY #1012
  • [x] TINYBLOB #1012
  • [x] TINYTEXT #1012
  • [x] MEDIUMBLOB #1012
  • [x] MEDIUMTEXT #1012
  • [x] LONGBLOB #1012
  • [x] LONGTEXT #1012
  • [x] BIT #1012

Feel free to copy this comment in the top. IMO, this makes it easier to keep track of the issue :-)

edit: Mmm, nevermind. Seems like only MEDIUMINT is missing.

Yeah, and we can't add support for it as there is no type in rust to serialize/deserialize it.

The only type left is mediumint which we aren't going to support. Closing this.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

killercup picture killercup  路  3Comments

astraw picture astraw  路  4Comments

kanekv picture kanekv  路  3Comments

killercup picture killercup  路  4Comments

jimmycuadra picture jimmycuadra  路  4Comments