questdb / nodejs-questdb-client

QuestDB Node.js Client
35 stars 8 forks source link

feat(nodejs): introduce safer timestamp API #21

Closed puzpuzpuz closed 11 months ago

puzpuzpuz commented 11 months ago

Note. This is a breaking change, so the patch bumps the version to 2.0.0.

Adds time unit as an optional parameter to timestamp-accepting methods:

  const bday = Date.parse('1856-07-10');
  sender
    .table('inventors')
    .symbol('born', 'Austrian Empire')
    .timestampColumn('birthday', bday, 'ms') // notice 'ms' here
    .intColumn('id', 0)
    .stringColumn('name', 'Nicola Tesla')
    .at(Date.now(), 'ms'); // notice 'ms' here

The unit defaults to 'us' (native QuestDB resolution) in both timestampColumn() and at(). Supported values are:

Also, includes some code style changes (e.g. consistent ' instead of mixed ' and ") and a number of improvements, including example unification with the Java client.

Considered alternatives

Temporal types could be used instead of the optional parameter, but the thing is that the spec is still experimental, so it's too early to rely on it.