pg_extras/queries/
cache_hit.rs1use crate::{queries::shared::Query, PgStatsVersion};
2use sqlx::postgres::PgRow;
3use sqlx::types::BigDecimal;
4use sqlx::Row;
5
6#[derive(Debug, Clone)]
7pub struct CacheHit {
8 pub name: String,
9 pub ratio: BigDecimal,
10}
11
12impl serde::Serialize for CacheHit {
13 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
14 where
15 S: serde::Serializer,
16 {
17 use serde::ser::SerializeStruct;
18 let mut state = serializer.serialize_struct("CacheHit", 2)?;
19 state.serialize_field("name", &self.name)?;
20 state.serialize_field("ratio", &format!("{:?}", self.ratio))?;
21 state.end()
22 }
23}
24
25impl Query for CacheHit {
26 fn new(row: &PgRow) -> Self {
27 Self {
28 name: row.try_get("name").unwrap_or_default(),
29 ratio: row.try_get("ratio").unwrap_or_default(),
30 }
31 }
32
33 fn to_row(&self) -> prettytable::Row {
34 row![self.name, self.ratio]
35 }
36
37 fn headers() -> prettytable::Row {
38 row!["name", "ratio"]
39 }
40
41 fn read_file(_pg_statement_version: Option<PgStatsVersion>) -> String {
42 include_str!("../sql/cache_hit.sql").to_string()
43 }
44}