Skip to content

Instantly share code, notes, and snippets.

@butlerx
Last active April 1, 2018 11:51
Show Gist options
  • Save butlerx/b45cbc34ce8ad72389414068e7a0dc2c to your computer and use it in GitHub Desktop.
Save butlerx/b45cbc34ce8ad72389414068e7a0dc2c to your computer and use it in GitHub Desktop.
stv_db
use std::time::SystemTime;
#[derive(Queryable)]
pub struct Election {
pub id: i32,
pub title: String,
pub draft: bool,
pub candidates: Vec<i32>,
pub created_at: SystemTime,
pub started_at: SystemTime,
pub finished_at: SystemTime,
}
#[derive(Queryable)]
pub struct Ballot {
pub ballot_id: i32,
pub created_at: SystemTime,
pub user_id: i32,
pub election_id: i32,
pub preference: Vec<i32>,
}
#[derive(Queryable)]
pub struct Voter {
pub user_id: i32,
pub user_name: String,
}
#[derive(Queryable)]
pub struct Candidate {
pub candidate_id: i32,
pub name: String,
}
table! {
election(id) {
id -> Integer,
title -> Text,
draft -> Bool,
candidates -> Array<Integer>,
created_at -> Timestamp,
started_at -> Timestamp,
finished_at -> Timestamp,
}
}
table! {
ballot(ballot_id) {
ballot_id -> Integer,
created_at -> Timestamp,
user_id -> Integer,
election_id -> Integer,
preference -> Array<Integer>,
}
}
table! {
voter(user_id) {
user_id -> Integer,
user_name -> Text,
}
}
table! {
candidate(candidate_id) {
candidate_id -> Integer,
name -> Text,
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment