Merge pull request #47 from Gusted/encode-url-postgres

Encode connection URL to database
This commit is contained in:
Aravinth Manivannan 2022-10-17 15:42:02 +05:30 committed by GitHub
commit 521abd82d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 10 deletions

View File

@ -13,6 +13,7 @@ async-trait = "0.1.51"
db-core = {path = "../db-core"}
futures = "0.3.15"
sqlx = { version = "0.5.13", features = [ "runtime-actix-rustls", "mysql", "time", "offline" ] }
urlencoding = "2.1.2"
[dev-dependencies]
actix-rt = "2"

View File

@ -68,14 +68,13 @@ impl Connect for ConnectionOptions {
async fn connect(self) -> DBResult<Self::Pool> {
let pool = match self {
Self::Fresh(fresh) => {
let mut connect_options =
sqlx::mysql::MySqlConnectOptions::from_str(&fresh.url).unwrap();
let mut connect_options = sqlx::mysql::MySqlConnectOptions::from_str(
&urlencoding::encode(&fresh.url),
)
.unwrap();
if fresh.disable_logging {
connect_options.disable_statement_logging();
}
sqlx::mysql::MySqlConnectOptions::from_str(&fresh.url)
.unwrap()
.disable_statement_logging();
fresh
.pool_options
.connect_with(connect_options)

View File

@ -13,6 +13,7 @@ async-trait = "0.1.51"
db-core = {path = "../db-core"}
futures = "0.3.15"
sqlx = { version = "0.5.13", features = [ "runtime-actix-rustls", "postgres", "time", "offline" ] }
urlencoding = "2.1.2"
[dev-dependencies]
actix-rt = "2"

View File

@ -68,14 +68,13 @@ impl Connect for ConnectionOptions {
async fn connect(self) -> DBResult<Self::Pool> {
let pool = match self {
Self::Fresh(fresh) => {
let mut connect_options =
sqlx::postgres::PgConnectOptions::from_str(&fresh.url).unwrap();
let mut connect_options = sqlx::postgres::PgConnectOptions::from_str(
&urlencoding::encode(&fresh.url),
)
.unwrap();
if fresh.disable_logging {
connect_options.disable_statement_logging();
}
sqlx::postgres::PgConnectOptions::from_str(&fresh.url)
.unwrap()
.disable_statement_logging();
fresh
.pool_options
.connect_with(connect_options)