SeaQL / sea-orm

🐚 An async & dynamic ORM for Rust
https://www.sea-ql.org/SeaORM/
Apache License 2.0
6.57k stars 461 forks source link

(maybe bug) PaginatorTrait does not apply to generic method. #2096

Closed DenuxPlays closed 4 months ago

DenuxPlays commented 4 months ago

Description

I have my entities in a separate crate and all functions return a Select. I also have a few helper functions in my "main" crate and one of them should count. The method is the following:

pub async fn count<T: EntityTrait>(select_stm: Select<T>) -> Result<u64, ApiError>
    where
        T: Send + Sized,
{
    let total = select_stm.count(get_database_connection()).await.map_err(ApiError::from)?;
    Ok(total)
}

But I am getting the following error message: image image

In fact I can't use any function in my function. I asked on the discord but nobody was able to help me.

Steps to Reproduce

  1. Create a helper function like shown above.
  2. Try to compile
  3. See the errors

Expected Behavior

Better documentation on covering this edge case or just working out of the box.

Actual Behavior

Compiling errors

Reproduces How Often

Everytime. Should be easy to reproduce or show me the error I am doing.

Workarounds

None (almost). Fetch all entries and simply count in rust. (Heavy load on the database). My current "workaround":

pub async fn count<T: EntityTrait>(select_stm: Select<T>) -> Result<u64, ApiError>
{
    find_all(select_stm).await.map(|models| models.len() as u64)
}

I wouldn't call this a workaround as it does something completly different.

Reproducible Example

Just add the method as it is a compile error there is no "need" for an actual example.

Versions

Rust: 1.75.0 Sea-Orm: 0.12.12 OS: Fedora 39 (and Alpine 3.19)

DenuxPlays commented 4 months ago

Maybe this is a bug maybe I just don't know enough about rust. I tried a lot of things I cannot find a solution, so if this is my error please show me how to fix this