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
impl EventDB
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;"
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;"
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;"
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
impl EventDB
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;"
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
impl EventDB
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;"
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
impl EventDB
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;"
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;"
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
impl EventDB
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;"
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;"
const EVENT_GOALS_QUERY: &'static str = "SELECT goal.idx, goal.name FROM goal WHERE goal.event_id = $1;"
source§impl EventDB
impl EventDB
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;"
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;"
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;"
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;"
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;"
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;"
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;"
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;"
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;"
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
impl EventDB
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"
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"
const SEARCH_PROPOSALS_QUERY: &'static str = "SELECT DISTINCT proposal.id, proposal.title, proposal.summary, proposal.deleted FROM proposal"
fn build_where_clause(table: &str, filter: &[SearchConstraint]) -> String
fn build_order_by_clause(table: &str, order_by: &[SearchOrderBy]) -> String
fn contruct_query(search_query: &SearchQuery) -> String
fn contruct_count_query(search_query: &SearchQuery) -> String
source§impl EventDB
impl EventDB
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;"
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;"
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;"
const FUND_GOALS_QUERY: &'static str = "SELECT id, name AS goal_name FROM goal WHERE goal.event_id = $1;"
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
impl BallotQueries for EventDB
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,
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,
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
impl EventQueries for EventDB
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,
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
impl ObjectiveQueries for EventDB
source§impl ProposalQueries for EventDB
impl ProposalQueries for EventDB
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,
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
impl RegistrationQueries for EventDB
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,
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
impl ReviewQueries for EventDB
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,
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
impl SchemaVersion for EventDB
source§impl SearchQueries for EventDB
impl SearchQueries for EventDB
source§impl VitSSFundQueries for EventDB
impl VitSSFundQueries for EventDB
impl EventDbQueries for EventDB
Auto Trait Implementations§
impl !RefUnwindSafe for EventDB
impl Send for EventDB
impl Sync for EventDB
impl Unpin for EventDB
impl !UnwindSafe for EventDB
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more