Questions tagged [tokio-postgres]

An asynchronous, pipelined, PostgreSQL client for rust.

https://docs.rs/tokio-postgres/0.7.2/tokio_postgres/

33 questions
1
vote
1 answer

How can you close a tokio-postgres connection?

In the tokio-postgres documentation in the first example, there is an example showing that you should run the database connection in a separate thread: // The connection object performs the actual communication with the database, // so spawn it off…
Dalit Sairio
  • 115
  • 3
1
vote
0 answers

How to pass multiple parameters for a query statement in tokio_postgres?

I need to pass several parameters into the tokio_postgres::query Statement. How can I properly do this? The way I do it below doesn't work, what gets passed into the SQL database is the unconverted $2, instead of the date 2021-04-06. use…
1
vote
1 answer

How do I use a custom Tokio runtime within tokio_postgres (and without the tokio::main macro)?

How would I implement this tokio_postgres example with a custom tokio runtime builder and without the main macro? This works fine, per the tokio_postgres docs: examples/withmacro.rs use tokio_postgres::{NoTls, Error}; async fn db_main()->…
cloudsurfin
  • 2,467
  • 2
  • 25
  • 29
1
vote
2 answers

Is it possible to deserialize tokio_postgres rows without Struct?

I am new to Rust and trying to build a simple API server which connects to a Postgresql db which has a API route that runs a direct sql query and output JSON as the result. I did google and found that all the examples used in all the packages…
Robert Chan
  • 144
  • 11
0
votes
0 answers

How can I create a condtional WHERE clause that depends on the input values in PostgreSQL?

I am using the tokio_postgres crate with Rust. Of course, I can create two seperate queries and perform condition checking on my input values in my code, although I am looking for a way to do it through the SQL query. I am passing two values into my…
0
votes
0 answers

Process panic at type conversion despite error handling block

I’ve got this code: let rarity_from_db: Decimal = row.get("rarity"); let rarity = rarity_from_db.to_f64().unwrap_or_else(|| { error!( "Could not convert Numeric rarity value to f64 for record with ID {id}" ); 0.0 }); It’s inside…
Milkncookiez
  • 6,817
  • 10
  • 57
  • 96
0
votes
1 answer

Rust Query bb8_postgres with integer params

I get the error expected &(dyn ToSql + Sync), found i32 when passing an integer as a param to query a row in a PostgreSQL database on the following line: let rows = client.query("SELECT value FROM test WHERE id = $1;",…
DogEatDog
  • 2,899
  • 2
  • 36
  • 65
0
votes
0 answers

How do I access individual fields of this Rust tokio_postgres error type

I'm new to Rust and I've got this error. Error: Error { kind: Db, cause: Some(DbError { severity: "ERROR", parsed_severity: Some(Error), code: SqlState(E23502), message: "null value in column \"id\" of relation \"trades\" violates not-null…
JohnAllen
  • 7,317
  • 9
  • 41
  • 65
0
votes
0 answers

no method named "query_one" found for struct "PooledConnection"

I'm trying to make a method in a struct that interacts with a tokio_postgres pool. The code looks something like this: pub struct DatabaseHandler where M: ManageConnection { pool: Pool } impl DatabaseHandler where M:…
Levi Taylor
  • 105
  • 5
0
votes
1 answer

future cannot be sent between threads safely after Mutex

I've been trying to move from postgres to tokio_postgres but struggle with some async. use scraper::Html; use std::sync::Arc; use tokio::sync::Mutex; use tokio::task; struct Url {} impl Url { fn scrapped_home(&self, symbol: String) -> Html { …
a-gradina
  • 43
  • 5
0
votes
2 answers

Passing None into tokio postgres sql client query method

I am using tokio postgres in a Rust project where I have query parameters. rows = client.query(QUERY, &[&input1, &input2.unwrap()]).await.expect("error"); where QUERY looks like this QUERY: &str = "SELECT * FROM Table WHERE Name=$1 AND Address=…
0
votes
1 answer

Error with tokio postgres and database query Rust

I am working on a rust project where I am working with tokio postgres. I have a table by name of DATA that has two columns "id" and "opt". I have the data hitting the query as two inputs where one is a String and the other is an Option. Following…
roku675
  • 59
  • 1
  • 5
0
votes
1 answer

Dynamic SQL queries for tokio postgres in Rust

I am working with tokio postgres for a Rust project where I have a table Home having two columns 'number' and 'address'. My queries are being sent from the rust source code using the sql client as shown below, let rows = client.query(QUERY,…
0
votes
0 answers

How to impl From for a tokio_postgres::Row

I've successfully impl From for AStruct, but is it possible to (1) impl From to tokio_postgres::Row and (2) subsequently insert the created tokio_postgres::Row into a table? I've looked at tokio_postgres::Row (see…
Neotenic Primate
  • 313
  • 3
  • 13
0
votes
1 answer

Can you convert tokio_postgres::config::Config to connection string?

I want to establish a database connection with tokio_postgres crate. I created a Config object with a connection configuration. However, connect function takes connection string (&str) as an argument. In the docs I couldn't find any way to convert…
Piotr
  • 91
  • 1
  • 4