sea-orm/Design.md
Chris Tsang 5d3d080ea7 Readme
2021-05-17 02:24:30 +08:00

771 B

Readability

Turbofish and inference

Consider the following method:

fn left_join<E>(self) -> Self
where
    E: EntityTrait,
{
    // ...
}

which has to be invoked like:

.left_join::<fruit::Entity>()

If we instead do:

fn left_join<E>(self, _: E) -> Self
where
    E: EntityTrait,
{
    // ...
}

then the Turbofish can be omitted:

.left_join(fruit::Entity)

provided that fruit::Entity is a unit struct.

Builder pattern

Instead of:

fn has_many(entity: Entity, from: Column, to: Column);

has_many(cake::Entity, cake::Column::Id, fruit::Column::CakeId)

we'd prefer having a builder and stating the params explicitly:

has_many(cake::Entity).from(cake::Column::Id).to(fruit::Column::CakeId)