Skip to content
NarDBv0.2.0-dev

Functions

CAST to rename a column, FORMAT and TO_DATE to format dates.

Three functions can be used inside fields(...). Upper or lower case names both work.

CAST — rename a column#

NarQL
from('members', 'm').fields({CAST('m.id', 'no'), CAST('m.name', 'first_name')});

The id field comes back as a column named no. The value does not change; only the column's name does.

FORMAT — format a date#

NarQL
from('members', 'm').where({'m.name': 'Osman'}).fields('m.name', FORMAT('m.birth_date', 'dd-mm-yyyy'));

FORMAT only applies to date and time fields (date, datetime, time, timestamp). The column keeps the field's name; wrap it in CAST to give it another one:

NarQL
from('members').fields(CAST(FORMAT('created_at', 'dd.mm.yyyy hh:ii'), 'joined'));
NarQL
# error: FORMAT applies to date and time fields; 'name' is string
from('members').fields(FORMAT('name', 'dd-mm-yyyy'));

TO_DATE — turn an integer timestamp into a date#

Many systems store time as an integer (a Unix timestamp). TO_DATE turns such a field into a readable date:

NarQL
from('members', 'm')
    .where({'m.login_at': {ne: null}})
    .fields('m.name', TO_DATE('m.login_at', 'dd-mm-yyyy hh:ii:ss'));
  • The value can be in seconds or milliseconds. Values with an absolute value of 10¹² or more are treated as milliseconds.
  • TO_DATE also works on date fields; there it behaves like FORMAT.

Format tokens#

TokenMeaningExample
yyyyyear2026
yytwo-digit year26
mm / MMmonth10
ddday30
hh / HHhour (00–23)14
iiminute05
sssecond09

Separators are - / . : , T and space. 'dd-mm-yyyy hh:ii:ss' produces 30-10-2026 14:05:09.

Times are written in UTC. There is no time zone option yet.