feat: add more scanned properties, switch over to diesel from rusqlite (with first migration)
This commit is contained in:
67
src/models.rs
Normal file
67
src/models.rs
Normal file
@@ -0,0 +1,67 @@
|
||||
use diesel::prelude::*;
|
||||
|
||||
use crate::schema::{artists, collections, tracks};
|
||||
|
||||
#[derive(Debug, Clone, Queryable, Selectable, Identifiable)]
|
||||
#[diesel(table_name = artists)]
|
||||
#[diesel(check_for_backend(diesel::sqlite::Sqlite))]
|
||||
pub struct Artist {
|
||||
pub id: i32,
|
||||
pub original_name: String,
|
||||
pub display_name: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Queryable, Selectable, Identifiable)]
|
||||
#[diesel(table_name = collections)]
|
||||
#[diesel(check_for_backend(diesel::sqlite::Sqlite))]
|
||||
pub struct Collection {
|
||||
pub id: i32,
|
||||
pub collection_type: String,
|
||||
pub original_name: String,
|
||||
pub display_name: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Queryable, Selectable, Identifiable, Associations)]
|
||||
#[diesel(table_name = tracks)]
|
||||
#[diesel(belongs_to(Artist, foreign_key = artist_id))]
|
||||
#[diesel(belongs_to(Collection, foreign_key = collection_id))]
|
||||
#[diesel(check_for_backend(diesel::sqlite::Sqlite))]
|
||||
pub struct Track {
|
||||
pub id: i32,
|
||||
pub artist_id: i32,
|
||||
pub collection_id: Option<i32>,
|
||||
pub original_title: Option<String>,
|
||||
pub display_title: Option<String>,
|
||||
pub track_number: Option<i32>,
|
||||
pub genre: Option<String>,
|
||||
pub track_datetime: Option<String>,
|
||||
pub length_sec: i32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Insertable)]
|
||||
#[diesel(table_name = artists)]
|
||||
pub struct NewArtist<'a> {
|
||||
pub original_name: &'a str,
|
||||
pub display_name: &'a str,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Insertable)]
|
||||
#[diesel(table_name = collections)]
|
||||
pub struct NewCollection<'a> {
|
||||
pub collection_type: &'a str,
|
||||
pub original_name: &'a str,
|
||||
pub display_name: &'a str,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Insertable)]
|
||||
#[diesel(table_name = tracks)]
|
||||
pub struct NewTrack<'a> {
|
||||
pub artist_id: i32,
|
||||
pub collection_id: Option<i32>,
|
||||
pub original_title: Option<&'a str>,
|
||||
pub display_title: Option<&'a str>,
|
||||
pub track_number: Option<i32>,
|
||||
pub genre: Option<&'a str>,
|
||||
pub track_datetime: Option<&'a str>,
|
||||
pub length_sec: i32,
|
||||
}
|
||||
Reference in New Issue
Block a user