Sqlx and actix-web3 tokio error


I'm working with sqlx - now when using actix-web3 as described here - I'm getting a panic:

cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.09s
     Running `target/debug/sqlx_test`
thread 'main' panicked at 'there is no reactor running, must be called from the context of a Tokio 1.x runtime', /home/doerig/.cargo/registry/src/github.com-1ecc6299db9ec823/sqlx-core-0.5.10/src/pool/inner.rs:32

My Cargo.toml look like this:

# Actix-web:
sqlx = { version = "0.5", features = [ "runtime-actix-native-tls" , "postgres" ] }
actix-web = "3"

main.rs like this:

use sqlx::postgres::PgPoolOptions;
// use sqlx::mysql::MySqlPoolOptions;
// etc.

// or #[tokio::main]
async fn main() -> Result<(), sqlx::Error> {
    // Create a connection pool
    //  for MySQL, use MySqlPoolOptions::new()
    //  for SQLite, use SqlitePoolOptions::new()
    //  etc.
    let pool = PgPoolOptions::new()

    // Make a simple query to return the given parameter (use a question mark `?` instead of `$1` for MySQL)
    let row: (i64,) = sqlx::query_as("SELECT $1")

    assert_eq!(row.0, 150);


Compiled it with Rust 1.58.1. The example code can be checked out from this repo. Or did I miss something - don't get it at the moment.


Found out when using the new actix-web4 like this

# Actix-web:
sqlx = { version = "0.5", features = [ "runtime-actix-native-tls" , "postgres" ] }
actix-web = "4.0.0-beta.5"

it seems to work.

Problem is that (non-beta) actix-web uses an old version of Tokio, and it breaks if you mix up Tokio versions.

Thanks - so in other words I could step down the sqlx version until it uses the same tokio version as actix-web3 does?

I don't know if there's a version of sqlx that uses Tokio 0.2.x, but if there is, then yes.

I would probably recommend you just use the beta, or use a framework that isn't perpetually stuck in beta/on an old Tokio.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.