Skip to content

Commit

Permalink
parse timezone parameter in mysql connection url (#3418)
Browse files Browse the repository at this point in the history
* feat(mysql): support configuring the timezone via url

* test: add test case for mysql with timezone

---------

Co-authored-by: lo <[email protected]>
  • Loading branch information
dojiong and lo authored Nov 27, 2024
1 parent 4f10962 commit 94607b5
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions sqlx-mysql/src/options/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ impl MySqlConnectOptions {
options = options.socket(&*value);
}

"timezone" | "time-zone" => {
options = options.timezone(Some(value.to_string()));
}

_ => {}
}
}
Expand Down Expand Up @@ -176,3 +180,16 @@ fn it_returns_the_parsed_url() {

assert_eq!(expected_url, opts.build_url());
}

#[test]
fn it_parses_timezone() {
let opts: MySqlConnectOptions = "mysql://user:password@hostname/database?timezone=%2B08:00"
.parse()
.unwrap();
assert_eq!(opts.timezone.as_deref(), Some("+08:00"));

let opts: MySqlConnectOptions = "mysql://user:password@hostname/database?time-zone=%2B08:00"
.parse()
.unwrap();
assert_eq!(opts.timezone.as_deref(), Some("+08:00"));
}

0 comments on commit 94607b5

Please sign in to comment.