Skip to content

Commit cb72202

Browse files
authored
Prefix generated struct with Compressed for clarity (#6)
1 parent 6e0860c commit cb72202

File tree

13 files changed

+87
-86
lines changed

13 files changed

+87
-86
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## 0.3.0
44

5+
- **Breaking**: Prefix generated struct with `Compressed` for clarity
56
- **Breaking**: Skip time range filter in `decompress` when used by `delete`
67
- This prevents data loss when compacting data into a single row to improve compression
78
- Add documentation to the generated code

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,13 @@ async fn example() -> anyhow::Result<()> {
8585

8686
// Write
8787
let stats = vec![QueryStat { database_id, collected_at: end - Duration::from_secs(120), fingerprint: 1, calls: 1, total_time: 1.0 }];
88-
QueryStats::store(db, stats).await?;
88+
CompressedQueryStats::store(db, stats).await?;
8989
let stats = vec![QueryStat { database_id, collected_at: end - Duration::from_secs(60), fingerprint: 1, calls: 1, total_time: 1.0 }];
90-
QueryStats::store(db, stats).await?;
90+
CompressedQueryStats::store(db, stats).await?;
9191

9292
// Read
9393
let mut calls = 0;
94-
for group in QueryStats::load(db, &[database_id], start, end).await? {
94+
for group in CompressedQueryStats::load(db, &[database_id], start, end).await? {
9595
for stat in group.decompress()? {
9696
calls += stat.calls;
9797
}
@@ -106,16 +106,16 @@ async fn example() -> anyhow::Result<()> {
106106
assert_eq!(2, db.query_one("SELECT count(*) FROM query_stats", &[]).await?.get::<_, i64>(0));
107107
transaction!(db, {
108108
let mut stats = Vec::new();
109-
for group in QueryStats::delete(db, &[database_id], start, end).await? {
109+
for group in CompressedQueryStats::delete(db, &[database_id], start, end).await? {
110110
for stat in group.decompress()? {
111111
stats.push(stat);
112112
}
113113
}
114114
assert_eq!(0, db.query_one("SELECT count(*) FROM query_stats", &[]).await?.get::<_, i64>(0));
115-
QueryStats::store(db, stats).await?;
115+
CompressedQueryStats::store(db, stats).await?;
116116
});
117117
assert_eq!(1, db.query_one("SELECT count(*) FROM query_stats", &[]).await?.get::<_, i64>(0));
118-
let group = QueryStats::load(db, &[database_id], start, end).await?.remove(0);
118+
let group = CompressedQueryStats::load(db, &[database_id], start, end).await?.remove(0);
119119
assert_eq!(group.start_at, end - Duration::from_secs(120));
120120
assert_eq!(group.end_at, end - Duration::from_secs(60));
121121
let stats = group.decompress()?;

benches/bucket_size/one_day.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ pub async fn store() -> Result<()> {
102102
pub async fn load() -> Result<()> {
103103
let db = &DB_POOL.get().await.unwrap();
104104
let mut stats = Vec::new();
105-
for group in QueryStats::load(db).await? {
105+
for group in CompressedQueryStats::load(db).await? {
106106
for stat in group.decompress() {
107107
stats.push(stat);
108108
}
@@ -123,7 +123,7 @@ pub async fn load() -> Result<()> {
123123
pub shared_blks_hit: i64,
124124
pub shared_blks_read: i64,
125125
}
126-
pub struct QueryStats {
126+
pub struct CompressedQueryStats {
127127
database_id: i64,
128128
start_at: SystemTime,
129129
collected_at: Vec<u8>,
@@ -137,15 +137,15 @@ pub async fn load() -> Result<()> {
137137
shared_blks_hit: Vec<u8>,
138138
shared_blks_read: Vec<u8>,
139139
}
140-
impl QueryStats {
140+
impl CompressedQueryStats {
141141
pub async fn load(db: &Client) -> Result<Vec<Self>> {
142142
let sql = "
143143
SELECT database_id, start_at, collected_at, collected_secs, fingerprint, postgres_role_id, calls, rows, total_time, io_time, shared_blks_hit, shared_blks_read
144144
FROM bucket_size_one_day
145145
";
146146
let mut results = Vec::new();
147147
for row in db.query(&db.prepare_cached(sql).await?, &[]).await? {
148-
results.push(QueryStats {
148+
results.push(Self {
149149
database_id: row.get(0),
150150
start_at: row.get(1),
151151
collected_at: row.get(2),

benches/bucket_size/ten_minute.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ pub async fn store() -> Result<()> {
8484
pub async fn load() -> Result<()> {
8585
let db = &DB_POOL.get().await.unwrap();
8686
let mut stats = Vec::new();
87-
for group in QueryStats::load(db).await? {
87+
for group in CompressedQueryStats::load(db).await? {
8888
for stat in group.decompress() {
8989
stats.push(stat);
9090
}
@@ -105,7 +105,7 @@ pub async fn load() -> Result<()> {
105105
pub shared_blks_hit: i64,
106106
pub shared_blks_read: i64,
107107
}
108-
pub struct QueryStats {
108+
pub struct CompressedQueryStats {
109109
database_id: i64,
110110
start_at: SystemTime,
111111
collected_at: Vec<u8>,
@@ -119,15 +119,15 @@ pub async fn load() -> Result<()> {
119119
shared_blks_hit: Vec<u8>,
120120
shared_blks_read: Vec<u8>,
121121
}
122-
impl QueryStats {
122+
impl CompressedQueryStats {
123123
pub async fn load(db: &Client) -> Result<Vec<Self>> {
124124
let sql = "
125125
SELECT database_id, start_at, collected_at, collected_secs, fingerprint, postgres_role_id, calls, rows, total_time, io_time, shared_blks_hit, shared_blks_read
126126
FROM bucket_size_ten_minute
127127
";
128128
let mut results = Vec::new();
129129
for row in db.query(&db.prepare_cached(sql).await?, &[]).await? {
130-
results.push(QueryStats {
130+
results.push(Self {
131131
database_id: row.get(0),
132132
start_at: row.get(1),
133133
collected_at: row.get(2),

benches/comparison/pco.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ pub async fn store() -> Result<()> {
104104
pub async fn load() -> Result<()> {
105105
let db = &DB_POOL.get().await.unwrap();
106106
let mut stats = Vec::new();
107-
for group in QueryStats::load(db).await? {
107+
for group in CompressedQueryStats::load(db).await? {
108108
for stat in group.decompress() {
109109
stats.push(stat);
110110
}
@@ -125,7 +125,7 @@ pub async fn load() -> Result<()> {
125125
pub shared_blks_hit: i64,
126126
pub shared_blks_read: i64,
127127
}
128-
pub struct QueryStats {
128+
pub struct CompressedQueryStats {
129129
database_id: i64,
130130
start_at: SystemTime,
131131
collected_at: Vec<u8>,
@@ -139,15 +139,15 @@ pub async fn load() -> Result<()> {
139139
shared_blks_hit: Vec<u8>,
140140
shared_blks_read: Vec<u8>,
141141
}
142-
impl QueryStats {
142+
impl CompressedQueryStats {
143143
pub async fn load(db: &Client) -> Result<Vec<Self>> {
144144
let sql = "
145145
SELECT database_id, start_at, collected_at, collected_secs, fingerprint, postgres_role_id, calls, rows, total_time, io_time, shared_blks_hit, shared_blks_read
146146
FROM comparison_pco
147147
";
148148
let mut results = Vec::new();
149149
for row in db.query(&db.prepare_cached(sql).await?, &[]).await? {
150-
results.push(QueryStats {
150+
results.push(Self {
151151
database_id: row.get(0),
152152
start_at: row.get(1),
153153
collected_at: row.get(2),

benches/comparison/pco_store.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ pub async fn store() -> Result<()> {
8080
});
8181
}
8282
}
83-
QueryStats::store(db, stats).await?;
83+
CompressedQueryStats::store(db, stats).await?;
8484
}
8585
}
8686
Ok(())
@@ -90,7 +90,7 @@ pub async fn load() -> Result<()> {
9090
let db = &DB_POOL.get().await.unwrap();
9191
let database_ids: Vec<i64> = db.query_one("SELECT array_agg(DISTINCT database_id) FROM comparison_pco_stores", &[]).await?.get(0);
9292
let mut stats = Vec::new();
93-
for group in QueryStats::load(db, &database_ids, SystemTime::UNIX_EPOCH, SystemTime::now()).await? {
93+
for group in CompressedQueryStats::load(db, &database_ids, SystemTime::UNIX_EPOCH, SystemTime::now()).await? {
9494
for stat in group.decompress()? {
9595
stats.push(stat);
9696
}

benches/float/mult.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ pub async fn store(mult: u8) -> Result<()> {
108108
pub async fn load(mult: u8) -> Result<()> {
109109
let db = &DB_POOL.get().await.unwrap();
110110
let mut stats = Vec::new();
111-
for group in QueryStats::load(db, mult).await? {
111+
for group in CompressedQueryStats::load(db, mult).await? {
112112
for stat in group.decompress() {
113113
stats.push(stat);
114114
}
@@ -129,7 +129,7 @@ pub async fn load(mult: u8) -> Result<()> {
129129
pub shared_blks_hit: i64,
130130
pub shared_blks_read: i64,
131131
}
132-
pub struct QueryStats {
132+
pub struct CompressedQueryStats {
133133
database_id: i64,
134134
start_at: SystemTime,
135135
collected_at: Vec<u8>,
@@ -143,15 +143,15 @@ pub async fn load(mult: u8) -> Result<()> {
143143
shared_blks_hit: Vec<u8>,
144144
shared_blks_read: Vec<u8>,
145145
}
146-
impl QueryStats {
146+
impl CompressedQueryStats {
147147
pub async fn load(db: &Client, mult: u8) -> Result<Vec<Self>> {
148148
let sql = &format!("
149149
SELECT database_id, start_at, collected_at, collected_secs, fingerprint, postgres_role_id, calls, rows, total_time, io_time, shared_blks_hit, shared_blks_read
150150
FROM float_mult_{mult}
151151
");
152152
let mut results = Vec::new();
153153
for row in db.query(&db.prepare_cached(sql).await?, &[]).await? {
154-
results.push(QueryStats {
154+
results.push(Self {
155155
database_id: row.get(0),
156156
start_at: row.get(1),
157157
collected_at: row.get(2),

benches/float/round.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ fn round(float: f64, decimals: u8) -> f64 {
114114
pub async fn load(decimals: u8) -> Result<()> {
115115
let db = &DB_POOL.get().await.unwrap();
116116
let mut stats = Vec::new();
117-
for group in QueryStats::load(db, decimals).await? {
117+
for group in CompressedQueryStats::load(db, decimals).await? {
118118
for stat in group.decompress() {
119119
stats.push(stat);
120120
}
@@ -135,7 +135,7 @@ pub async fn load(decimals: u8) -> Result<()> {
135135
pub shared_blks_hit: i64,
136136
pub shared_blks_read: i64,
137137
}
138-
pub struct QueryStats {
138+
pub struct CompressedQueryStats {
139139
database_id: i64,
140140
start_at: SystemTime,
141141
collected_at: Vec<u8>,
@@ -149,15 +149,15 @@ pub async fn load(decimals: u8) -> Result<()> {
149149
shared_blks_hit: Vec<u8>,
150150
shared_blks_read: Vec<u8>,
151151
}
152-
impl QueryStats {
152+
impl CompressedQueryStats {
153153
pub async fn load(db: &Client, decimals: u8) -> Result<Vec<Self>> {
154154
let sql = &format!("
155155
SELECT database_id, start_at, collected_at, collected_secs, fingerprint, postgres_role_id, calls, rows, total_time, io_time, shared_blks_hit, shared_blks_read
156156
FROM float_round_{decimals}
157157
");
158158
let mut results = Vec::new();
159159
for row in db.query(&db.prepare_cached(sql).await?, &[]).await? {
160-
results.push(QueryStats {
160+
results.push(Self {
161161
database_id: row.get(0),
162162
start_at: row.get(1),
163163
collected_at: row.get(2),

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub fn store(args: TokenStream, item: TokenStream) -> TokenStream {
5454
let model = parse_macro_input!(i as ItemStruct);
5555
let item = proc_macro2::TokenStream::from(item);
5656
let name = model.ident.clone();
57-
let packed_name = Ident::new(&(model.ident.to_string() + "s"), Span::call_site());
57+
let packed_name = Ident::new(&format!("Compressed{}s", model.ident), Span::call_site());
5858

5959
let table_name = if let Some(table_name) = table_name {
6060
table_name.to_string()

tests/expand/boolean.expanded.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@ pub struct QueryStat {
44
pub calls: i64,
55
}
66
/// Generated by pco_store to store and load compressed versions of [QueryStat]
7-
pub struct QueryStats {
7+
pub struct CompressedQueryStats {
88
pub database_id: i64,
99
toplevel: Vec<u8>,
1010
calls: Vec<u8>,
1111
}
12-
impl QueryStats {
12+
impl CompressedQueryStats {
1313
/// Loads data for the specified filters.
1414
///
1515
/// For models with a timestamp, [decompress][Self::decompress] automatically filters out
1616
/// rows outside the requested time range.
1717
pub async fn load(
1818
db: &deadpool_postgres::Object,
1919
database_id: &[i64],
20-
) -> anyhow::Result<Vec<QueryStats>> {
20+
) -> anyhow::Result<Vec<CompressedQueryStats>> {
2121
if database_id.is_empty() {
2222
return ::anyhow::__private::Err({
2323
use ::anyhow::__private::kind::*;
@@ -38,7 +38,7 @@ impl QueryStats {
3838
let mut results = Vec::new();
3939
for row in db.query(&db.prepare_cached(&sql).await?, &[&database_id]).await? {
4040
results
41-
.push(QueryStats {
41+
.push(CompressedQueryStats {
4242
database_id: row.get(0usize),
4343
toplevel: row.get(1usize),
4444
calls: row.get(2usize),
@@ -53,7 +53,7 @@ impl QueryStats {
5353
pub async fn delete(
5454
db: &deadpool_postgres::Object,
5555
database_id: &[i64],
56-
) -> anyhow::Result<Vec<QueryStats>> {
56+
) -> anyhow::Result<Vec<CompressedQueryStats>> {
5757
if database_id.is_empty() {
5858
return ::anyhow::__private::Err({
5959
use ::anyhow::__private::kind::*;
@@ -74,7 +74,7 @@ impl QueryStats {
7474
let mut results = Vec::new();
7575
for row in db.query(&db.prepare_cached(&sql).await?, &[&database_id]).await? {
7676
results
77-
.push(QueryStats {
77+
.push(CompressedQueryStats {
7878
database_id: row.get(0usize),
7979
toplevel: row.get(1usize),
8080
calls: row.get(2usize),

0 commit comments

Comments
 (0)