Adding get by unique ID to dal
At this point, we are going to build on what we have already done, meaning that we are going to define a trait, and implement that trait for our Postgres descriptor. With our plan, our trait takes the following form:
// nanoservices/auth/dal/src/users/transactions/get.rs
pub trait GetByUniqueId {
fn get_by_unique_id(id: String) ->
impl Future<Output = Result<User, NanoServiceError>> + Send;
}
Our trait implementation can be achieved with the code below:
// nanoservices/auth/dal/src/users/transactions/get.rs
impl GetByUniqueId for SqlxPostGresDescriptor {
fn get_by_unique_id(id: String)
-> impl Future<Output = Result<User, NanoServiceError>> + Send {
sqlx_postgres_get_by_unique_id(id)
}
}
And finally, our function that makes the database call is achieved with the following code:
// nanoservices/auth/dal/src/users/transactions/get.rs
async fn sqlx_postgres_get_by_unique_id(id: String)
->...