Skip to content

GenericClient is not implemented for T: tokio_postgres::GenericClient #286

@LouisGariepy

Description

@LouisGariepy

Migrated from halcyonnouveau/clorinde#117, originally reported by @TimDiekmann on 2025-06-10.

The generated code generates a new trait GenericClient. This is basically a copy of tokio_postgres::GenericClient, however, it's not the same trait.
The trait is implemented on tokio_postgres::Client and tokio_postgres::Transaction, but not on a generic T: tokio_postgres::GenericClient. This means in a generic context

async fn takes_client(client: &impl GenericClient) {
    // do something with `clorinde::GenericClient`
}

this will error.

If this code snippet would be generated instead, everything would work as expected:

impl<C: tokio_postgres::GenericClient + Sync> GenericClient for C {
    async fn prepare(&self, query: &str) -> Result<Statement, Error> {
        tokio_postgres::GenericClient::prepare(self, query).await
    }

    async fn execute<T>(
        &self,
        query: &T,
        params: &[&(dyn tokio_postgres::types::ToSql + Sync)],
    ) -> Result<u64, Error>
    where
        T: ?Sized + tokio_postgres::ToStatement + Sync + Send,
    {
        tokio_postgres::GenericClient::execute(self, query, params).await
    }

    async fn query_one<T>(
        &self,
        statement: &T,
        params: &[&(dyn tokio_postgres::types::ToSql + Sync)],
    ) -> Result<tokio_postgres::Row, Error>
    where
        T: ?Sized + tokio_postgres::ToStatement + Sync + Send,
    {
        tokio_postgres::GenericClient::query_one(self, statement, params).await
    }

    async fn query_opt<T>(
        &self,
        statement: &T,
        params: &[&(dyn tokio_postgres::types::ToSql + Sync)],
    ) -> Result<Option<tokio_postgres::Row>, Error>
    where
        T: ?Sized + tokio_postgres::ToStatement + Sync + Send,
    {
        tokio_postgres::GenericClient::query_opt(self, statement, params).await
    }

    async fn query<T>(
        &self,
        query: &T,
        params: &[&(dyn tokio_postgres::types::ToSql + Sync)],
    ) -> Result<Vec<tokio_postgres::Row>, Error>
    where
        T: ?Sized + tokio_postgres::ToStatement + Sync + Send,
    {
        tokio_postgres::GenericClient::query(self, query, params).await
    }

    async fn query_raw<T, I>(&self, statement: &T, params: I) -> Result<RowStream, Error>
    where
        T: ?Sized + ToStatement + Sync + Send,
        I: IntoIterator + Sync + Send,
        I::IntoIter: ExactSizeIterator,
        I::Item: BorrowToSql,
    {
        tokio_postgres::GenericClient::query_raw(self, statement, params).await
    }
}

Btw, the GenericClient does not need the Send bound:

pub trait GenericClient: Sync {

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcodegenAn issue regarding code generation, or the generated code itself.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions