@@ -2,7 +2,7 @@ use crate::certs::CRUNCHY;
22use diesel:: { Connection , ConnectionResult , PgConnection , QueryResult } ;
33use diesel_async:: pooled_connection:: deadpool:: { Hook , HookError } ;
44use diesel_async:: pooled_connection:: ManagerConfig ;
5- use diesel_async:: { AsyncPgConnection , RunQueryDsl } ;
5+ use diesel_async:: { AsyncConnection , AsyncPgConnection , RunQueryDsl } ;
66use native_tls:: { Certificate , TlsConnector } ;
77use postgres_native_tls:: MakeTlsConnector ;
88use secrecy:: ExposeSecret ;
@@ -23,6 +23,18 @@ pub fn oneoff_connection() -> anyhow::Result<PgConnection> {
2323 oneoff_connection_with_config ( & config) . map_err ( Into :: into)
2424}
2525
26+ pub async fn oneoff_async_connection_with_config (
27+ config : & config:: DatabasePools ,
28+ ) -> ConnectionResult < AsyncPgConnection > {
29+ let url = connection_url ( config, config. primary . url . expose_secret ( ) ) ;
30+ AsyncPgConnection :: establish ( & url) . await
31+ }
32+
33+ pub async fn oneoff_async_connection ( ) -> anyhow:: Result < AsyncPgConnection > {
34+ let config = config:: DatabasePools :: full_from_environment ( & config:: Base :: from_environment ( ) ?) ?;
35+ Ok ( oneoff_async_connection_with_config ( & config) . await ?)
36+ }
37+
2638pub fn connection_url ( config : & config:: DatabasePools , url : & str ) -> String {
2739 let mut url = Url :: parse ( url) . expect ( "Invalid database URL" ) ;
2840
0 commit comments