Defining our create user database transactions
For our database transaction of inserting the user into the database, we need the following imports:
// nanoservices/auth/dal/src/users/transactions/create.rs
use crate::users::schema::{NewUser, User};
use glue::errors::{NanoServiceError, NanoServiceErrorStatus};
use std::future::Future;
use crate::connections::sqlx_postgres::SQLX_POSTGRES_POOL;
use super::super::descriptors::SqlxPostGresDescriptor;
We then must define our trait that is the template for inserting a user with the code below:
// nanoservices/auth/dal/src/users/transactions/create.rs
pub trait SaveOne {
fn save_one(user: NewUser)
-> impl Future<Output = Result<
User, NanoServiceError>
> + Send;
}
We then implement the trait with a placeholder function for our Postgres database descriptor with the following code:
// nanoservices/auth/dal/src/users/transactions/create.rs
impl SaveOne for SqlxPostGresDescriptor {
fn save_one(user: NewUser...