mirror of
https://github.com/austinried/subtracks.git
synced 2026-11-16 01:00:17 +01:00
Restore the both-tables-empty fallback in the credit recompute, skip redundant marker writes, append albumless tracks after album tracks, and make the paged artist query observe sources. Add tests for an interrupted sync and the partial-relation migration guard.
92 lines
3.1 KiB
Kotlin
92 lines
3.1 KiB
Kotlin
package com.subtracks.data.db
|
|
|
|
import androidx.room3.Dao
|
|
import androidx.room3.Insert
|
|
import androidx.room3.Query
|
|
import androidx.room3.Upsert
|
|
import com.subtracks.data.model.Source
|
|
import com.subtracks.data.model.SubsonicConfig
|
|
import com.subtracks.data.model.SubsonicSource
|
|
import kotlinx.coroutines.flow.Flow
|
|
|
|
@Dao
|
|
interface SourcesDao {
|
|
@Query("SELECT * FROM sources ORDER BY createdAt")
|
|
fun sources(): Flow<List<Source>>
|
|
|
|
@Query("SELECT * FROM sources WHERE id = :id")
|
|
fun source(id: Long): Flow<Source?>
|
|
|
|
@Query("SELECT * FROM sources WHERE id = :id")
|
|
suspend fun sourceOnce(id: Long): Source?
|
|
|
|
@Query("SELECT id FROM sources WHERE isActive = 1 LIMIT 1")
|
|
fun activeSourceId(): Flow<Long?>
|
|
|
|
@Query("SELECT * FROM subsonic_sources WHERE sourceId = :sourceId")
|
|
fun subsonicSource(sourceId: Long): Flow<SubsonicSource?>
|
|
|
|
@Query("SELECT id FROM sources WHERE isActive = 1 LIMIT 1")
|
|
suspend fun activeSourceIdOnce(): Long?
|
|
|
|
@Query("SELECT creditsStale FROM sources WHERE id = :sourceId")
|
|
suspend fun creditsStale(sourceId: Long): Boolean?
|
|
|
|
@Query("UPDATE sources SET creditsStale = :stale WHERE id = :sourceId AND creditsStale != :stale")
|
|
suspend fun setCreditsStale(
|
|
sourceId: Long,
|
|
stale: Boolean,
|
|
)
|
|
|
|
@Query("UPDATE sources SET name = :name, address = :address WHERE id = :sourceId")
|
|
suspend fun updateSourceDetails(
|
|
sourceId: Long,
|
|
name: String,
|
|
address: String,
|
|
)
|
|
|
|
@Insert
|
|
suspend fun insertSource(source: Source): Long
|
|
|
|
@Upsert
|
|
suspend fun upsertSource(source: Source)
|
|
|
|
@Upsert
|
|
suspend fun upsertSubsonicSource(subsonic: SubsonicSource)
|
|
|
|
@Query("UPDATE subsonic_sources SET useTokenAuth = 0 WHERE sourceId = :sourceId")
|
|
suspend fun disableTokenAuth(sourceId: Long)
|
|
|
|
@Query("DELETE FROM sources WHERE id = :id")
|
|
suspend fun deleteSourceRow(id: Long)
|
|
|
|
suspend fun deleteSource(id: Long) = deleteSourceRow(id)
|
|
|
|
@Query("UPDATE sources SET isActive = (id = :sourceId)")
|
|
suspend fun setActiveSource(sourceId: Long)
|
|
|
|
@Query(
|
|
"SELECT s.id AS id, s.name AS name, s.address AS address, c.username AS username, " +
|
|
"c.password AS password, c.useTokenAuth AS useTokenAuth " +
|
|
"FROM sources s JOIN subsonic_sources c ON c.sourceId = s.id " +
|
|
"WHERE s.isActive = 1 LIMIT 1",
|
|
)
|
|
fun activeSubsonicConfig(): Flow<SubsonicConfig?>
|
|
|
|
@Query(
|
|
"SELECT s.id AS id, s.name AS name, s.address AS address, c.username AS username, " +
|
|
"c.password AS password, c.useTokenAuth AS useTokenAuth " +
|
|
"FROM sources s JOIN subsonic_sources c ON c.sourceId = s.id " +
|
|
"WHERE s.isActive = 1 LIMIT 1",
|
|
)
|
|
suspend fun activeSubsonicConfigOnce(): SubsonicConfig?
|
|
|
|
@Query(
|
|
"SELECT s.id AS id, s.name AS name, s.address AS address, c.username AS username, " +
|
|
"c.password AS password, c.useTokenAuth AS useTokenAuth " +
|
|
"FROM sources s JOIN subsonic_sources c ON c.sourceId = s.id " +
|
|
"WHERE s.id = :sourceId LIMIT 1",
|
|
)
|
|
suspend fun subsonicConfigOnce(sourceId: Long): SubsonicConfig?
|
|
}
|