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

Remove impl_Insertable macro #692

Closed
wants to merge 3 commits into from

Conversation

weiznich
Copy link
Member

No description provided.

@weiznich weiznich force-pushed the remove_insertable_macro branch 3 times, most recently from 446e48e to e94f313 Compare February 13, 2017 13:32
Copy link
Member

@killercup killercup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before digging into the functional aspects of this, I left some stylistic requests. Formatting complex types is not easy, but I hope you can see a pattern in my suggestions. (Maybe someone over at rust-lang/style-team#15 is interested in this as well?) I'd also appreciate trailing commas everywhere (I've commented only in a few places).

Feel free to not make the code style changes until after the functionality has been reviewed.

(ColumnInsertValue<self::__diesel_schema_migrations::version,
AsNullableExpr<&'insert &'a str,
self::__diesel_schema_migrations::version>>, ): InsertValues<DB>,
{
Copy link
Member

@killercup killercup Feb 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is pretty much unparsable to me. Maybe format it like this?

type Table = self::__diesel_schema_migrations::table;
type Version = self::__diesel_schema_migrations::version;

impl<'ins, 'a, DB> Insertable<Table, DB> for &'ins NewMigration<'a> where
    DB: Backend,
    (ColumnInsertValue<
        Version,
        AsNullableExpr<&'ins &'a str, version>,
    >,): InsertValues<DB>,

ColumnInsertValue::Expression(
#column,
AsExpression::<<<#column as Expression>::SqlType
as IntoNullable>::Nullable>::as_expression(value)
Copy link
Member

@killercup killercup Feb 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you try not to break the line here? I'd split this up into

type NullableColumn = AsExpression::<
    <<#column as Expression>::SqlType as IntoNullable>::Nullable,
>;

and then use NullableColumn::as_expression(value)

(ColumnInsertValue::Expression(self::__diesel_schema_migrations::version,
AsExpression::<<<self::__diesel_schema_migrations::version
as Expression>::SqlType as IntoNullable>::Nullable>
::as_expression(version)),)
Copy link
Member

@killercup killercup Feb 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you try not to break this at as and ::? It's really hard to read this way. Using the Table alias from abovem you could write

(ColumnInsertValue::Expression(Version,
    AsExpression::<
        <<Version as Expression>::SqlType as IntoNullable>::Nullable,
    >::as_expression(version)
),)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a big fan of type aliases btw. They can be used to make nice "reverse" associated type accessors like this (IIRC):

type SqlType<T> = <T as Expression>::SqlType;
type Nullable<T> = <T as IntoNullable>::Nullable;

ColumnInsertValue::Expression(
#column,
AsExpression::<<<#column as Expression>::SqlType
as IntoNullable>::Nullable>::as_expression(#field_access)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pls don't break at as. See above.

}
)
}))
.build();
Copy link
Member

@killercup killercup Feb 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use block ident? I'd write this as

.with_predicates(
    model.generics.lifetimes
    .iter()
    .map(|l| {
        syn::WherePredicate::RegionPredicate(
            syn::WhereRegionPredicate {
                lifetime: l.lifetime.clone(),
                bounds: vec![insert.lifetime.clone()],
            }
        )
    })
)
.build();

(Also note the space before { and trailing comma in WhereRegionPredicate)

#table_name::table,
Self,
Op,
Ret
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing commas are good :)

fn make_column_insert_value(
a: &Attr,
table_name: &syn::Ident,
struct_name: &str
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing comma


#[test]
fn simple_struct_definition() {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✂️

@weiznich weiznich force-pushed the remove_insertable_macro branch 2 times, most recently from 7e3e3b6 to c5b6eae Compare February 13, 2017 14:43
@weiznich
Copy link
Member Author

Any news on this?

@sgrif
Copy link
Member

sgrif commented Apr 30, 2017

I'd like to postpone these for the time being. I think there are two steps I'd like to take as separate PRs before we take this step:

  • Move the tests for the bang macro to instead use the #[derive] (and presumably move them to the diesel_codegen crate)
  • Remove the struct parsing code from diesel and only leave the entry point that codegen uses.

That would make our job of reviewing significantly easier, help point out gaps in our test coverage, and make me more comfortable with this step.

@sgrif sgrif closed this Apr 30, 2017
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

Successfully merging this pull request may close these issues.

None yet

3 participants