Skip to content

Commit

Permalink
chore: get rid of some unneeded accessors
Browse files Browse the repository at this point in the history
  • Loading branch information
jacek-prisma committed Dec 11, 2024
1 parent 17c1994 commit dd5f258
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
11 changes: 6 additions & 5 deletions quaint/src/connector/postgres/native/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ mod tests {
let q1 = cache.get_query(&client, sql, &types).await.unwrap();
let q2 = cache.get_query(&client, sql, &types).await.unwrap();
assert!(
std::ptr::eq(q1.metadata(), q2.metadata()),
Arc::ptr_eq(&q1.metadata, &q2.metadata),
"stmt1 and stmt2 should re-use the same metadata"
);

Expand All @@ -324,7 +324,7 @@ mod tests {
// the old query should be evicted from the cache
let q3 = cache.get_query(&client, sql, &types).await.unwrap();
assert!(
!std::ptr::eq(q1.metadata(), q3.metadata()),
!Arc::ptr_eq(&q1.metadata, &q3.metadata),
"stmt1 and stmt3 should not re-use the same metadata"
);
})
Expand All @@ -340,12 +340,13 @@ mod tests {
let types = [Type::INT4];

let q1 = cache.get_query(&client, sql1, &types).await.unwrap();
assert_eq!(q1.query(), sql1);
assert_eq!(q1.sql, sql1);
let q2 = cache.get_query(&client, sql2, &types).await.unwrap();
assert_eq!(q2.query(), sql2);
// the requested query traceparent should be preserved
assert_eq!(q2.sql, sql2);

assert!(
std::ptr::eq(q1.metadata(), q2.metadata()),
Arc::ptr_eq(&q1.metadata, &q2.metadata),
"stmt1 and stmt2 should re-use the same metadata"
);
})
Expand Down
14 changes: 2 additions & 12 deletions quaint/src/connector/postgres/native/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ impl PreparedQuery for Statement {
/// A query combined with the relevant type information about its parameters and columns.
#[derive(Debug)]
pub struct TypedQuery<'a> {
sql: &'a str,
metadata: Arc<QueryMetadata>,
pub(super) sql: &'a str,
pub(super) metadata: Arc<QueryMetadata>,
}

impl<'a> TypedQuery<'a> {
Expand All @@ -58,16 +58,6 @@ impl<'a> TypedQuery<'a> {
metadata: metadata.into(),
}
}

/// Get the SQL string of the query.
pub fn query(&self) -> &'a str {
self.sql
}

/// Get the metadata associated with the query.
pub fn metadata(&self) -> &QueryMetadata {
&self.metadata
}
}

#[async_trait]
Expand Down

0 comments on commit dd5f258

Please sign in to comment.