-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from NikolaiSch/adding-tests
Fixing rustfmt
- Loading branch information
Showing
8 changed files
with
201 additions
and
208 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
blank_lines_upper_bound = 2 | ||
combine_control_expr = false | ||
edition = "2021" | ||
force_multiline_blocks = true | ||
format_code_in_doc_comments = true | ||
format_generated_files = false | ||
imports_layout = "HorizontalVertical" | ||
imports_granularity = "Crate" | ||
group_imports = "StdExternalCrate" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,43 @@ | ||
//! Database operation helpers for sqlite, using diesel | ||
use diesel::prelude::*; | ||
use diesel::{prelude::*, RunQueryDsl}; | ||
|
||
use diesel::RunQueryDsl; | ||
|
||
use super::models::{Stream, StreamNew}; | ||
use super::schema; | ||
use super::schema::stream; | ||
use super::schema::stream::dsl::*; | ||
use super::{ | ||
models::{Stream, StreamNew}, | ||
schema, | ||
schema::{stream, stream::dsl::*}, | ||
}; | ||
|
||
pub fn establish_connection() -> Result<SqliteConnection, anyhow::Error> { | ||
let database_url = format!("{}/sports.db", std::env::temp_dir().display()); | ||
|
||
Ok(SqliteConnection::establish(&database_url)?) | ||
} | ||
|
||
pub fn create_stream( | ||
conn: &mut SqliteConnection, | ||
new_stream: &StreamNew, | ||
) -> Result<usize, anyhow::Error> { | ||
Ok(diesel::insert_or_ignore_into(stream::table) | ||
.values(new_stream) | ||
.execute(conn)?) | ||
pub fn create_stream(conn: &mut SqliteConnection, | ||
new_stream: &StreamNew) | ||
-> Result<usize, anyhow::Error> { | ||
Ok(diesel::insert_or_ignore_into(stream::table).values(new_stream) | ||
.execute(conn)?) | ||
} | ||
|
||
pub fn get_streams(conn: &mut SqliteConnection) -> Result<Vec<Stream>, anyhow::Error> { | ||
Ok(stream.load::<Stream>(conn)?) | ||
} | ||
|
||
pub fn get_empty_streams(conn: &mut SqliteConnection) -> Result<Vec<Stream>, anyhow::Error> { | ||
Ok(stream | ||
.filter(schema::stream::stream_link.eq("")) | ||
.load::<Stream>(conn)?) | ||
Ok(stream.filter(schema::stream::stream_link.eq("")) | ||
.load::<Stream>(conn)?) | ||
} | ||
|
||
pub fn get_linked_streams(conn: &mut SqliteConnection) -> Result<Vec<Stream>, anyhow::Error> { | ||
Ok(stream | ||
.filter(schema::stream::stream_link.ne("")) | ||
.load::<Stream>(conn)?) | ||
Ok(stream.filter(schema::stream::stream_link.ne("")) | ||
.load::<Stream>(conn)?) | ||
} | ||
|
||
pub fn get_streams_by_id( | ||
conn: &mut SqliteConnection, | ||
search_id: i32, | ||
) -> Result<Vec<Stream>, anyhow::Error> { | ||
Ok(stream | ||
.filter(schema::stream::id.eq(search_id)) | ||
.load::<Stream>(conn)?) | ||
pub fn get_streams_by_id(conn: &mut SqliteConnection, | ||
search_id: i32) | ||
-> Result<Vec<Stream>, anyhow::Error> { | ||
Ok(stream.filter(schema::stream::id.eq(search_id)) | ||
.load::<Stream>(conn)?) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.