Repository navigation
Functions
The rules have no database functions: a rule compares fields, properties and constants with an operator. What you can use instead:
- the property functions, e.g.
["$.items.length()", ">", 0]or["$.phone.isNull()", "==", true], -
@currentUseras a value, the name of the user who sends the request (see Rules), -
@now,@now-1d... as a value, the current date and time, shifted (since 3.21.0, see below), - values computed by your test or script before the request.
Since 3.21.0 a rule can compare with the current moment: @now, shifted with + or - and a number of seconds (s), minutes (m), hours (h), days (d) or weeks (w):
{
"rules": [
["createdAt", "<", "@now-1d"],
["$.validUntil", ">", "@now"]
]
}| Value | Means |
|---|---|
@now |
now |
@now-30m |
30 minutes ago |
@now-2h |
2 hours ago |
@now-7d |
7 days ago |
@now+1w |
in a week |
@now is taken when the server reads the rules, from the server's clock. It works like a date constant (below): for the fields createdAt and modifiedAt and for properties holding a date. Dates in properties are compared as they are written, so a date with Z (UTC) matches @now exactly when the server runs in UTC, as the Docker image does. It is the way to select by age in a job, e.g. the reservations older than 2 hours.
Before 3.21.0, or for a date that isn't relative to now, compute the date in your test and send it as a constant in the format yyyy-MM-ddTHH:mm:ss.SSSZ, e.g. to select data created at least one day ago:
{
"rules": [
["createdAt", "<", "2026-11-15T12:00:00.000Z"]
]
}The format needs milliseconds and the Z at the end. For example:
- JavaScript:
new Date(Date.now() - 24 * 60 * 60 * 1000).toISOString() - Java:
Instant.now().minus(1, ChronoUnit.DAYS).truncatedTo(ChronoUnit.MILLIS).toString()(prints no milliseconds when they are 0; useDateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").withZone(ZoneOffset.UTC)to be sure) - Python:
(datetime.now(timezone.utc) - timedelta(days=1)).strftime("%Y-%m-%dT%H:%M:%S.%f")[:-3] + "Z"
The same works for properties. A property is stored in JSON, without a type; when it is compared with such a date constant, Databucket reads it as a timestamp:
{
"rules": [
["$.birthDate", "<", "2000-11-18T20:00:00.000Z"]
]
}A value in any other format, e.g. 2000-11-18 or 2000-11-18T20:00:00Z, is compared as text. Properties whose value doesn't start with a date (yyyy-MM-dd) don't match.
Until 3.17.0 the old API version 1 accepted native SQL functions with the #func: prefix, e.g. ["createdAt", "<", "#func:NOW() - INTERVAL '1 DAY'"]. They are refused with 400 Bad Request; use @now-1d or compute the value in the test as shown above.
Wiki
Work in the project
- Navigation
- Overview
- Searching
- Filtering
- Create/modify/remove data
- Data reservation
- Data details
- Data history
- Tasks execution
- Data export
- Data import
- Data generation
Project settings
Management
API