Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

sqlx this functionality requires a Tokio context

$
0
0

I'm looking at the quickstart of SQLx to connect to a posgresql database:

Cargo.toml:

[dependencies]sqlx = { version = "0.7", features = [ "postgres", "runtime-tokio", "tls-rustls" ] }tokio = { version = "0.2.22", features = ["full"] }

and here is my main.rs (copied from the read me).

use sqlx::PgPool;#[tokio::main]async fn main() -> Result<(), sqlx::Error> {    let pool = PgPool::connect("postgres://root:password@localhost:5555/test").await?;    let row: (i64,) = sqlx::query_as("SELECT $1")        .bind(150_i64)        .fetch_one(&pool)        .await?;    assert_eq!(row.0, 150);    Ok(())}

When I run cargo run I get the error:

thread 'main' panicked at /Users/valentin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/sqlx-core-0.7.4/src/pool/inner.rs:500:5:this functionality requires a Tokio context

I can connect to my PostgreSQL database with the command:

 psql -h localhost -p 5555 -U root -d test

and the password password.

What am I missing?


Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>