-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
42 changed files
with
455 additions
and
558 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DROP INDEX unique_front_user_id; |
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 @@ | ||
CREATE UNIQUE INDEX unique_front_user_id ON ankis(front, user_id); |
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 @@ | ||
DROP TABLE songs; |
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,10 @@ | ||
CREATE TABLE songs ( | ||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, | ||
title VARCHAR(255) NOT NULL, | ||
artist VARCHAR(255) NOT NULL, | ||
language VARCHAR(255) NOT NULL, | ||
video_url VARCHAR(255) NOT NULL, | ||
lyrics TEXT NOT NULL | ||
); | ||
|
||
CREATE UNIQUE INDEX songs_title_artist_language ON songs (title, artist, language); |
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
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 |
---|---|---|
@@ -1,9 +1,10 @@ | ||
pub use models::{Anki, Text, User}; | ||
pub use models::{Anki, Song, Text, User}; | ||
pub use utils::establish_connection; | ||
|
||
mod anki; | ||
mod models; | ||
mod schema; | ||
mod song; | ||
mod text; | ||
mod user; | ||
mod utils; |
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,70 @@ | ||
use super::models::Song; | ||
use super::utils::establish_connection; | ||
use diesel::prelude::*; | ||
|
||
impl Song { | ||
fn get_query_filter( | ||
lang: &str, | ||
query: &Option<String>, | ||
) -> Box< | ||
dyn BoxableExpression< | ||
super::schema::songs::table, | ||
diesel::sqlite::Sqlite, | ||
SqlType = diesel::sql_types::Bool, | ||
>, | ||
> { | ||
use super::schema::songs::dsl::*; | ||
|
||
if query.is_none() { | ||
return Box::new(language.eq(lang.to_owned())); | ||
} | ||
let query = format!("%{}%", query.clone().unwrap()); | ||
|
||
let filter = artist.like(query.clone()).or(title.like(query.clone())); | ||
|
||
Box::new(filter) | ||
} | ||
|
||
pub fn get_all( | ||
lang: String, | ||
items_number: i32, | ||
offset: i32, | ||
query: Option<String>, | ||
) -> Vec<Self> { | ||
let connection = &mut establish_connection(); | ||
|
||
use super::schema::songs::dsl::*; | ||
|
||
songs | ||
.filter(language.eq(&lang)) | ||
.filter(Self::get_query_filter(&lang, &query)) | ||
.limit(items_number.into()) | ||
.offset(offset.into()) | ||
.load::<Self>(connection) | ||
.unwrap_or(Vec::new()) | ||
} | ||
|
||
pub fn get_total(lang: String, query: Option<String>) -> i32 { | ||
let connection = &mut establish_connection(); | ||
|
||
use super::schema::songs::dsl::*; | ||
|
||
songs | ||
.filter(Self::get_query_filter(&lang, &query)) | ||
.count() | ||
.get_result(connection) | ||
.unwrap_or(0) as i32 | ||
} | ||
|
||
pub fn get_by_id(song_id: i32) -> Option<Self> { | ||
let connection = &mut establish_connection(); | ||
|
||
use super::schema::songs::dsl::*; | ||
|
||
songs | ||
.filter(id.eq(song_id)) | ||
.first(connection) | ||
.optional() | ||
.unwrap_or(None) | ||
} | ||
} |
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
Oops, something went wrong.