parse timezone parameter in mysql connection url (#3418)

* feat(mysql): support configuring the timezone via url

* test: add test case for mysql with timezone

---------

Co-authored-by: lo <lo@los-MacBook-Pro.local>
This commit is contained in:
Lo 2024-11-28 06:14:00 +08:00 committed by GitHub
parent 4f10962743
commit 94607b5a10
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -72,6 +72,10 @@ impl MySqlConnectOptions {
options = options.socket(&*value);
}
"timezone" | "time-zone" => {
options = options.timezone(Some(value.to_string()));
}
_ => {}
}
}
@ -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"));
}