| 1 | use crate::connection::ConnectOptions; |
| 2 | use crate::error::Error; |
| 3 | use crate::{PgConnectOptions, PgConnection}; |
| 4 | use futures_core::future::BoxFuture; |
| 5 | use log::LevelFilter; |
| 6 | use sqlx_core::Url; |
| 7 | use std::time::Duration; |
| 8 | |
| 9 | impl ConnectOptions for PgConnectOptions { |
| 10 | type Connection = PgConnection; |
| 11 | |
| 12 | fn from_url(url: &Url) -> Result<Self, Error> { |
| 13 | Self::parse_from_url(url) |
| 14 | } |
| 15 | |
| 16 | fn to_url_lossy(&self) -> Url { |
| 17 | self.build_url() |
| 18 | } |
| 19 | |
| 20 | fn connect(&self) -> BoxFuture<'_, Result<Self::Connection, Error>> |
| 21 | where |
| 22 | Self::Connection: Sized, |
| 23 | { |
| 24 | Box::pin(PgConnection::establish(self)) |
| 25 | } |
| 26 | |
| 27 | fn log_statements(mut self, level: LevelFilter) -> Self { |
| 28 | self.log_settings.log_statements(level); |
| 29 | self |
| 30 | } |
| 31 | |
| 32 | fn log_slow_statements(mut self, level: LevelFilter, duration: Duration) -> Self { |
| 33 | self.log_settings.log_slow_statements(level, duration); |
| 34 | self |
| 35 | } |
| 36 | } |