Hello
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:
[dependencies]
# 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.
//#[async_std::main]
// or #[tokio::main]
#[actix_web::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()
.max_connections(5)
.connect("postgres://postgres:password@localhost/test").await?;
// 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")
.bind(150_i64)
.fetch_one(&pool).await?;
assert_eq!(row.0, 150);
Ok(())
}
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.
Stefan