diff --git a/quaint/src/connector/postgres/native/mod.rs b/quaint/src/connector/postgres/native/mod.rs index ba2f401b0e8..8f0ae1ca2a0 100644 --- a/quaint/src/connector/postgres/native/mod.rs +++ b/quaint/src/connector/postgres/native/mod.rs @@ -67,7 +67,7 @@ const DB_SYSTEM_NAME_COCKROACHDB: &str = "cockroachdb"; /// A connector interface for the PostgreSQL database. #[derive(Debug)] -pub struct PostgreSql { +pub struct PostgreSql { client: PostgresClient, pg_bouncer: bool, socket_timeout: Option, @@ -79,7 +79,9 @@ pub struct PostgreSql; +pub type PostgreSqlWithDefaultCache = PostgreSql; +pub type PostgreSqlWithNoCache = PostgreSql; +pub type PostgreSqlWithTracingCache = PostgreSql; #[derive(Debug)] struct SslAuth { @@ -216,7 +218,7 @@ impl PostgresNativeUrl { } } -impl PostgreSql { +impl PostgreSqlWithNoCache { /// Create a new websocket connection to managed database pub async fn new_with_websocket(url: PostgresWebSocketUrl) -> crate::Result { let client = connect_via_websocket(url).await?; @@ -225,8 +227,8 @@ impl PostgreSql { 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, @@ -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(); @@ -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(); @@ -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(); @@ -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(); @@ -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(); diff --git a/quaint/src/connector/postgres/url.rs b/quaint/src/connector/postgres/url.rs index 19dae0066be..c35c123b439 100644 --- a/quaint/src/connector/postgres/url.rs +++ b/quaint/src/connector/postgres/url.rs @@ -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] diff --git a/quaint/src/pooled/manager.rs b/quaint/src/pooled/manager.rs index 5d93d1be58b..4b13ca26bd2 100644 --- a/quaint/src/pooled/manager.rs +++ b/quaint/src/pooled/manager.rs @@ -139,8 +139,8 @@ impl Manager for QuaintManager { tls_manager, is_tracing_enabled: false, } => { - use crate::connector::PostgreSql; - Ok(Box::new(::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")] @@ -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")] diff --git a/quaint/src/single.rs b/quaint/src/single.rs index 9743d69368a..d4d48eff73d 100644 --- a/quaint/src/single.rs +++ b/quaint/src/single.rs @@ -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 = ::new(url, &tls_manager).await?; + let psql = connector::PostgreSqlWithDefaultCache::new(url, &tls_manager).await?; Arc::new(psql) as Arc } #[cfg(feature = "mssql-native")] diff --git a/schema-engine/connectors/sql-schema-connector/src/flavour/postgres/connection.rs b/schema-engine/connectors/sql-schema-connector/src/flavour/postgres/connection.rs index 3a8f9fb6517..59325574d79 100644 --- a/schema-engine/connectors/sql-schema-connector/src/flavour/postgres/connection.rs +++ b/schema-engine/connectors/sql-schema-connector/src/flavour/postgres/connection.rs @@ -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 { @@ -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, }