Struct sql_abstractor::Postgres

source ·
pub struct Postgres { /* private fields */ }
Expand description

Postgress implementation.

It’s a wrapper around sqlx::postgres

§Examples

It implemeents orchestrator memory abstraction, that means that could be used as:

use sql_abstractor::Postgres;
use orchestrator::prelude::*;
 
GenerateState!(ExerciseResult, DummyExercise);
let m = Box::new(
    Postgres::clean_init("postgresql://postgres:test@localhost:5432/thesis")
    .await
    .unwrap(),
);
let mut o: Orchestrator<State> = Orchestrator::new(1, m);
o.run().await;

Implementations§

source§

impl Postgres

implement some initialization

source

pub async fn init(builder: &str) -> Result<Self, Error>

initialize connector It could be used multiple times without loosing any data.

This is the correct way to obtain Self

source

pub async fn clean_init(builder: &str) -> Result<Self, Error>

WARNING: THIS WILL ERASE ALL THE DATA CONTAINED IN THE DATABASE, AND THEN INIT

Trait Implementations§

source§

impl<S: ExecutorGlobalState> StateMemory<S> for Postgres

state memory implementation

source§

fn get_exercise<'life0, 'async_trait>( &'life0 self, name: String, ) -> Pin<Box<dyn Future<Output = Result<(TypeId, String), Box<dyn StdError + Send + Sync + 'static>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

get an exercise from memory type, source

source§

fn enable_executor<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, input: &'life1 S, output: &'life2 S, data: String, ) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn StdError + Send + Sync + 'static>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

used to enable a particular executor
source§

fn get_execution_plan<'life0, 'life1, 'async_trait>( &'life0 self, input: &'life1 S, ) -> Pin<Box<dyn Future<Output = Result<Vec<(TypeId, TypeId, String)>, Box<dyn StdError + Send + Sync + 'static>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

from a particular state, which executor will be triggered? in which order?
source§

fn add_exercise<'life0, 'async_trait>( &'life0 self, name: String, exercise_type: S, source: String, ) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn StdError + Send + Sync + 'static>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

add an exercise to memory
source§

impl StatelessMemory for Postgres

implementation of the StatelessMemory trait

source§

fn login<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, username: &'life1 str, password: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<User<Authenticated>, Box<dyn StdError>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

tries to login the current user, returning an authenticated user instance

source§

fn get_by_username<'life0, 'life1, 'async_trait>( &'life0 self, username: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<User<Unauthenticated>, Box<dyn StdError>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

gets a user by his username

source§

fn get_all_users<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<User<Unauthenticated>>, Box<dyn StdError>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

returns all user present in the DB.

source§

fn get_authenticate<'life0, 'life1, 'async_trait>( &'life0 self, token: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<User<Authenticated>, Box<dyn StdError>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

check if the given token is valid, and if so returns the correct user

source§

fn get_admin<'life0, 'life1, 'async_trait>( &'life0 self, token: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<User<Admin>, Box<dyn StdError>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

if the token is valid, it get’s the user, and if so checks if it is an Admin

source§

fn add_submission<'life0, 'async_trait>( &'life0 self, exercise_name: String, source: String, user: User<Authenticated>, ) -> Pin<Box<dyn Future<Output = Result<i64, Box<dyn StdError + Send + Sync>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

add submission (on success returns submission id)

source§

fn add_exercise_result<'life0, 'async_trait>( &'life0 self, submission_id: i64, user: User<Authenticated>, result: ExerciseResult, ) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn StdError + Send + Sync>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

add exercise result

source§

fn register<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, username: &'life1 str, password: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<User<Unauthenticated>, Box<dyn StdError>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

register User, it should not authenticate it
source§

fn list_exercise_names<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<String>, Box<dyn StdError>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

list exercises names

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<S, Cur> Memory<S> for Cur
where S: ExecutorGlobalState, Cur: StateMemory<S> + StatelessMemory,

§

fn as_stateless(&self) -> &dyn StatelessMemory

conversion into a StatelessMemory
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more