sfackler / rust-postgres

Native PostgreSQL driver for the Rust programming language
Apache License 2.0
3.46k stars 439 forks source link

How to process payload from notify after collected notify? #1131

Open Barto-Paja opened 5 months ago

Barto-Paja commented 5 months ago

Hello, I'm trying to process the collected payload from a notification. When I receive notification from PostgreSQL database, I would like to insert new data into the db. I took the code from example https://github.com/sfackler/rust-postgres/blob/98f5a11bc0a8e451552d8941ffa078c7eb6cd60c/tokio-postgres/tests/test/main.rs#L736-L769 something like this:

let notifications = rx
    .filter_map(|m| match m {
        AsyncMessage::Notification(n) => {
            println!("Notification {:?}", n);
            // insert_stuff(connection_parameters, n.payload()) <-- insert new data into db, but here asking for add await
            future::ready(Some(n))
        },
        _ => future::ready(None),
    })
    .collect::<Vec<_>>()
    .await;

Note: newbie in rust