Initial diesel models.

This commit is contained in:
Jordan Petridis 2017-09-16 02:22:23 +03:00
parent 600415ff5d
commit 55a310d3a5
No known key found for this signature in database
GPG Key ID: CEABAD9F5683B9A6
7 changed files with 91 additions and 9 deletions

View File

@ -15,4 +15,8 @@ diesel_codegen = { version = "0.16.0", features = ["sqlite"] }
time = "0.1.38"
xdg = "2.1.0"
lazy_static = "0.2.8"
chrono = "0.4.0"
chrono = "0.4.0"
rss = { version = "1.1.0", features = ["from_url"]}
# overide diesel's dependancy that would otherwise turn a dotenv feature of
# that rss depends upon
dotenv = "*"

View File

@ -1,8 +1,8 @@
CREATE TABLE `Episode` (
CREATE TABLE `episode` (
`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
`title` TEXT NOT NULL,
`desrciption` TEXT,
`uri` TEXT NOT NULL,
`description` TEXT,
`local_uri` TEXT,
`thumbnail` TEXT,
`lenght` INTEGER,
@ -10,14 +10,14 @@ CREATE TABLE `Episode` (
`podcast_id` INTEGER NOT NULL
);
CREATE TABLE `Podcast` (
CREATE TABLE `podcast` (
`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
`title` TEXT NOT NULL,
`uri` TEXT NOT NULL,
`link` TEXT,
`description` TEXT,
`last_modified` TEXT,
`http_etag` INTEGER,
`http_etag` TEXT,
`image_uri` TEXT,
`image_local` TEXT
);

View File

@ -19,5 +19,7 @@ pub fn run() -> Result<()> {
info!("{:?}", foo);
::init()?;
::parse_feeds::foo();
Ok(())
}

View File

@ -21,10 +21,12 @@ extern crate diesel_codegen;
extern crate xdg;
extern crate reqwest;
extern crate rss;
pub mod cli;
pub mod schema;
pub mod models;
pub mod parse_feeds;
pub mod errors {
@ -58,11 +60,15 @@ lazy_static!{
static ref HAMMOND_CONFIG: PathBuf = HAMMOND_XDG.create_config_directory(HAMMOND_XDG.get_config_home()).unwrap();
static ref HAMMOND_CACHE: PathBuf = HAMMOND_XDG.create_cache_directory(HAMMOND_XDG.get_cache_home()).unwrap();
static ref DB_PATH: std::path::PathBuf = HAMMOND_XDG.place_data_file("hammond.db").unwrap();
static ref DB_PATH: PathBuf = {
// Ensure that xdg_data is created.
&HAMMOND_DATA;
HAMMOND_XDG.place_data_file("hammond.db").unwrap()
};
}
pub fn init() -> Result<()> {
&HAMMOND_DATA;
let conn = establish_connection();
// embedded_migrations::run(&conn)?;
embedded_migrations::run_with_output(&conn, &mut std::io::stdout())?;

View File

@ -0,0 +1,62 @@
use schema::{episode, podcast};
#[derive(Queryable, Identifiable)]
#[derive(Associations)]
#[table_name = "episode"]
#[belongs_to(Podcast, foreign_key = "podcast_id")]
#[derive(Debug, Clone)]
pub struct Episode {
id: i32,
title: String,
uri: String,
local_uri: Option<String>,
description: Option<String>,
thumbnail: Option<String>,
lenght: Option<i32>,
guid: Option<String>,
podcast_id: i32,
}
#[derive(Queryable, Identifiable)]
#[table_name = "podcast"]
#[derive(Debug, Clone)]
pub struct Podcast {
id: i32,
title: String,
uri: String,
link: Option<String>,
description: Option<String>,
last_modified: Option<String>,
http_etag: Option<String>,
image_uri: Option<String>,
image_local: Option<String>,
}
#[derive(Insertable)]
#[table_name = "episode"]
#[derive(Debug, Clone)]
pub struct NewEpisode<'a> {
title: &'a str,
uri: &'a str,
local_uri: Option<&'a str>,
description: Option<&'a str>,
thumbnail: Option<&'a str>,
lenght: Option<i32>,
guid: Option<&'a str>,
podcast_id: i32,
}
#[derive(Insertable)]
#[table_name = "podcast"]
#[derive(Debug, Clone)]
pub struct NewPodcast<'a> {
title: &'a str,
uri: &'a str,
link: Option<&'a str>,
description: Option<&'a str>,
last_modified: Option<&'a str>,
http_etag: Option<&'a str>,
image_uri: Option<&'a str>,
image_local: Option<&'a str>,
}

8
src/parse_feeds.rs Normal file
View File

@ -0,0 +1,8 @@
use rss::Channel;
pub fn foo() {
let channel = Channel::from_url("https://feeds.feedburner.com/InterceptedWithJeremyScahill").unwrap();
println!("{:#?}", channel);
}

View File

@ -2,8 +2,8 @@ table! {
episode (id) {
id -> Integer,
title -> Text,
desrciption -> Nullable<Text>,
uri -> Text,
description -> Nullable<Text>,
local_uri -> Nullable<Text>,
thumbnail -> Nullable<Text>,
lenght -> Nullable<Integer>,
@ -20,7 +20,7 @@ table! {
link -> Nullable<Text>,
description -> Nullable<Text>,
last_modified -> Nullable<Text>,
http_etag -> Nullable<Integer>,
http_etag -> Nullable<Text>,
image_uri -> Nullable<Text>,
image_local -> Nullable<Text>,
}