Quantcast
Channel: Mobile - Couchbase Forums
Viewing all articles
Browse latest Browse all 1119

Live Query Dynamic Date

$
0
0

Is there as of a yet a way to use a dynamic date inside a couchbase lite live query?

I.e. Is there a way to rewrite the following WHERE clause
WHERE STR_TO_MILLIS(item.date) < STR_TO_MILLIS('2025-02-11T15:45:38.483Z')?
to something like
WHERE STR_TO_MILLIS(item.date) < STR_TO_MILLIS(NOW())

My concrete use case is needing to filter for overdue tasks based on their item.notification date in relation to the moment at which the query receives an update. Hardcoding the check is fine for a one time get of the list, but falls short in the case of a live query where naturally what now and therefore overdue represents is dynamic.

Here is the full query I am using, for context:

SELECT
	item,
	IFMISSING(item.individualRepeatNotification, item.notification) AS activeNotification,
	STR_TO_MILLIS(IFMISSING(item.individualRepeatNotification, item.notification)) < STR_TO_MILLIS('${DATE_STRING}') AS isOverdue
FROM {$SCOPE}.{$COLLECTION} as item 
WHERE 
	item.isHidden = false 
	AND item.completion IS MISSING 
	AND activeNotification IS NOT MISSING
ORDER BY
	CASE WHEN isOverdue THEN 1 ELSE 2 END,
	CASE WHEN isOverdue THEN activeNotification ELSE NULL END DESC,
	CASE WHEN NOT isOverdue THEN activeNotification ELSE NULL END ASC
LIMIT ${DESIRED_COUNT}

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 1119

Trending Articles