Struct event_db::EventDB

source ·
pub struct EventDB {
    pub(crate) pool: Pool<PostgresConnectionManager<NoTls>>,
}
Expand description

Connection to the Election Database

Fields§

§pool: Pool<PostgresConnectionManager<NoTls>>

Implementations§

source§

impl EventDB

source

const BALLOT_VOTE_OPTIONS_QUERY: &'static str = "SELECT vote_options.objective FROM proposal INNER JOIN objective ON proposal.objective = objective.row_id INNER JOIN vote_options ON objective.vote_options = vote_options.id WHERE objective.event = $1 AND objective.id = $2 AND proposal.id = $3;"

source

const BALLOT_VOTE_PLANS_QUERY: &'static str = "SELECT proposal_voteplan.bb_proposal_index, voteplan.id, voteplan.category, voteplan.encryption_key, voteplan.group_id FROM proposal_voteplan INNER JOIN proposal ON proposal_voteplan.proposal_id = proposal.row_id INNER JOIN voteplan ON proposal_voteplan.voteplan_id = voteplan.row_id INNER JOIN objective ON proposal.objective = objective.row_id WHERE objective.event = $1 AND objective.id = $2 AND proposal.id = $3;"

source

const BALLOTS_VOTE_OPTIONS_PER_OBJECTIVE_QUERY: &'static str = "SELECT vote_options.objective, proposal.id as proposal_id FROM proposal INNER JOIN objective ON proposal.objective = objective.row_id INNER JOIN vote_options ON objective.vote_options = vote_options.id WHERE objective.event = $1 AND objective.id = $2;"

source

const BALLOTS_VOTE_OPTIONS_PER_EVENT_QUERY: &'static str = "SELECT vote_options.objective, proposal.id as proposal_id, objective.id as objective_id FROM proposal INNER JOIN objective ON proposal.objective = objective.row_id INNER JOIN vote_options ON objective.vote_options = vote_options.id WHERE objective.event = $1;"

source§

impl EventDB

source

const OBJECTIVES_QUERY: &'static str = "SELECT objective.row_id, objective.id, objective.title, objective.description, objective.deleted, objective.rewards_currency, objective.rewards_total, objective.extra, objective_category.name, objective_category.description as objective_category_description FROM objective INNER JOIN objective_category on objective.category = objective_category.name WHERE objective.event = $1 LIMIT $2 OFFSET $3;"

source

const VOTING_GROPUS_QEURY: &'static str = "SELECT voteplan.group_id as group, voteplan.token_id as voting_token FROM voteplan WHERE objective_id = $1;"

source§

impl EventDB

source

const PROPOSALS_QUERY: &'static str = "SELECT proposal.id, proposal.title, proposal.summary, proposal.deleted FROM proposal INNER JOIN objective on proposal.objective = objective.row_id WHERE objective.event = $1 AND objective.id = $2 LIMIT $3 OFFSET $4;"

source

const PROPOSAL_QUERY: &'static str = "SELECT proposal.id, proposal.title, proposal.summary, proposal.deleted, proposal.extra, proposal.funds, proposal.url, proposal.files_url, proposal.proposer_name, proposal.proposer_contact, proposal.proposer_url, proposal.public_key FROM proposal INNER JOIN objective on proposal.objective = objective.row_id WHERE objective.event = $1 AND objective.id = $2 AND proposal.id = $3;"

source§

impl EventDB

source

const REVIEWS_QUERY: &'static str = "SELECT proposal_review.row_id, proposal_review.assessor FROM proposal_review INNER JOIN proposal on proposal.row_id = proposal_review.proposal_id INNER JOIN objective on proposal.objective = objective.row_id WHERE objective.event = $1 AND objective.id = $2 AND proposal.id = $3 LIMIT $4 OFFSET $5;"

source

const RATINGS_PER_REVIEW_QUERY: &'static str = "SELECT review_rating.metric, review_rating.rating, review_rating.note FROM review_rating WHERE review_rating.review_id = $1;"

source

const REVIEW_TYPES_QUERY: &'static str = "SELECT review_metric.row_id, review_metric.name, review_metric.description, review_metric.min, review_metric.max, review_metric.map, objective_review_metric.note, objective_review_metric.review_group FROM review_metric INNER JOIN objective_review_metric on review_metric.row_id = objective_review_metric.metric INNER JOIN objective on objective_review_metric.objective = objective.row_id WHERE objective.event = $1 AND objective.id = $2 LIMIT $3 OFFSET $4;"

source§

impl EventDB

source

const EVENTS_QUERY: &'static str = "SELECT event.row_id, event.name, event.start_time, event.end_time, snapshot.last_updated FROM event LEFT JOIN snapshot ON event.row_id = snapshot.event ORDER BY event.row_id ASC LIMIT $1 OFFSET $2;"

source

const EVENT_QUERY: &'static str = "SELECT event.row_id, event.name, event.start_time, event.end_time, event.snapshot_start, event.registration_snapshot_time, event.voting_power_threshold, event.max_voting_power_pct, event.insight_sharing_start, event.proposal_submission_start, event.refine_proposals_start, event.finalize_proposals_start, event.proposal_assessment_start, event.assessment_qa_start, event.voting_start, event.voting_end, event.tallying_end, snapshot.last_updated FROM event LEFT JOIN snapshot ON event.row_id = snapshot.event WHERE event.row_id = $1;"

source

const EVENT_GOALS_QUERY: &'static str = "SELECT goal.idx, goal.name FROM goal WHERE goal.event_id = $1;"

source§

impl EventDB

source

const VOTER_BY_EVENT_QUERY: &'static str = "SELECT voter.voting_key, voter.voting_group, voter.voting_power, snapshot.as_at, snapshot.last_updated, snapshot.final, SUM(contribution.value)::BIGINT as delegations_power, COUNT(contribution.value) AS delegations_count FROM voter INNER JOIN snapshot ON voter.snapshot_id = snapshot.row_id INNER JOIN contribution ON contribution.snapshot_id = snapshot.row_id WHERE voter.voting_key = $1 AND contribution.voting_key = $1 AND snapshot.event = $2 GROUP BY voter.voting_key, voter.voting_group, voter.voting_power, snapshot.as_at, snapshot.last_updated, snapshot.final;"

source

const VOTER_BY_LAST_EVENT_QUERY: &'static str = "SELECT snapshot.event, voter.voting_key, voter.voting_group, voter.voting_power, snapshot.as_at, snapshot.last_updated, snapshot.final, SUM(contribution.value)::BIGINT as delegations_power, COUNT(contribution.value) AS delegations_count FROM voter INNER JOIN snapshot ON voter.snapshot_id = snapshot.row_id INNER JOIN contribution ON contribution.snapshot_id = snapshot.row_id WHERE voter.voting_key = $1 AND contribution.voting_key = $1 AND snapshot.last_updated = (SELECT MAX(snapshot.last_updated) as last_updated from snapshot) GROUP BY snapshot.event, voter.voting_key, voter.voting_group, voter.voting_power, snapshot.as_at, snapshot.last_updated, snapshot.final;"

source

const VOTER_DELEGATORS_LIST_QUERY: &'static str = "SELECT contribution.stake_public_key FROM contribution INNER JOIN snapshot ON contribution.snapshot_id = snapshot.row_id WHERE contribution.voting_key = $1 AND snapshot.event = $2;"

source

const TOTAL_BY_EVENT_VOTING_QUERY: &'static str = "SELECT SUM(voter.voting_power)::BIGINT as total_voting_power FROM voter INNER JOIN snapshot ON voter.snapshot_id = snapshot.row_id WHERE voter.voting_group = $1 AND snapshot.event = $2;"

source

const TOTAL_BY_LAST_EVENT_VOTING_QUERY: &'static str = "SELECT SUM(voter.voting_power)::BIGINT as total_voting_power FROM voter INNER JOIN snapshot ON voter.snapshot_id = snapshot.row_id AND snapshot.last_updated = (SELECT MAX(snapshot.last_updated) as last_updated from snapshot) WHERE voter.voting_group = $1;"

source

const DELEGATOR_SNAPSHOT_INFO_BY_EVENT_QUERY: &'static str = " SELECT snapshot.as_at, snapshot.last_updated, snapshot.final FROM snapshot WHERE snapshot.event = $1 LIMIT 1;"

source

const DELEGATOR_SNAPSHOT_INFO_BY_LAST_EVENT_QUERY: &'static str = "SELECT snapshot.event, snapshot.as_at, snapshot.last_updated, snapshot.final FROM snapshot WHERE snapshot.last_updated = (SELECT MAX(snapshot.last_updated) as last_updated from snapshot) LIMIT 1;"

source

const DELEGATIONS_BY_EVENT_QUERY: &'static str = "SELECT contribution.voting_key, contribution.voting_group, contribution.voting_weight, contribution.value, contribution.reward_address FROM contribution INNER JOIN snapshot ON contribution.snapshot_id = snapshot.row_id WHERE contribution.stake_public_key = $1 AND snapshot.event = $2;"

source

const TOTAL_POWER_BY_EVENT_QUERY: &'static str = "SELECT SUM(voter.voting_power)::BIGINT as total_voting_power FROM voter INNER JOIN snapshot ON voter.snapshot_id = snapshot.row_id WHERE snapshot.event = $1;"

source

const TOTAL_POWER_BY_LAST_EVENT_QUERY: &'static str = "SELECT SUM(voter.voting_power)::BIGINT as total_voting_power FROM voter INNER JOIN snapshot ON voter.snapshot_id = snapshot.row_id WHERE snapshot.last_updated = (SELECT MAX(snapshot.last_updated) as last_updated from snapshot);"

source§

impl EventDB

source

const SEARCH_EVENTS_QUERY: &'static str = "SELECT event.row_id, event.name, event.start_time, event.end_time, snapshot.last_updated FROM event LEFT JOIN snapshot ON event.row_id = snapshot.event"

source

const SEARCH_OBJECTIVES_QUERY: &'static str = "SELECT objective.id, objective.title, objective.description, objective.deleted, objective_category.name, objective_category.description as objective_category_description FROM objective INNER JOIN objective_category on objective.category = objective_category.name"

source

const SEARCH_PROPOSALS_QUERY: &'static str = "SELECT DISTINCT proposal.id, proposal.title, proposal.summary, proposal.deleted FROM proposal"

source

fn build_where_clause(table: &str, filter: &[SearchConstraint]) -> String

source

fn build_order_by_clause(table: &str, order_by: &[SearchOrderBy]) -> String

source

fn contruct_query(search_query: &SearchQuery) -> String

source

fn contruct_count_query(search_query: &SearchQuery) -> String

source§

impl EventDB

source

const FUND_QUERY: &'static str = "SELECT this_fund.row_id AS id, this_fund.name AS fund_name, this_fund.description AS fund_goal, this_fund.registration_snapshot_time AS registration_snapshot_time, this_fund.voting_power_threshold AS voting_power_threshold, this_fund.start_time AS fund_start_time, this_fund.end_time AS fund_end_time, this_fund.insight_sharing_start AS insight_sharing_start, this_fund.proposal_submission_start AS proposal_submission_start, this_fund.refine_proposals_start AS refine_proposals_start, this_fund.finalize_proposals_start AS finalize_proposals_start, this_fund.proposal_assessment_start AS proposal_assessment_start, this_fund.assessment_qa_start AS assessment_qa_start, this_fund.snapshot_start AS snapshot_start, this_fund.voting_start AS voting_start, this_fund.voting_end AS voting_end, this_fund.tallying_end AS tallying_end, (this_fund.extra->'url'->'results') #>> '{}' AS results_url, (this_fund.extra->'url'->'survey') #>> '{}' AS survey_url, next_fund.row_id AS next_id, next_fund.start_time AS next_fund_start_time, next_fund.registration_snapshot_time AS next_registration_snapshot_time, next_fund.name AS next_fund_name, next_fund.insight_sharing_start AS next_insight_sharing_start, next_fund.proposal_submission_start AS next_proposal_submission_start, next_fund.refine_proposals_start AS next_refine_proposals_start, next_fund.finalize_proposals_start AS next_finalize_proposals_start, next_fund.proposal_assessment_start AS next_proposal_assessment_start, next_fund.assessment_qa_start AS next_assessment_qa_start, next_fund.snapshot_start AS next_snapshot_start, next_fund.voting_start AS next_voting_start, next_fund.voting_end AS next_voting_end, next_fund.tallying_end AS next_tallying_end FROM event this_fund LEFT JOIN event next_fund ON next_fund.row_id = this_fund.row_id + 1 WHERE this_fund.end_time > CURRENT_TIMESTAMP AT TIME ZONE 'UTC' AND this_fund.start_time < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' ORDER BY this_fund.row_id DESC LIMIT 1;"

source

const FUND_VOTE_PLANS_QUERY: &'static str = "SELECT voteplan.row_id AS id, voteplan.id AS chain_voteplan_id, voteplan.category AS chain_voteplan_payload, voteplan.encryption_key AS chain_vote_encryption_key, event.row_id AS fund_id, voteplan.token_id AS token_identifier FROM voteplan INNER JOIN objective ON voteplan.objective_id = objective.row_id INNER JOIN event ON objective.event = event.row_id WHERE event.row_id = $1;"

source

const FUND_CHALLENGES_QUERY: &'static str = "SELECT objective.row_id AS internal_id, objective.id AS id, objective.category AS challenge_type, objective.title AS title, objective.description AS description, objective.rewards_total AS rewards_total, objective.proposers_rewards AS proposers_rewards, (objective.extra->'url') #>> '{}' AS challenge_url, (objective.extra->'sponsor') #>> '{}' AS highlights FROM objective WHERE objective.event = $1;"

source

const FUND_GOALS_QUERY: &'static str = "SELECT id, name AS goal_name FROM goal WHERE goal.event_id = $1;"

source

const FUND_GROUPS_QUERY: &'static str = "SELECT voteplan.token_id AS token_identifier, voting_group.name AS group_id FROM voting_group INNER JOIN voteplan ON voteplan.group_id = voting_group.name INNER JOIN objective ON voteplan.objective_id = objective.row_id WHERE objective.event = $1;"

Trait Implementations§

source§

impl BallotQueries for EventDB

source§

fn get_ballot<'life0, 'async_trait>( &'life0 self, event: EventId, objective: ObjectiveId, proposal: ProposalId ) -> Pin<Box<dyn Future<Output = Result<Ballot, Error>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,

source§

fn get_objective_ballots<'life0, 'async_trait>( &'life0 self, event: EventId, objective: ObjectiveId ) -> Pin<Box<dyn Future<Output = Result<Vec<ProposalBallot>, Error>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,

source§

fn get_event_ballots<'life0, 'async_trait>( &'life0 self, event: EventId ) -> Pin<Box<dyn Future<Output = Result<Vec<ObjectiveBallots>, Error>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,

source§

impl EventQueries for EventDB

source§

fn get_events<'life0, 'async_trait>( &'life0 self, limit: Option<i64>, offset: Option<i64> ) -> Pin<Box<dyn Future<Output = Result<Vec<EventSummary>, Error>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,

source§

fn get_event<'life0, 'async_trait>( &'life0 self, event: EventId ) -> Pin<Box<dyn Future<Output = Result<Event, Error>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,

source§

impl ObjectiveQueries for EventDB

source§

fn get_objectives<'life0, 'async_trait>( &'life0 self, event: EventId, limit: Option<i64>, offset: Option<i64> ) -> Pin<Box<dyn Future<Output = Result<Vec<Objective>, Error>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,

source§

impl ProposalQueries for EventDB

source§

fn get_proposal<'life0, 'async_trait>( &'life0 self, event: EventId, objective: ObjectiveId, proposal: ProposalId ) -> Pin<Box<dyn Future<Output = Result<Proposal, Error>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,

source§

fn get_proposals<'life0, 'async_trait>( &'life0 self, event: EventId, objective: ObjectiveId, limit: Option<i64>, offset: Option<i64> ) -> Pin<Box<dyn Future<Output = Result<Vec<ProposalSummary>, Error>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,

source§

impl RegistrationQueries for EventDB

source§

fn get_voter<'life0, 'life1, 'async_trait>( &'life0 self, event: &'life1 Option<EventId>, voting_key: String, with_delegations: bool ) -> Pin<Box<dyn Future<Output = Result<Voter, Error>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

source§

fn get_delegator<'life0, 'life1, 'async_trait>( &'life0 self, event: &'life1 Option<EventId>, stake_public_key: String ) -> Pin<Box<dyn Future<Output = Result<Delegator, Error>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

source§

impl ReviewQueries for EventDB

source§

fn get_reviews<'life0, 'async_trait>( &'life0 self, event: EventId, objective: ObjectiveId, proposal: ProposalId, limit: Option<i64>, offset: Option<i64> ) -> Pin<Box<dyn Future<Output = Result<Vec<AdvisorReview>, Error>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,

source§

fn get_review_types<'life0, 'async_trait>( &'life0 self, event: EventId, objective: ObjectiveId, limit: Option<i64>, offset: Option<i64> ) -> Pin<Box<dyn Future<Output = Result<Vec<ReviewType>, Error>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,

source§

impl SchemaVersion for EventDB

source§

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

Check the schema version. return the current schema version if its current. Otherwise return an error.
source§

impl SearchQueries for EventDB

source§

fn search<'life0, 'async_trait>( &'life0 self, search_query: SearchQuery, total: bool, limit: Option<i64>, offset: Option<i64> ) -> Pin<Box<dyn Future<Output = Result<SearchResult, Error>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,

source§

impl VitSSFundQueries for EventDB

source§

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

source§

impl EventDbQueries for EventDB

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for Twhere 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 Twhere 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 Twhere 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