package com.example.dtf.dao

import androidx.paging.PagingSource
import androidx.room.*
import com.example.dtf.models.*
import kotlinx.coroutines.flow.Flow

@Dao
interface PostDao {
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insert(post: Post)

    @Update
    suspend fun update(post: Post)

    @Delete
    suspend fun delete(post: Post)

    @Query("select * from post where post.id = :id")
    fun getById(id: Int) : Flow<Post>

    @Query("select * from post where post.category_id = :categoryId ORDER BY date DESC")
    fun getByCategory(categoryId: String) : PagingSource<Int, Post>

    @Query("delete from post where category_id = :query")
    fun deleteByQuery(query: String)
}
