You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The exact solution I propose is do the translation from a relative date into an absolute date in the NQL language. This means adding a new syntax to NQL to represent a relative date and then processing that into an exact date inside the parser, and storing an absolute query in our intermediary format (Mongo query JSON). Our intermediary format would then represent a simple absolute date query to perform on the database, which we can already do.
This solution does not add relative date handling all the way to the database / JSON
lookup. The query that is performed will be absolute, but in the URL/API query we will be able to represent this as relative. The reason for this is that neither mongo query/mingo nor knex have support for relative dates.
Proposed Syntax:
last_seen_at:>=now-1d (since yesterday)
last_seen_at:<=now+1d (before tomorrow)
In detail:
>= or <= are NQL’s greater than or less than operators.
now a keyword that represents now
-/+ plus or minus, used to indicate dates since or dates before now
1d represents “one day” - an interval to add or subtract from now
We can support different intervals:
now-30d (30 days ago)
now-4w (4 weeks ago)
now-12M (12 months ago)
now-1y (1 year ago)
now-1h (1 hour ago)
now-1m (1 minute ago)
now-1s (1 second ago)
Note: M is capitalised for Months as per datetime formatters in most languages, where m represents minutes.
last_seen_at:>=now-1d would become the following Mongo Query JSON:
closes: https://github.com/NexesJS/NQL-Lang/issues/9
This adds relative date expressions in the form now-1d.
These are translated into absolute dates inside the NQL parser
The output format then contains a standard gt/lt type date expression
This is because mongo queries don't support relative dates without using $expr and knex doesn't support them at all.
We'd have to change a lot of stuff to support relative queries to the DB / to JSON but this solves the immediate problem simply.
This has meant introducing state into the lexer, which is new to me. This done so that we can correctly interpret the -/+ symbols
in two different "states". This could be used to improve the lexer further.
This is quite a complex addition to the language, but it reduces complexity everywhere else.
We have a need for relative date handling in NQL.
The exact solution I propose is do the translation from a relative date into an absolute date in the NQL language. This means adding a new syntax to NQL to represent a relative date and then processing that into an exact date inside the parser, and storing an absolute query in our intermediary format (Mongo query JSON). Our intermediary format would then represent a simple absolute date query to perform on the database, which we can already do.
This solution does not add relative date handling all the way to the database / JSON
lookup. The query that is performed will be absolute, but in the URL/API query we will be able to represent this as relative. The reason for this is that neither mongo query/mingo nor knex have support for relative dates.
Proposed Syntax:
last_seen_at:>=now-1d
(since yesterday)last_seen_at:<=now+1d
(before tomorrow)In detail:
>=
or<=
are NQL’s greater than or less than operators.now
a keyword that represents now-/+
plus or minus, used to indicate dates since or dates before now1d
represents “one day” - an interval to add or subtract from nowWe can support different intervals:
now-30d
(30 days ago)now-4w
(4 weeks ago)now-12M
(12 months ago)now-1y
(1 year ago)now-1h
(1 hour ago)now-1m
(1 minute ago)now-1s
(1 second ago)Note:
M
is capitalised for Months as per datetime formatters in most languages, wherem
represents minutes.last_seen_at:>=now-1d
would become the following Mongo Query JSON:The text was updated successfully, but these errors were encountered: