Skip to content

Commit

Permalink
fix: define aliases and fix some references to PostgreSql
Browse files Browse the repository at this point in the history
  • Loading branch information
jacek-prisma committed Dec 11, 2024
1 parent 853e957 commit 01f7b20
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 18 deletions.
22 changes: 12 additions & 10 deletions quaint/src/connector/postgres/native/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const DB_SYSTEM_NAME_COCKROACHDB: &str = "cockroachdb";

/// A connector interface for the PostgreSQL database.
#[derive(Debug)]
pub struct PostgreSql<QueriesCache = LruPreparedStatementCache, StmtsCache = LruPreparedStatementCache> {
pub struct PostgreSql<QueriesCache, StmtsCache> {
client: PostgresClient,
pg_bouncer: bool,
socket_timeout: Option<Duration>,
Expand All @@ -79,7 +79,9 @@ pub struct PostgreSql<QueriesCache = LruPreparedStatementCache, StmtsCache = Lru
db_system_name: &'static str,
}

pub type PostgreSqlForTracing = PostgreSql<LruTracingCache, NoopPreparedStatementCache>;
pub type PostgreSqlWithDefaultCache = PostgreSql<LruPreparedStatementCache, LruPreparedStatementCache>;
pub type PostgreSqlWithNoCache = PostgreSql<NoopPreparedStatementCache, NoopPreparedStatementCache>;
pub type PostgreSqlWithTracingCache = PostgreSql<LruTracingCache, NoopPreparedStatementCache>;

#[derive(Debug)]
struct SslAuth {
Expand Down Expand Up @@ -216,7 +218,7 @@ impl PostgresNativeUrl {
}
}

impl PostgreSql<LruPreparedStatementCache, LruPreparedStatementCache> {
impl PostgreSqlWithNoCache {
/// Create a new websocket connection to managed database
pub async fn new_with_websocket(url: PostgresWebSocketUrl) -> crate::Result<Self> {
let client = connect_via_websocket(url).await?;
Expand All @@ -225,8 +227,8 @@ impl PostgreSql<LruPreparedStatementCache, LruPreparedStatementCache> {
client: PostgresClient(client),
socket_timeout: None,
pg_bouncer: false,
queries_cache: LruPreparedStatementCache::with_capacity(0),
stmts_cache: LruPreparedStatementCache::with_capacity(0),
queries_cache: NoopPreparedStatementCache,
stmts_cache: NoopPreparedStatementCache,
is_healthy: AtomicBool::new(true),
is_cockroachdb: false,
is_materialize: false,
Expand Down Expand Up @@ -958,7 +960,7 @@ mod tests {

let tls_manager = MakeTlsConnectorManager::new(pg_url.clone());

let client = PostgreSql::new(pg_url, &tls_manager).await.unwrap();
let client = PostgreSqlWithDefaultCache::new(pg_url, &tls_manager).await.unwrap();

let result_set = client.query_raw("SHOW search_path", &[]).await.unwrap();
let row = result_set.first().unwrap();
Expand Down Expand Up @@ -1012,7 +1014,7 @@ mod tests {

let tls_manager = MakeTlsConnectorManager::new(pg_url.clone());

let client = PostgreSql::new(pg_url, &tls_manager).await.unwrap();
let client = PostgreSqlWithDefaultCache::new(pg_url, &tls_manager).await.unwrap();

let result_set = client.query_raw("SHOW search_path", &[]).await.unwrap();
let row = result_set.first().unwrap();
Expand Down Expand Up @@ -1065,7 +1067,7 @@ mod tests {

let tls_manager = MakeTlsConnectorManager::new(pg_url.clone());

let client = PostgreSql::new(pg_url, &tls_manager).await.unwrap();
let client = PostgreSqlWithDefaultCache::new(pg_url, &tls_manager).await.unwrap();

let result_set = client.query_raw("SHOW search_path", &[]).await.unwrap();
let row = result_set.first().unwrap();
Expand Down Expand Up @@ -1118,7 +1120,7 @@ mod tests {

let tls_manager = MakeTlsConnectorManager::new(pg_url.clone());

let client = PostgreSql::new(pg_url, &tls_manager).await.unwrap();
let client = PostgreSqlWithDefaultCache::new(pg_url, &tls_manager).await.unwrap();

let result_set = client.query_raw("SHOW search_path", &[]).await.unwrap();
let row = result_set.first().unwrap();
Expand Down Expand Up @@ -1171,7 +1173,7 @@ mod tests {

let tls_manager = MakeTlsConnectorManager::new(pg_url.clone());

let client = PostgreSql::new(pg_url, &tls_manager).await.unwrap();
let client = PostgreSqlWithDefaultCache::new(pg_url, &tls_manager).await.unwrap();

let result_set = client.query_raw("SHOW search_path", &[]).await.unwrap();
let row = result_set.first().unwrap();
Expand Down
2 changes: 1 addition & 1 deletion quaint/src/connector/postgres/url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ mod tests {
fn should_not_enable_caching_with_pgbouncer() {
let url =
PostgresNativeUrl::new(Url::parse("postgresql:///localhost:5432/foo?pgbouncer=true").unwrap()).unwrap();
assert_eq!(0, url.cache_settings().capacity());
assert_eq!(0, url.cache_settings().capacity);
}

#[test]
Expand Down
8 changes: 4 additions & 4 deletions quaint/src/pooled/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ impl Manager for QuaintManager {
tls_manager,
is_tracing_enabled: false,
} => {
use crate::connector::PostgreSql;
Ok(Box::new(<PostgreSql>::new(url.clone(), tls_manager).await?) as Self::Connection)
use crate::connector::PostgreSqlWithDefaultCache;
Ok(Box::new(PostgreSqlWithDefaultCache::new(url.clone(), tls_manager).await?) as Self::Connection)
}

#[cfg(feature = "postgresql-native")]
Expand All @@ -149,8 +149,8 @@ impl Manager for QuaintManager {
tls_manager,
is_tracing_enabled: true,
} => {
use crate::connector::PostgreSqlForTracing;
Ok(Box::new(PostgreSqlForTracing::new(url.clone(), tls_manager).await?) as Self::Connection)
use crate::connector::PostgreSqlWithTracingCache;
Ok(Box::new(PostgreSqlWithTracingCache::new(url.clone(), tls_manager).await?) as Self::Connection)
}

#[cfg(feature = "mssql-native")]
Expand Down
2 changes: 1 addition & 1 deletion quaint/src/single.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ impl Quaint {
s if s.starts_with("postgres") || s.starts_with("postgresql") => {
let url = connector::PostgresNativeUrl::new(url::Url::parse(s)?)?;
let tls_manager = connector::MakeTlsConnectorManager::new(url.clone());
let psql = <connector::PostgreSql>::new(url, &tls_manager).await?;
let psql = connector::PostgreSqlWithDefaultCache::new(url, &tls_manager).await?;
Arc::new(psql) as Arc<dyn TransactionCapable>
}
#[cfg(feature = "mssql-native")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::sql_renderer::IteratorJoin;

use super::MigratePostgresUrl;

pub(super) struct Connection(connector::PostgreSql);
pub(super) struct Connection(connector::PostgreSqlWithNoCache);

impl Connection {
pub(super) async fn new(url: url::Url) -> ConnectorResult<Connection> {
Expand All @@ -24,7 +24,7 @@ impl Connection {
let quaint = match url.0 {
PostgresUrl::Native(ref native_url) => {
let tls_manager = MakeTlsConnectorManager::new(native_url.as_ref().clone());
connector::PostgreSql::new(native_url.as_ref().clone(), &tls_manager).await
connector::PostgreSqlWithNoCache::new(native_url.as_ref().clone(), &tls_manager).await
}
PostgresUrl::WebSocket(ref ws_url) => connector::PostgreSql::new_with_websocket(ws_url.clone()).await,
}
Expand Down

0 comments on commit 01f7b20

Please sign in to comment.