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

Error on large table definitions #53

Closed
lephyrius opened this Issue Dec 5, 2015 · 7 comments

Comments

Projects
None yet
3 participants
@lephyrius

lephyrius commented Dec 5, 2015

This code works:

table! {
    hello {
        id -> Serial,
        hello_a -> Integer,
        hello_b -> Integer,
        hello_c -> Integer,
        hello_d -> Integer,
        hello_e -> Integer,
        hello_f -> Integer,
        hello_g -> Integer,
        hello_h -> Integer,
        hello_i -> Integer,
        hello_j -> Integer,
        hello_k -> Integer,
        hello_l -> Integer,
        hello_m -> Integer,
        hello_n -> Integer,
        hello_o -> Integer,
    }
}

This code doesn't work:

table! {
    hello {
        id -> Serial,
        hello_a -> Integer,
        hello_b -> Integer,
        hello_c -> Integer,
        hello_d -> Integer,
        hello_e -> Integer,
        hello_f -> Integer,
        hello_g -> Integer,
        hello_h -> Integer,
        hello_i -> Integer,
        hello_j -> Integer,
        hello_k -> Integer,
        hello_l -> Integer,
        hello_m -> Integer,
        hello_n -> Integer,
        hello_o -> Integer,
        hello_p -> Integer,
    }
}

It gives this error:

<diesel macros>:16:54: 19:52 error: the trait `diesel::types::NativeSqlType` is not implemented for the type `(diesel::types::Integer, diesel::types::Integer, diesel::types::Integer, diesel::types::Integer, diesel::types::Integer, diesel::types::Integer, diesel::types::Integer, diesel::types::Integer, diesel::types::Integer, diesel::types::Integer, diesel::types::Integer, diesel::types::Integer, diesel::types::Integer, diesel::types::Integer, diesel::types::Integer, diesel::types::Integer, diesel::types::Integer)` [E0277]
<diesel macros>:16 out . push_identifier ( stringify ! ( $ name ) ) } } impl AsQuery for table {
<diesel macros>:17 type SqlType = SqlType ; type Query = SelectStatement < SqlType , (
<diesel macros>:18 $ ( $ column_name ) , + ) , Self > ; fn as_query ( self ) -> Self:: Query {
<diesel macros>:19 SelectStatement:: simple ( all_columns , self ) } } impl Table for table {
<diesel macros>:15:1: 17:58 note: in this expansion of table_body! (defined in <diesel macros>)
<diesel macros>:5:1: 6:2 note: in this expansion of table! (defined in <diesel macros>)
<diesel macros>:2:1: 2:64 note: in this expansion of table! (defined in <diesel macros>)
src/main.rs:50:1: 70:2 note: in this expansion of table! (defined in <diesel macros>)
<diesel macros>:16:54: 19:52 help: run `rustc --explain E0277` to see a detailed explanation
<diesel macros>:16:54: 19:52 note: required by `diesel::query_builder::AsQuery`
<diesel macros>:16:54: 19:52 error: the trait `diesel::expression::SelectableExpression<hello::table, (diesel::types::Integer, diesel::types::Integer, diesel::types::Integer, diesel::types::Integer, diesel::types::Integer, diesel::types::Integer, diesel::types::Integer, diesel::types::Integer, diesel::types::Integer, diesel::types::Integer, diesel::types::Integer, diesel::types::Integer, diesel::types::Integer, diesel::types::Integer, diesel::types::Integer, diesel::types::Integer, diesel::types::Integer)>` is not implemented for the type `(hello::columns::id, hello::columns::hello_a, hello::columns::hello_b, hello::columns::hello_c, hello::columns::hello_d, hello::columns::hello_e, hello::columns::hello_f, hello::columns::hello_g, hello::columns::hello_h, hello::columns::hello_i, hello::columns::hello_j, hello::columns::hello_k, hello::columns::hello_l, hello::columns::hello_m, hello::columns::hello_n, hello::columns::hello_o, hello::columns::hello_p)` [E0277]
<diesel macros>:16 out . push_identifier ( stringify ! ( $ name ) ) } } impl AsQuery for table {
<diesel macros>:17 type SqlType = SqlType ; type Query = SelectStatement < SqlType , (
<diesel macros>:18 $ ( $ column_name ) , + ) , Self > ; fn as_query ( self ) -> Self:: Query {
<diesel macros>:19 SelectStatement:: simple ( all_columns , self ) } } impl Table for table {
<diesel macros>:15:1: 17:58 note: in this expansion of table_body! (defined in <diesel macros>)
<diesel macros>:5:1: 6:2 note: in this expansion of table! (defined in <diesel macros>)
<diesel macros>:2:1: 2:64 note: in this expansion of table! (defined in <diesel macros>)
src/main.rs:50:1: 70:2 note: in this expansion of table! (defined in <diesel macros>)
<diesel macros>:16:54: 19:52 help: run `rustc --explain E0277` to see a detailed explanation
<diesel macros>:16:54: 19:52 note: required by `diesel::query_builder::AsQuery`
<diesel macros>:19:53: 23:45 error: the trait `diesel::expression::Expression` is not implemented for the type `(hello::columns::id, hello::columns::hello_a, hello::columns::hello_b, hello::columns::hello_c, hello::columns::hello_d, hello::columns::hello_e, hello::columns::hello_f, hello::columns::hello_g, hello::columns::hello_h, hello::columns::hello_i, hello::columns::hello_j, hello::columns::hello_k, hello::columns::hello_l, hello::columns::hello_m, hello::columns::hello_n, hello::columns::hello_o, hello::columns::hello_p)` [E0277]
<diesel macros>:19 SelectStatement:: simple ( all_columns , self ) } } impl Table for table {
<diesel macros>:20 type PrimaryKey = columns:: $ pk ; type AllColumns = ( $ ( $ column_name ) , +
<diesel macros>:21 ) ; fn name (  ) -> & 'static str { stringify ! ( $ name ) } fn primary_key (
<diesel macros>:22 & self ) -> Self:: PrimaryKey { columns:: $ pk } fn all_columns (  ) -> Self::
<diesel macros>:23 AllColumns { ( $ ( $ column_name ) , + ) } } pub mod columns {
<diesel macros>:15:1: 17:58 note: in this expansion of table_body! (defined in <diesel macros>)
<diesel macros>:5:1: 6:2 note: in this expansion of table! (defined in <diesel macros>)
<diesel macros>:2:1: 2:64 note: in this expansion of table! (defined in <diesel macros>)
src/main.rs:50:1: 70:2 note: in this expansion of table! (defined in <diesel macros>)
<diesel macros>:19:53: 23:45 help: run `rustc --explain E0277` to see a detailed explanation
error: aborting due to 3 previous errors

What is wrong? I'm pretty new on rust. 🍶

@sgrif

This comment has been minimized.

Member

sgrif commented Dec 5, 2015

Busted! I only support tuples of an arbitrarily large size, as it takes longer to compile when I increase it. Right now we go to 16 IIRC, I'll bump it to 26

@sgrif sgrif closed this in d2d3181 Dec 14, 2015

@sgrif

This comment has been minimized.

Member

sgrif commented Dec 14, 2015

This is fixed in the next release. You'll need to add features = ["large-tables"] to your Cargo.toml, as this change increases our compile time by a ton, and I don't think common usage requires > 16.

@lephyrius

This comment has been minimized.

lephyrius commented Dec 14, 2015

@sgrif That's how it is working with legacy code. :)
THX!
Why can't it be configurable? (might be a stupid question by me. Only knowing C++ templates. )

@sgrif

This comment has been minimized.

Member

sgrif commented Dec 14, 2015

Unfortunately since we're working with tuples here, I can't just use an arbitrary number in the macro. (The short version is self.19 is a valid expression, but self.(19-1) is not.)

So I have to put some boilerplate in to make this work, which means I end up picking some arbitrary number. 26 was what my editor macro to add more impls worked up to.

@iamsebastian

This comment has been minimized.

Contributor

iamsebastian commented Jun 3, 2016

I'm totally sure it will be not a default case, but at the moment I got three tables (the whole db contains ~ 50 tables) with more than 26 columns (up to 40 columns). Is there are any chance, to get this compiled? I just tried to migrate an old data-structure from MySQL to Pg and would like to do a test-connection with the diesel-demo (, where the structure gets magically converted to ORM 😀 )

@sgrif

This comment has been minimized.

Member

sgrif commented Jun 3, 2016

You can double it again with the "huge-tables" feature

@iamsebastian

This comment has been minimized.

Contributor

iamsebastian commented Jun 3, 2016

Well done, sir. Thank you, Sean.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment