added subscription model

This commit is contained in:
Gonçalo Valério 2019-04-02 00:02:13 +01:00
parent 46dd07f3e4
commit 0eb0e7b295
7 changed files with 48 additions and 0 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@
.idea
.vscode
*.iml
local.db

5
diesel.toml Normal file
View File

@ -0,0 +1,5 @@
# For documentation on how to configure this file,
# see diesel.rs/guides/configuring-diesel-cli
[print_schema]
file = "src/schema.rs"

0
migrations/.gitkeep Normal file
View File

View File

@ -0,0 +1,2 @@
-- This file should undo anything in `up.sql`
DROP TABLE subscriptions

View File

@ -0,0 +1,9 @@
-- Your SQL goes here
CREATE TABLE subscriptions (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
callback VARCHAR NOT NULL,
topic VARCHAR NOT NULL,
sec VARCHAR NOT NULL,
created_at INTEGER NOT NULL,
expires_at INTEGER NOT NULL
)

21
src/models.rs Normal file
View File

@ -0,0 +1,21 @@
use super::schema::posts;
#[derive(Queryable)]
pub struct Subscription {
pub id: i32,
pub callback: String,
pub topic: String,
pub sec: String,
pub created_at: i32,
pub expires_at: i32
}
#[derive(Insertable)]
#[table_name="subscriptions"]
pub struct NewSubscription<'a> {
pub callback: &'a str,
pub topic: &'a str,
pub sec: &'a str,
pub created_at: &'a i32,
pub expires_at: &'a i32
}

10
src/schema.rs Normal file
View File

@ -0,0 +1,10 @@
table! {
subscriptions (id) {
id -> Integer,
callback -> Text,
topic -> Text,
sec -> Text,
created_at -> Integer,
expires_at -> Integer,
}
}