refactor: get connection pool based on olap/oltp features (#743)

This commit is contained in:
Kartikeya Hegde
2023-03-20 11:35:10 +05:30
committed by GitHub
parent 853dfa1635
commit a392fb165d
18 changed files with 147 additions and 146 deletions

View File

@ -2,7 +2,7 @@ use error_stack::IntoReport;
use super::{MockDb, Store};
use crate::{
connection::pg_connection,
connection,
core::errors::{self, CustomResult},
types::storage,
};
@ -46,7 +46,7 @@ impl ApiKeyInterface for Store {
&self,
api_key: storage::ApiKeyNew,
) -> CustomResult<storage::ApiKey, errors::StorageError> {
let conn = pg_connection(&self.master_pool).await?;
let conn = connection::pg_connection_write(self).await?;
api_key
.insert(&conn)
.await
@ -59,7 +59,7 @@ impl ApiKeyInterface for Store {
key_id: String,
api_key: storage::ApiKeyUpdate,
) -> CustomResult<storage::ApiKey, errors::StorageError> {
let conn = pg_connection(&self.master_pool).await?;
let conn = connection::pg_connection_write(self).await?;
storage::ApiKey::update_by_key_id(&conn, key_id, api_key)
.await
.map_err(Into::into)
@ -67,7 +67,7 @@ impl ApiKeyInterface for Store {
}
async fn revoke_api_key(&self, key_id: &str) -> CustomResult<bool, errors::StorageError> {
let conn = pg_connection(&self.master_pool).await?;
let conn = connection::pg_connection_write(self).await?;
storage::ApiKey::revoke_by_key_id(&conn, key_id)
.await
.map_err(Into::into)
@ -78,7 +78,7 @@ impl ApiKeyInterface for Store {
&self,
key_id: &str,
) -> CustomResult<Option<storage::ApiKey>, errors::StorageError> {
let conn = pg_connection(&self.master_pool).await?;
let conn = connection::pg_connection_read(self).await?;
storage::ApiKey::find_optional_by_key_id(&conn, key_id)
.await
.map_err(Into::into)
@ -89,7 +89,7 @@ impl ApiKeyInterface for Store {
&self,
hashed_api_key: storage::HashedApiKey,
) -> CustomResult<Option<storage::ApiKey>, errors::StorageError> {
let conn = pg_connection(&self.master_pool).await?;
let conn = connection::pg_connection_read(self).await?;
storage::ApiKey::find_optional_by_hashed_api_key(&conn, hashed_api_key)
.await
.map_err(Into::into)
@ -102,7 +102,7 @@ impl ApiKeyInterface for Store {
limit: Option<i64>,
offset: Option<i64>,
) -> CustomResult<Vec<storage::ApiKey>, errors::StorageError> {
let conn = pg_connection(&self.master_pool).await?;
let conn = connection::pg_connection_read(self).await?;
storage::ApiKey::find_by_merchant_id(&conn, merchant_id, limit, offset)
.await
.map_err(Into::into)