Questions tagged [tokio-postgres]

An asynchronous, pipelined, PostgreSQL client for rust.

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

33 questions
6
votes
2 answers

How to pass a Future as a function argument?

I am used to Scala's Future type where you wrap whatever object you're returning in Future[..] to designate it as such. My Rust function hello returns Query and I don't seem able to pass that result as an argument with type Future.…
ecoe
  • 4,994
  • 7
  • 54
  • 72
4
votes
0 answers

How to implement tokio_postgres::types::ToSql for enum type (rust, postgres)

I need to implement the tokio_postgres::types::ToSql for an enum type (rust and db as enum implemented) and I had no idea how to ... Example enum Flag {MyFlag1, MyFlag2, MyFlag3}; // on postgres db : // CREATE TYPE flag AS ENUM ('my_flag_1',…
Siassei
  • 41
  • 1
4
votes
1 answer

multiple value inserts to Postgres using Tokio-postgres in Rust

I am using the below code to insert to a Postgres DB using tokio-postgres, is there any better option : let members = &[obj] //obj is a struct let mut params = Vec::<&(dyn ToSql + Sync)>::new(); let mut i = 1; let mut qry:String = "insert into…
M.Nair
  • 243
  • 2
  • 9
3
votes
1 answer

Rust tokio_postgres row to object mapping fails with serde_postgres for timestamp column

I have rust actix-web rest project, which uses tokio_postgres and serde_postgres. The Table acme=# \d job Table "public.job" Column | Type | Collation | Nullable | …
Bopsi
  • 2,090
  • 5
  • 36
  • 58
2
votes
1 answer

Rust and PostgreSQL with tokio_postgres

I have a PostgreSQL database with one simple table: CREATE DATABASE test_database; \c test_database; CREATE TABLE users ( id int primary key NOT NULL, name varchar(40) NOT NULL ); INSERT INTO users (id,name) VALUES (1, 'user_one'); INSERT INTO users…
miravelardo
  • 75
  • 1
  • 9
2
votes
1 answer

The trait `FromSql<'_>` is not implemented for `Uuid` in tokio-postgres in rust

I am trying to use UUID as my primary key in Postgres. I am getting the trait FromSql<'_> is not implemented for Uuid in tokio-postgres. First I try to use tokio-pg-mapper but it is also showing the same compile error. So, I try diff approach and…
GrvTyagi
  • 4,231
  • 1
  • 33
  • 40
2
votes
1 answer

How to take ownership of a Mutex of a tokio_postgres::Client with an async task?

I want to create a function that returns a tokio_postgres client. However, I can't find a solution to take ownership of variable (a database connection from the library tokio_postgres) in an async task (to connect to the database). Here is my code…
Léo Coletta
  • 1,099
  • 2
  • 12
  • 24
1
vote
1 answer

Tokio_postgres hangs when trying to perform simple query

I'm trying to connect to a postgres server from my Rust program, but I can't seem to run even simple queries, they just hang with no error or output. I start my database with: docker run -p 9897:5432 --name postgres-server -e…
jotjern
  • 460
  • 5
  • 18
1
vote
1 answer

Unable to pass tokio-postgres pool connections to Axum handler

I'm a Rust newbie. I'm trying to create a pool of tokio-postgres connections to a handler, it should use the connection for fill a database table. I used deadpool-postgres and it seems it creates the pool. Problem is that i can't pass the pool to…
1
vote
1 answer

The latest chrono 0.4 crate uses time 0.1 which has a potential segfault - how to fix?

I'm writing an app in Rust that uses a PostgreSQL client connection pool with Chrono (0.4.22) features for date time calculations. So my Cargo.toml has these lines: [dependencies] postgres = {version = "0.19", features = ["with-chrono-0_4"]} chrono…
Code4R7
  • 2,600
  • 1
  • 19
  • 42
1
vote
1 answer

Rust error on dyn ToSql + Sync: Temporary which is freed while still in use

I am working on a rust project that is using the following code let mut container: Vec<&(dyn ToSql + Sync)> = Vec::new(); I have a variable name which is of type Option. I am getting this error when I execute the following snippet if…
1
vote
1 answer

tokio_postgres: serialize Json into Vec

TLDR: Given a query that returns rows with a column containing a Json array: id | name | post_ids ----+---------+---------- 1 | JohnDoe | [1,2] Serializing it using tokio_postgres into the User model —which contains a post_ids: Vec
Emille C.
  • 315
  • 2
  • 15
1
vote
1 answer

How do I "throw" a tokio_postgres::Error?

I want to create a validation when I'm creating a new user. Already an email error must be returned. Like this: pub async fn insert_usuario(usuario: &Usuario) -> Result<&Usuario, Error> { let mut fetch_usuario= Usuario { nome: String::new(),…
1
vote
1 answer

How do you convert a collection to a Result in rust and actix to return data from postgres?

Using rust and the actix framework, I am trying to fetch a list of records from postgres and return it as JSON. I am referencing this example code: https://github.com/actix/examples/tree/master/databases/postgres The following are my changes. The…
travisluong
  • 143
  • 3
  • 10
1
vote
2 answers

How to return tokio_postgres ToSql type from closure in Rust?

How could I avoid repeating myself by passing the ToSql data as a closure, telling tokio-postgres which columns of data, from my various struct models, to COPY/SELECT/etc? For instance, ideally I could pass various table/column args, like: // see…
ecoe
  • 4,994
  • 7
  • 54
  • 72
1
2 3