Giter VIP home page Giter VIP logo

Comments (6)

khuey avatar khuey commented on May 30, 2024

Ugh, that's kind of nasty. Maybe we should add a method onto PostgresConnectionManager and give you a way to get that from the Pool.

from bb8.

djc avatar djc commented on May 30, 2024

It seems like a weird API from tokio-postgres. If Connection is supposed to "generally be spawned off onto an executor", you have no way of getting notifications? @sfackler, is that true? Wouldn't it make more sense to expose some kind of query_raw() like API from the Client?

from bb8.

hengchu avatar hengchu commented on May 30, 2024

Ugh, that's kind of nasty. Maybe we should add a method onto PostgresConnectionManager and give you a way to get that from the Pool.

That could work. Although this is not a high-priority issue (at least not for me...). Since we are using a dedicated connection already, right now I just use tokio_postgres::connect directly to get the underlying connection object, instead of through bb8.

It seems like a weird API from tokio-postgres. If Connection is supposed to "generally be spawned off onto an executor", you have no way of getting notifications? @sfackler, is that true? Wouldn't it make more sense to expose some kind of query_raw() like API from the Client?

There does seem to be some friction between bb8's API and tokio_postgres's notification API. Currently, you need to call poll_message on the tokio_postgres::Connection object to receive notifications. You can make this more ergonomic with futures::stream::poll_fn which just turns the connection into a notification Stream value.

from bb8.

khuey avatar khuey commented on May 30, 2024

It appears you have to drive the connection yourself if you want to get LISTEN notifications. Ideally tokio-postgres would split those off into a separate Stream for you ...

from bb8.

sfackler avatar sfackler commented on May 30, 2024

The general expectation is that if you want to forward notifications to a stream, you'd write that code and then spawn it off: https://github.com/sfackler/rust-postgres/blob/master/tokio-postgres/tests/test/main.rs#L616-L619

What would a query_raw function do?

from bb8.

djc avatar djc commented on May 30, 2024

Ah, that general expectation is actually reasonable. But it's different from what I read into the documentation for poll_message(): "Applications that wish to examine those messages should use this method to drive the connection rather than its Future implementation.". I guess there's no simple way to get this for a Client because there's potentially many Clients.

Maybe link that example code from the poll_message() docs?

from bb8.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.