Formatting
This commit is contained in:
+1
-3
@@ -33,9 +33,7 @@ impl Database {
|
||||
.min_connections(1)
|
||||
.sqlx_logging(false);
|
||||
|
||||
let conn = SeaDatabase::connect(opts)
|
||||
.await
|
||||
.map_err(DbError::SeaOrm)?;
|
||||
let conn = SeaDatabase::connect(opts).await.map_err(DbError::SeaOrm)?;
|
||||
|
||||
// Enable WAL mode for better concurrent read performance
|
||||
if database_url.starts_with("sqlite:") && !database_url.contains(":memory:") {
|
||||
|
||||
@@ -74,6 +74,7 @@ impl MigrationTrait for Migration {
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
#[allow(clippy::enum_variant_names)]
|
||||
pub(crate) enum Artists {
|
||||
Table,
|
||||
Id,
|
||||
|
||||
@@ -21,7 +21,12 @@ impl MigrationTrait for Migration {
|
||||
.auto_increment()
|
||||
.primary_key(),
|
||||
)
|
||||
.col(ColumnDef::new(Tracks::FilePath).text().not_null().unique_key())
|
||||
.col(
|
||||
ColumnDef::new(Tracks::FilePath)
|
||||
.text()
|
||||
.not_null()
|
||||
.unique_key(),
|
||||
)
|
||||
.col(ColumnDef::new(Tracks::Title).text())
|
||||
.col(ColumnDef::new(Tracks::Artist).text())
|
||||
.col(ColumnDef::new(Tracks::Album).text())
|
||||
|
||||
@@ -10,14 +10,13 @@ pub async fn upsert(
|
||||
musicbrainz_id: Option<&str>,
|
||||
artist_id: Option<i32>,
|
||||
) -> DbResult<Album> {
|
||||
if let Some(mbid) = musicbrainz_id {
|
||||
if let Some(existing) = Albums::find()
|
||||
if let Some(mbid) = musicbrainz_id
|
||||
&& let Some(existing) = Albums::find()
|
||||
.filter(album::Column::MusicbrainzId.eq(mbid))
|
||||
.one(db)
|
||||
.await?
|
||||
{
|
||||
return Ok(existing);
|
||||
}
|
||||
{
|
||||
return Ok(existing);
|
||||
}
|
||||
|
||||
if let Some(existing) = find_by_name_and_artist(db, name, album_artist).await? {
|
||||
|
||||
+19
-8
@@ -4,16 +4,19 @@ use sea_orm::*;
|
||||
use crate::entities::artist::{self, ActiveModel, Entity as Artists, Model as Artist};
|
||||
use crate::error::{DbError, DbResult};
|
||||
|
||||
pub async fn upsert(db: &DatabaseConnection, name: &str, musicbrainz_id: Option<&str>) -> DbResult<Artist> {
|
||||
pub async fn upsert(
|
||||
db: &DatabaseConnection,
|
||||
name: &str,
|
||||
musicbrainz_id: Option<&str>,
|
||||
) -> DbResult<Artist> {
|
||||
// Try to find by musicbrainz_id first, then by name
|
||||
if let Some(mbid) = musicbrainz_id {
|
||||
if let Some(existing) = Artists::find()
|
||||
if let Some(mbid) = musicbrainz_id
|
||||
&& let Some(existing) = Artists::find()
|
||||
.filter(artist::Column::MusicbrainzId.eq(mbid))
|
||||
.one(db)
|
||||
.await?
|
||||
{
|
||||
return Ok(existing);
|
||||
}
|
||||
{
|
||||
return Ok(existing);
|
||||
}
|
||||
|
||||
if let Some(existing) = find_by_name(db, name).await? {
|
||||
@@ -80,14 +83,22 @@ pub async fn update(db: &DatabaseConnection, id: i32, model: ActiveModel) -> DbR
|
||||
Ok(active.update(db).await?)
|
||||
}
|
||||
|
||||
pub async fn update_top_songs(db: &DatabaseConnection, id: i32, top_songs_json: &str) -> DbResult<Artist> {
|
||||
pub async fn update_top_songs(
|
||||
db: &DatabaseConnection,
|
||||
id: i32,
|
||||
top_songs_json: &str,
|
||||
) -> DbResult<Artist> {
|
||||
let existing = get_by_id(db, id).await?;
|
||||
let mut active: ActiveModel = existing.into();
|
||||
active.top_songs = Set(top_songs_json.to_string());
|
||||
Ok(active.update(db).await?)
|
||||
}
|
||||
|
||||
pub async fn update_similar_artists(db: &DatabaseConnection, id: i32, similar_json: &str) -> DbResult<Artist> {
|
||||
pub async fn update_similar_artists(
|
||||
db: &DatabaseConnection,
|
||||
id: i32,
|
||||
similar_json: &str,
|
||||
) -> DbResult<Artist> {
|
||||
let existing = get_by_id(db, id).await?;
|
||||
let mut active: ActiveModel = existing.into();
|
||||
active.similar_artists = Set(similar_json.to_string());
|
||||
|
||||
@@ -106,7 +106,11 @@ pub async fn get_needing_metadata(db: &DatabaseConnection) -> DbResult<Vec<Track
|
||||
.await?)
|
||||
}
|
||||
|
||||
pub async fn update_metadata(db: &DatabaseConnection, id: i32, model: ActiveModel) -> DbResult<Track> {
|
||||
pub async fn update_metadata(
|
||||
db: &DatabaseConnection,
|
||||
id: i32,
|
||||
model: ActiveModel,
|
||||
) -> DbResult<Track> {
|
||||
let mut active = model;
|
||||
active.id = Set(id);
|
||||
active.updated_at = Set(Utc::now().naive_utc());
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use chrono::Utc;
|
||||
use sea_orm::*;
|
||||
use sea_orm::sea_query::Expr;
|
||||
use sea_orm::*;
|
||||
|
||||
use crate::entities::wanted_item::{
|
||||
self, ActiveModel, Entity as WantedItems, ItemType, Model as WantedItem, WantedStatus,
|
||||
|
||||
Reference in New Issue
Block a user