1use std::sync::Arc;
2use std::time::Instant;
3
4use opentelemetry::KeyValue;
5use opentelemetry::metrics::Histogram;
6
7use crate::database::Database;
8use crate::pool::SharedState;
9
10pub struct PoolConnection<DB: sqlx::Database> {
18 pub(crate) inner: sqlx::pool::PoolConnection<DB>,
19 pub(crate) state: SharedState,
20 pub(crate) use_time: Arc<Histogram<f64>>,
21 pub(crate) acquired_at: Instant,
22 pub(crate) base_attrs: Vec<KeyValue>,
23}
24
25impl<DB: sqlx::Database> Drop for PoolConnection<DB> {
26 fn drop(&mut self) {
27 self.use_time
28 .record(self.acquired_at.elapsed().as_secs_f64(), &self.base_attrs);
29 }
30}
31
32impl<DB: sqlx::Database> std::fmt::Debug for PoolConnection<DB> {
33 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
34 f.debug_struct("PoolConnection").finish_non_exhaustive()
35 }
36}
37
38impl<DB: Database> PoolConnection<DB> {
39 impl_with_annotations_mut!();
40}