From 72691c8d6386678be51c71d62e50d168d8fe28bb Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Sun, 8 Apr 2018 15:49:19 +0200 Subject: [PATCH] feat(models/schema): Map up posts & threads table --- src/models.rs | 16 ++++++++++++++++ src/schema.rs | 24 ++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 src/models.rs create mode 100644 src/schema.rs diff --git a/src/models.rs b/src/models.rs new file mode 100644 index 000000000..a7ed8a91d --- /dev/null +++ b/src/models.rs @@ -0,0 +1,16 @@ +use chrono::prelude::{DateTime, Utc}; + +#[derive(Queryable)] +pub struct Thread { + pub id: i32, + pub title: String, + pub body: String, + pub posted: DateTime, +} + +pub struct Post { + pub id: i32, + pub thread: i32, + pub body: String, + pub posted: DateTime, +} diff --git a/src/schema.rs b/src/schema.rs new file mode 100644 index 000000000..a899f52ac --- /dev/null +++ b/src/schema.rs @@ -0,0 +1,24 @@ +table! { + posts (id) { + id -> Int4, + thread -> Int4, + body -> Text, + posted -> Timestamptz, + } +} + +table! { + threads (id) { + id -> Int4, + title -> Varchar, + body -> Text, + posted -> Timestamptz, + } +} + +joinable!(posts -> threads (thread)); + +allow_tables_to_appear_in_same_query!( + posts, + threads, +);