package com.example.pmulabs.room.dao

import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.Query
import androidx.room.Update
import com.example.pmulabs.room.models.Article
import kotlinx.coroutines.flow.Flow

@Dao
interface ArticleDao {
    @Query("select * from article")
    fun getAll(): Flow<List<Article>>

    @Query("select * from article where article.id = :idArticle")
    fun getArticleById(idArticle: Int): Flow<Article>

    @Query("SELECT * FROM article ORDER BY id DESC LIMIT :limit OFFSET :offset")
    suspend fun getArticles(limit: Int, offset: Int): List<Article>

    @Insert
    suspend fun insert(article: Article)

    @Update
    suspend fun update(article: Article)

    @Delete
    suspend fun delete(article: Article)
}