forked from agzam/vyatsu-schedule
feat(db): add teacher schedule tables and Room v4 migration
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
package agzam.vyatsu.data.local
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
import androidx.room.OnConflictStrategy
|
||||
import androidx.room.Query
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
@Dao
|
||||
interface TeacherDao {
|
||||
@Query("SELECT * FROM departments ORDER BY name")
|
||||
fun observeDepartments(): Flow<List<DepartmentEntity>>
|
||||
|
||||
@Query("SELECT * FROM departments WHERE departmentId = :id")
|
||||
suspend fun getDepartment(id: String): DepartmentEntity?
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun insertAll(departments: List<DepartmentEntity>)
|
||||
|
||||
@Query("SELECT MAX(lastSyncedAt) FROM departments")
|
||||
suspend fun maxSyncedAt(): Long?
|
||||
|
||||
@Query("SELECT DISTINCT faculty FROM departments ORDER BY faculty")
|
||||
suspend fun getFaculties(): List<String>
|
||||
|
||||
@Query("DELETE FROM department_periods")
|
||||
suspend fun deleteAllPeriods()
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun insertPeriods(periods: List<DepartmentPeriodEntity>)
|
||||
|
||||
@Query(
|
||||
"SELECT * FROM department_periods WHERE weekStart <= :epochDay AND weekEnd >= :epochDay ORDER BY departmentId"
|
||||
)
|
||||
suspend fun getPeriodsForDate(epochDay: Long): List<DepartmentPeriodEntity>
|
||||
|
||||
@Query("SELECT * FROM department_periods WHERE departmentId = :departmentId ORDER BY weekStart")
|
||||
suspend fun getPeriodsForDepartment(departmentId: String): List<DepartmentPeriodEntity>
|
||||
}
|
||||
Reference in New Issue
Block a user