-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(core): diesel models and db interface changes for call_back_mapper table #6571
base: main
Are you sure you want to change the base?
Changes from 7 commits
c774c2a
c41e062
e3ed4a7
9b1056b
0c4ef49
baf137e
df0e757
c5b7164
75d929b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use diesel::{Identifiable, Insertable, Queryable, Selectable}; | ||
use serde::{self, Deserialize, Serialize}; | ||
use serde_json; | ||
|
||
use crate::schema::call_back_mapper; | ||
|
||
#[derive( | ||
Clone, Debug, Eq, PartialEq, Identifiable, Queryable, Selectable, Serialize, Deserialize, | ||
)] | ||
#[diesel(table_name = call_back_mapper, primary_key(id), check_for_backend(diesel::pg::Pg))] | ||
|
||
pub struct CallBackMapper { | ||
pub id: String, | ||
#[serde(rename = "type")] | ||
pub type_: String, | ||
pub data: serde_json::Value, | ||
pub created_at: time::PrimitiveDateTime, | ||
pub last_modified_at: time::PrimitiveDateTime, | ||
} | ||
|
||
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize, Insertable)] | ||
#[diesel(table_name = call_back_mapper)] | ||
pub struct CallBackMapperNew { | ||
pub id: String, | ||
#[serde(rename = "type")] | ||
pub type_: String, | ||
pub data: serde_json::Value, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use diesel::{associations::HasTable, ExpressionMethods}; | ||
|
||
use super::generics; | ||
use crate::{ | ||
call_back_mapper::{CallBackMapper, CallBackMapperNew}, | ||
schema::call_back_mapper::dsl, | ||
PgPooledConn, StorageResult, | ||
}; | ||
|
||
impl CallBackMapperNew { | ||
pub async fn insert(self, conn: &PgPooledConn) -> StorageResult<CallBackMapper> { | ||
generics::generic_insert(conn, self).await | ||
} | ||
} | ||
|
||
impl CallBackMapper { | ||
pub async fn find_by_id(conn: &PgPooledConn, id: String) -> StorageResult<Self> { | ||
generics::generic_find_one::<<Self as HasTable>::Table, _, _>( | ||
conn, | ||
dsl::id.eq(id.to_owned()), | ||
) | ||
.await | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use error_stack::report; | ||
// use diesel_models::call_back_mapper; | ||
prasunna09 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
use router_env::{instrument, tracing}; | ||
|
||
use super::Store; | ||
use crate::{ | ||
connection, | ||
core::errors::{self, CustomResult}, | ||
types::storage, | ||
}; | ||
|
||
#[async_trait::async_trait] | ||
pub trait CallBackMapperInterface { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we please move the trait CallBackMapperInterface to hyperswitch_domain_models and have the domain models defined for CallBackMapper? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is a db interface, could you please tell me why db interface needs to be moved to domain model? ps. checked all other db interface, no interface lies in domain model. please let me know If I m missing something |
||
async fn insert_call_back_mapper( | ||
&self, | ||
call_back_mapper: storage::CallBackMapperNew, | ||
) -> CustomResult<storage::CallBackMapper, errors::StorageError>; | ||
|
||
async fn find_call_back_mapper_by_id( | ||
&self, | ||
id: String, | ||
) -> CustomResult<storage::CallBackMapper, errors::StorageError>; | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl CallBackMapperInterface for Store { | ||
#[instrument(skip_all)] | ||
async fn insert_call_back_mapper( | ||
&self, | ||
call_back_mapper: storage::CallBackMapperNew, | ||
) -> CustomResult<storage::CallBackMapper, errors::StorageError> { | ||
let conn = connection::pg_connection_write(self).await?; | ||
call_back_mapper | ||
.insert(&conn) | ||
.await | ||
.map_err(|error| report!(errors::StorageError::from(error))) | ||
} | ||
|
||
async fn find_call_back_mapper_by_id( | ||
&self, | ||
id: String, | ||
) -> CustomResult<storage::CallBackMapper, errors::StorageError> { | ||
let conn = connection::pg_connection_read(self).await?; | ||
storage::CallBackMapper::find_by_id(&conn, id) | ||
.await | ||
.map_err(|error| report!(errors::StorageError::from(error))) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub use diesel_models::call_back_mapper::{CallBackMapper, CallBackMapperNew}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-- This file should undo anything in `up.sql` | ||
DROP TABLE IF EXISTS call_back_mapper; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
-- Your SQL goes here | ||
CREATE TABLE IF NOT EXISTS call_back_mapper ( | ||
prasunna09 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
id VARCHAR(128) NOT NULL PRIMARY KEY, | ||
type VARCHAR(64) NOT NULL, | ||
data JSONB NOT NULL, | ||
created_at TIMESTAMP NOT NULL DEFAULT now()::TIMESTAMP, | ||
last_modified_at TIMESTAMP NOT NULL DEFAULT now()::TIMESTAMP | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if there is no sensitive value, is this still needed? Also this table should be used for storing HS entity reference