Saturday, 15 December 2018

SQLite : How to populate a boolean field on a pojo, from a subQuery

I want to return a list of posts like.

@Query("SELECT * FROM posts")
List<Post> getPosts()

I have a pojo.

post {
   name:String
   id :String
   postUid:String
   userHasNewContent:Boolean
}

Now, I want every post in the list to have the userHasNewContent:Boolean, populated by checking if the user who owns this post has new content(Not older than a week)

So I tried.

@Query("SELECT *,
       (SELECT content_uid FROM content WHERE content_uid = postUid AND
        contentTime < :aWeekAgo)AS userHasNewContent 
      FROM posts")
List<Post> getPosts(String aWeekAgo)

WHERE content is: content{ contentTime:Long //Unix Timestamp id:String }

AND

public static Long aWeekAgo() {
        long day = (1000 * 60) * 60 * 24;
        return System.currentTimeMillis() - day * 7;
    }

This doesn't seem to work as expected, am I doing this the way?



from SQLite : How to populate a boolean field on a pojo, from a subQuery

No comments:

Post a Comment