Skip to main content

PostgresDB

Struct PostgresDB 

Source
pub struct PostgresDB {
    pub pool: Pool<Postgres>,
}
Expand description

Struct to handle connections to postgres databases

Fields§

§pool: Pool<Postgres>

pool is made public to allow extending this struct outside of the library

Implementations§

Source§

impl PostgresDB

Source

pub async fn new(connection_string: &str) -> Result<PostgresDB, Error>

Source

pub async fn clean(&self) -> Result<(), Error>

Clean database by dropping all tables and than run init

Source

pub async fn init(&self) -> Result<(), Error>

Initialize new database by creating table

Trait Implementations§

Source§

impl AssetHandler for PostgresDB

Handler for globally available Asset data

Source§

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

Return AssetSelector for all assets

Source§

fn insert_asset<'life0, 'life1, 'async_trait>( &'life0 self, asset: &'life1 Asset, ) -> Pin<Box<dyn Future<Output = Result<i32, DataError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

fn get_asset_id<'life0, 'life1, 'async_trait>( &'life0 self, asset: &'life1 Asset, ) -> Pin<Box<dyn Future<Output = Option<i32>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

fn get_asset_by_id<'life0, 'async_trait>( &'life0 self, id: i32, ) -> Pin<Box<dyn Future<Output = Result<Asset, DataError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn get_asset_by_isin<'life0, 'life1, 'async_trait>( &'life0 self, isin: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Asset, DataError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

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

Return a list of all assets ordered by name
Source§

fn update_asset<'life0, 'life1, 'async_trait>( &'life0 self, asset: &'life1 Asset, ) -> Pin<Box<dyn Future<Output = Result<(), DataError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

fn delete_asset<'life0, 'async_trait>( &'life0 self, id: i32, ) -> Pin<Box<dyn Future<Output = Result<(), DataError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

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

Source§

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

Get a list of currencies as list of AssetSelectors
Source§

fn get_or_new_currency<'life0, 'async_trait>( &'life0 self, iso_code: CurrencyISOCode, ) -> Pin<Box<dyn Future<Output = Result<Currency, DataError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Either read currency from database or create new currency and store it in database with default rounding digits
Source§

fn get_or_new_currency_with_digits<'life0, 'async_trait>( &'life0 self, iso_code: CurrencyISOCode, rounding_digits: i32, ) -> Pin<Box<dyn Future<Output = Result<Currency, DataError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Either read currency from database or create new currency and store it in database. If currency exists already, ignore rounding errors.
Source§

impl ObjectHandler for PostgresDB

Handler for globally available Asset data

Source§

fn store_object<'life0, 'life1, 'life2, 'life3, 'async_trait, T>( &'life0 self, id: &'life1 str, _object_type: &'life2 str, object: &'life3 T, ) -> Pin<Box<dyn Future<Output = Result<(), DataError>> + Send + 'async_trait>>
where T: 'async_trait + Serialize + Sync, Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Source§

fn get_object<'life0, 'life1, 'async_trait, T>( &'life0 self, id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<T, DataError>> + Send + 'async_trait>>
where T: 'async_trait + DeserializeOwned, Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

impl QuoteHandler for PostgresDB

PostgreSQL implementation of quote handler

Source§

fn into_arc_dispatch(self: Arc<Self>) -> Arc<dyn AssetHandler + Send + Sync>

Source§

fn insert_ticker<'life0, 'life1, 'async_trait>( &'life0 self, ticker: &'life1 Ticker, ) -> Pin<Box<dyn Future<Output = Result<i32, DataError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

fn get_ticker_id<'life0, 'life1, 'async_trait>( &'life0 self, ticker: &'life1 str, ) -> Pin<Box<dyn Future<Output = Option<i32>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

fn insert_if_new_ticker<'life0, 'life1, 'async_trait>( &'life0 self, ticker: &'life1 Ticker, ) -> Pin<Box<dyn Future<Output = Result<i32, DataError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

fn get_ticker_by_id<'life0, 'async_trait>( &'life0 self, id: i32, ) -> Pin<Box<dyn Future<Output = Result<Ticker, DataError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

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

Source§

fn get_all_ticker_for_source<'life0, 'life1, 'async_trait>( &'life0 self, source: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Vec<Ticker>, DataError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

fn get_all_ticker_for_asset<'life0, 'async_trait>( &'life0 self, asset_id: i32, ) -> Pin<Box<dyn Future<Output = Result<Vec<Ticker>, DataError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Get all ticker that belong to a given asset specified by its asset ID
Source§

fn update_ticker<'life0, 'life1, 'async_trait>( &'life0 self, ticker: &'life1 Ticker, ) -> Pin<Box<dyn Future<Output = Result<(), DataError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

fn delete_ticker<'life0, 'async_trait>( &'life0 self, id: i32, ) -> Pin<Box<dyn Future<Output = Result<(), DataError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn insert_quote<'life0, 'life1, 'async_trait>( &'life0 self, quote: &'life1 Quote, ) -> Pin<Box<dyn Future<Output = Result<i32, DataError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Insert, get, update and delete for market data sources
Source§

fn get_last_fx_quote_before<'life0, 'life1, 'async_trait>( &'life0 self, curr: &'life1 CurrencyISOCode, time: DateTime<Local>, ) -> Pin<Box<dyn Future<Output = Result<(Quote, Currency), DataError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get the last quote in database for a specific currency iso code on or before the given time
Source§

fn get_last_quote_before_by_id<'life0, 'async_trait>( &'life0 self, asset_id: i32, time: DateTime<Local>, ) -> Pin<Box<dyn Future<Output = Result<(Quote, Currency), DataError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Get the last quote in database for a specific asset id on or before the given time
Source§

fn get_quotes_in_range_by_id<'life0, 'async_trait>( &'life0 self, asset_id: i32, start: DateTime<Local>, end: DateTime<Local>, ) -> Pin<Box<dyn Future<Output = Result<Vec<(Quote, i32)>, DataError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Get all quotes within a time range for a specific asset id
Source§

fn get_all_quotes_for_ticker<'life0, 'async_trait>( &'life0 self, ticker_id: i32, ) -> Pin<Box<dyn Future<Output = Result<Vec<Quote>, DataError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn update_quote<'life0, 'life1, 'async_trait>( &'life0 self, quote: &'life1 Quote, ) -> Pin<Box<dyn Future<Output = Result<(), DataError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

fn delete_quote<'life0, 'async_trait>( &'life0 self, id: i32, ) -> Pin<Box<dyn Future<Output = Result<(), DataError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

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

Source§

impl TransactionHandler for PostgresDB

Handler for globally available data

Source§

fn insert_transaction<'life0, 'life1, 'async_trait>( &'life0 self, transaction: &'life1 Transaction, ) -> Pin<Box<dyn Future<Output = Result<i32, DataError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

fn get_transaction_by_id<'life0, 'async_trait>( &'life0 self, id: i32, ) -> Pin<Box<dyn Future<Output = Result<Transaction, DataError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

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

Source§

fn update_transaction<'life0, 'life1, 'async_trait>( &'life0 self, transaction: &'life1 Transaction, ) -> Pin<Box<dyn Future<Output = Result<(), DataError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

fn delete_transaction<'life0, 'async_trait>( &'life0 self, id: i32, ) -> Pin<Box<dyn Future<Output = Result<(), DataError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

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.

Source§

impl<T> Instrument for T

Source§

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

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

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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

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>,

Source§

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.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<T> DeserializeOwnedAlias for T

Source§

impl<T> SendAlias for T

Source§

impl<T> SerializeAlias for T

Source§

impl<T> SyncAlias for T