Open Sir-Will opened 4 years ago
For INSERT
s done with JSONEachRow
and writing JS objects to stream (like here) you can pass Date instance as a column value.
For now with SELECT
s you will always get Date and DateTime values as strings, and forced to parse them by yourself.
You can use moment
library:
const ClickHouse = require('@apla/clickhouse')
const moment = require('moment')
const options = <OPTIONS>
const ch = new ClickHouse(options)
const writableStream = ch.query('INSERT INTO testdb.testtable', { format: 'JSONEachRow' }, (err) => {
console.log(err)
console.log('Clickhouse insert!')
})
writableStream.write({
'name': 'Foo',
'timestamp': new Date(),
'date': moment.utc(new Date()).format('YYYY-MM-DD'),
'datetime': moment.utc(new Date()).format('YYYY-MM-DD HH:mm:ss'),
})
writableStream.write({
'name': 'Bar',
'timestamp': new Date(),
'date': moment.utc(new Date()).format('YYYY-MM-DD'),
'datetime': moment.utc(new Date()).format('YYYY-MM-DD HH:mm:ss'),
})
writableStream.end()
hey,
I'm trying to insert the clickhouse type
Date
from jsDate()
. I triednew Date().toISOString().substr(0,10)
which worked fine but reading it causes it to return aString
.What's the proper way of doing this?