WatermelonDB icon indicating copy to clipboard operation
WatermelonDB copied to clipboard

How to get the actual data inside ._raw from fetch() query result?

Open prieyudaarvis opened this issue 2 years ago • 3 comments

I do have a single query like this:

const rows = await db.active.collections
    .get('messages')
    .query(
            Q.where('status', messagesStatus.ERROR)
     ).fetch()

the results is like this:

[
  {
     __changes: Object,
   isEditing: false,
   preparedState: null,
   __raw: MY ACTUAL DATA
  },
  {
     __changes: Object,
   isEditing: false,
   preparedState: null,
   __raw: MY ACTUAL DATA
  },
]

I can use map to get ._raw data but I dont think it is a good idea. Any insight?

prieyudaarvis avatar Sep 08 '22 07:09 prieyudaarvis

remove the .fetch and the .active.collections. It should be:

const rows = await db.get('messages').query(
    Q.where('status', messagesStatus.ERROR)
)

KrisLau avatar Sep 08 '22 20:09 KrisLau

removing .fetch and .active.collection will get:

TypeError: undefined is not a function

prieyudaarvis avatar Sep 09 '22 05:09 prieyudaarvis

@prieyudaarvis What is your db variable pointing to? And also just try removing the fetch()

KrisLau avatar Sep 09 '22 13:09 KrisLau