this version of actix/sqlx works, but uses diff runtime?

This commit is contained in:
Brandon Thomas committed 2021-05-16 11:57:29 -04:00
1 parent 0cc74fe266
commit 32a9949559
4 files changed
+398 -313

No files matched your search

Generated
+369 -303
View File
File diff suppressed because it is too large. Load diff
+8 -1
View File
@@ -24,7 +24,14 @@ rand = "0.8.3"
# Database
#sqlx = { version = "0.5.0", features = ["mysql", "runtime-tokio-rustls", "chrono"] }
sqlx = { version = "0.3", features = [ "mysql" ] }
#error: one of the features ['runtime-actix-native-tls', 'runtime-async-std-native-tls', 'runtime-tokio-native-tls', 'runtime-actix-rustls', 'runtime-async-std-rustls', 'runtime-tokio-rustls'] must be enabled
#sqlx = { version = "0.5", features = [ "mysql", "runtime-actix-native-tls" ] }
sqlx = { version = "0.5", features = [ "mysql", "runtime-async-std-rustls" ] }
#sqlx = { version = "0.5.0", features = ["mysql", "runtime-actix-rustls", "chrono"] }
#diesel = { version = "1.4.4", features = ["mysql", "r2d2", "chrono"] }
#diesel-derive-enum = { version = "1.0.0", features = ["mysql"] }
+6 -1
View File
@@ -27,6 +27,11 @@ TODO
* Install indexes on all foreign keys
* Make sure unique indexes are correct
Notes / TODOs:
* Tests: https://stackoverflow.com/questions/65370752/how-do-i-create-an-actix-web-server-that-accepts-both-sqlx-database-pools-and-tr
* Examples for good Actix+Sqlx Tests:
https://stackoverflow.com/questions/65370752/how-do-i-create-an-actix-web-server-that-accepts-both-sqlx-database-pools-and-tr
* Actix/sqlx runtime compat:
https://github.com/launchbadge/sqlx/issues/1117#issuecomment-801237734
+15 -8
View File
@@ -8,7 +8,7 @@ use actix_web::{HttpServer, web, HttpResponse, App};
use std::sync::Arc;
use crate::server_state::{ServerState, EnvConfig};
use sqlx::MySqlPool;
//use sqlx::mysql::MySqlPoolOptions;
use sqlx::mysql::MySqlPoolOptions;
const DEFAULT_BIND_ADDRESS : &'static str = "0.0.0.0:12345";
const DEFAULT_RUST_LOG: &'static str = "debug,actix_web=info";
@@ -52,16 +52,22 @@ pub async fn serve(server_state: ServerState) -> AnyhowResult<()>
let db_connection_string = "mysql://root:root@localhost/storyteller";
//let pool = MySqlPool::connect(db_connection_string).await?;
/*let pool = MySqlPoolOptions::new()
let pool = MySqlPoolOptions::new()
.max_connections(5)
.connect(db_connection_string)
.await?;*/
.await?;
let row: (i64,) = sqlx::query_as("SELECT 1")
//.bind(150_i64)
.fetch_one(&pool).await?;
println!("Result: {:?}", row);
/*
// Working example in 0.3 sqlx
let pool = MySqlPool::new(db_connection_string).await?;
/*let row: (i64,) = sqlx::query_as("SELECT $1")
.bind(150_i64)
.fetch_one(&pool).await?;*/
let recs = sqlx::query!(
r#"
SELECT id, username
@@ -71,6 +77,7 @@ pub async fn serve(server_state: ServerState) -> AnyhowResult<()>
)
.fetch_all(&pool)
.await?;
*/
let server_state_arc = web::Data::new(Arc::new(server_state));