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

Drop Default trait bound of PrimaryKeyTrait::ValueType #205

Merged
merged 17 commits into from
Oct 12, 2021
Merged

Conversation

billy1624
Copy link
Member

@billy1624 billy1624 commented Sep 27, 2021

@billy1624 billy1624 self-assigned this Sep 27, 2021
Copy link
Member Author

@billy1624 billy1624 left a comment

Choose a reason for hiding this comment

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

I'm thinking how to get rid of all these...

// This
<<Self as ActiveModelTrait>::Entity as EntityTrait>::PrimaryKey:
            PrimaryKeyValue<<Self as ActiveModelTrait>::Entity>,

// And this
<<A as ActiveModelTrait>::Entity as EntityTrait>::PrimaryKey:
            PrimaryKeyValue<<A as ActiveModelTrait>::Entity>,

src/entity/active_model.rs Outdated Show resolved Hide resolved
src/entity/base_entity.rs Outdated Show resolved Hide resolved
@billy1624
Copy link
Member Author

billy1624 commented Sep 27, 2021

Got this error, somehow...

Error: Exec("error returned from database: database table is locked: metadata")

https://github.com/SeaQL/sea-orm/runs/3719025255#step:5:290

Might be related launchbadge/sqlx#326

@billy1624 billy1624 marked this pull request as ready for review September 28, 2021 11:04
@tyt2y3
Copy link
Member

tyt2y3 commented Sep 29, 2021

Thanks. It looks good generally.

Though I don't understand why we have to add a new trait PrimaryKeyValue.

I think the existing API provides sufficient info for us to implement extract_primary_key_value_from_model.

src/executor/insert.rs Outdated Show resolved Hide resolved
@billy1624
Copy link
Member Author

billy1624 commented Sep 30, 2021

Though I don't understand why we have to add a new trait PrimaryKeyValue.

I don't want to include get_primary_key_value inside PrimaryKeyTrait because this will requires changing either...

  • Add type def Entity: EntityTrait
  • Add generic E: EntityTrait

I think the existing API provides sufficient info for us to implement extract_primary_key_value_from_model.

I think the only way to extract either (A, B) (tuple value) or A (single value) is to impl PrimaryKeyValue inside DerivePrimayKey and counting the number of primary key columns.

@tyt2y3
Copy link
Member

tyt2y3 commented Sep 30, 2021

I think, since our identity is only a tuple of 1, 2 or 3,
there can be ways to accomplish this without introducing a new trait.

Iterable actually is able to tell us the arity I suppose.

@billy1624
Copy link
Member Author

Something like this?

fn find_by_id(values: <Self::PrimaryKey as PrimaryKeyTrait>::ValueType) -> Select<Self> {
let mut select = Self::find();
let mut keys = Self::PrimaryKey::iter();
for v in values.into_value_tuple() {
if let Some(key) = keys.next() {
let col = key.into_column();
select = select.filter(col.eq(v));
} else {
panic!("primary key arity mismatch");
}
}
if keys.next().is_some() {
panic!("primary key arity mismatch");
}
select
}

@tyt2y3
Copy link
Member

tyt2y3 commented Oct 5, 2021

Still WIP?

@billy1624
Copy link
Member Author

I think, since our identity is only a tuple of 1, 2 or 3, there can be ways to accomplish this without introducing a new trait.

Iterable actually is able to tell us the arity I suppose.

Stuck on this

@tyt2y3
Copy link
Member

tyt2y3 commented Oct 5, 2021

Something like this?

Yes, should be.

@tyt2y3
Copy link
Member

tyt2y3 commented Oct 6, 2021

still stuck?

@billy1624
Copy link
Member Author

Yep loll

@billy1624
Copy link
Member Author

billy1624 commented Oct 6, 2021

I can avoid add a new trait by putting extract_primary_key_value method in ActiveModelTrait. And implement it inside proc_macros. How is that sounds? @tyt2y3

@tyt2y3
Copy link
Member

tyt2y3 commented Oct 8, 2021

No we don't need that either

@tyt2y3 tyt2y3 merged commit 213a3fb into master Oct 12, 2021
@tyt2y3 tyt2y3 deleted the last-insert-id branch October 12, 2021 06:12
arpancodes pushed a commit to arpancodes/sea-orm that referenced this pull request Apr 8, 2022
* Add a "with-array" option for postgres.

This introduces "Array" as a new Value variant.
It can be derived from all Vec<T> types, where T is a valid Value,
   except for u8, which is already handled by Bytes.

* Fix typo.

Co-authored-by: Chris Tsang <[email protected]>
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.

Why PrimaryKeyTrait::ValueType: Default is needed?
2 participants