npm i rethinkdb-ts
or
yarn add rethinkdb-ts
// if you support import
import { r } from 'rethinkdb-ts';
// if you dont
const { r } = require('rethinkdb-ts');
// in an async context
// if you want to initialize a connection pool
await r.connectPool(options);
// if you want to initialize a single connection
const conn = await r.connect(options);
{ host: '...', port: '...' }
you'll have to encapsulate in a server/servers property:
{
server: {
host: '172.23.12.2',
port: 21085,
tls: true,
ca: caCert,
// If your certificate common name doesn't match the host:
// checkServerIdentity() {}
}
}
The options for standard connections is described here.
If you want an SSL/TLS, add tls: true
and the options described here and
const {r} = require('rethinkdb-ts')
or import {r} from 'rethinkdb-ts'
instead of const r = require('rethinkdbdash')(options)
await r.connectPool()
{ cursor: true }
option, for getting a cursor use .getCursor(runOptions)
instead of .run(runOptions)
.run()
will coerce streams to array by default feeds will return a cursor like rethinkdbdashbluebird
toStream()
.asyncIterator()
const serializedQuery = r.table(...).filter(...).map(...).serialize()
and get it like this r.deserialize(serializedQuery).run()
or even r.deserialize<RStream>(serializedQuery).reduce(...).run()
the serialized query is a normal string so you can store it in the DB. No need for ugly workarounds like .toString
and eval
anymore. Also the serialized query is the actual JSON that gets sent to the server so it should be cross-language compatible if any other driver cares to implement it..then()
directly on a query (optionalRun), it can confuse users that queries are promises leading to false assumptions:
.run()
as many times as you want (promises run only once and return the same value without running other times)