Skip to content
This repository was archived by the owner on Aug 30, 2025. It is now read-only.

Commit a9ff411

Browse files
committed
extrapolate db pool initialization/getting function
1 parent 4c4b249 commit a9ff411

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/main.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -203,13 +203,7 @@ async fn main() {
203203
};
204204

205205
log::info!(target: "symfonia::db", "Establishing database connection");
206-
let db = DATABASE
207-
.get_or_init(|| async {
208-
database::establish_connection()
209-
.await
210-
.expect("Could not establish a connection to the database")
211-
})
212-
.await;
206+
let db = db_pool().await;
213207

214208
if database::check_migrating_from_spacebar(db)
215209
.await
@@ -276,3 +270,14 @@ async fn main() {
276270
.expect("Failed to start server");
277271
}
278272
}
273+
274+
/// Retrieve a `static` reference to the [PgPool].
275+
pub async fn db_pool() -> &'static PgPool {
276+
DATABASE
277+
.get_or_init(|| async {
278+
database::establish_connection()
279+
.await
280+
.expect("Could not establish a connection to the database")
281+
})
282+
.await
283+
}

0 commit comments

Comments
 (0)