Class: RethinkDBAdapter

RethinkDBAdapter


new RethinkDBAdapter(opts)

RethinkDBAdapter class.

Parameters:
Name Type Argument Description
opts Object <optional>

Configuration opts.

Properties
Name Type Argument Default Description
authKey string <optional>
""

RethinkDB authorization key.

bufferSize number <optional>
10

Buffer size for connection pool.

db string <optional>
"test"

Default database.

debug boolean <optional>
false

Whether to log debugging information.

host string <optional>
"localhost"

RethinkDB host.

max number <optional>
50

Maximum connections in pool.

min number <optional>
10

Minimum connections in pool.

operators Object <optional>

Override the default predicate functions for specified operators.

port number <optional>
28015

RethinkDB port.

raw boolean <optional>
false

Whether to return a more detailed response object.

Example
// Use Container instead of DataStore on the server
import {Container} from 'js-data'
import RethinkdbDBAdapter from 'js-data-rethinkdb'

// Create a store to hold your Mappers
const store = new Container()

// Create an instance of RethinkdbDBAdapter with default settings
const adapter = new RethinkdbDBAdapter()

// Mappers in "store" will use the RethinkDB adapter by default
store.registerAdapter('rethinkdb', adapter, { default: true })

// Create a Mapper that maps to a "user" table
store.defineMapper('user')

Extends

Members


<static> OPERATORS

Default predicate functions for the filtering operators.

Properties:
Name Type Description
== function

Equality operator.

!= function

Inequality operator.

> function

"Greater than" operator.

>= function

"Greater than or equal to" operator.

< function

"Less than" operator.

<= function

"Less than or equal to" operator.

isectEmpty function

Operator to test that the intersection between two arrays is empty.

isectNotEmpty function

Operator to test that the intersection between two arrays is NOT empty.

in function

Operator to test whether a value is found in the provided array.

notIn function

Operator to test whether a value is NOT found in the provided array.

contains function

Operator to test whether an array contains the provided value.

notContains function

Operator to test whether an array does NOT contain the provided value.


authKey :string

RethinkDB authorization key.

Type:
  • string

bufferSize :number

Buffer size for connection pool.

Type:
  • number
Default Value:
  • 10

db :string

Default database.

Type:
  • string
Default Value:
  • "test"

debug :boolean

Whether to log debugging information.

Type:
  • boolean
Overrides:
Default Value:
  • false

deleteOpts :Object

Default options to pass to r#delete.

Type:
  • Object
Default Value:
  • {}

host :string

RethinkDB host.

Type:
  • string
Default Value:
  • "localhost"

insertOpts :Object

Default options to pass to r#insert.

Type:
  • Object
Default Value:
  • {}

max :number

Maximum connections in pool.

Type:
  • number
Default Value:
  • 50

min :number

Minimum connections in pool.

Type:
  • number
Default Value:
  • 10

operators :Object

Override the default predicate functions for specified operators.

Type:
  • Object
Default Value:
  • {}

port :number

RethinkDB port.

Type:
  • number
Default Value:
  • 10

r :Object

The rethinkdbdash instance used by this adapter. Use this directly when you need to write custom queries.

Type:
  • Object

raw :boolean

Whether to return a more detailed response object.

Type:
  • boolean
Overrides:
Default Value:
  • false

runOpts :Object

Default options to pass to r#run.

Type:
  • Object
Default Value:
  • {}

updateOpts :Object

Default options to pass to r#update.

Type:
  • Object
Default Value:
  • {}

Methods


<static> extend(instanceProps, classProps)

Alternative to ES6 class syntax for extending RethinkDBAdapter.

Parameters:
Name Type Argument Description
instanceProps Object <optional>

Properties that will be added to the prototype of the RethinkDBAdapter.

classProps Object <optional>

Properties that will be added as static properties to the RethinkDBAdapter itself.

Returns:

RethinkDBAdapter of RethinkDBAdapter.

Type
Object

afterCreate(mapper, props, opts, response)

Lifecycle method method called by create.

Override this method to add custom behavior for this lifecycle hook.

Returning a Promise causes create to wait for the Promise to resolve before continuing.

If opts.raw is true then response will be a detailed response object, otherwise response will be the created record.

response may be modified. You can also re-assign response to another value by returning a different value or a Promise that resolves to a different value.

A thrown error or rejected Promise will bubble up and reject the Promise returned by create.

Parameters:
Name Type Description
mapper Object

The mapper argument passed to create.

props Object

The props argument passed to create.

opts Object

The opts argument passed to create.

response Object | Response

Created record or Response, depending on the value of opts.raw.

Properties:
Name Type Description
opts.op string

afterCreate

Inherited From:
Overrides:

afterDestroy(mapper, id, opts, response)

Lifecycle method method called by destroy.

Override this method to add custom behavior for this lifecycle hook.

Returning a Promise causes destroy to wait for the Promise to resolve before continuing.

If opts.raw is true then response will be a detailed response object, otherwise response will be undefined.

response may be modified. You can also re-assign response to another value by returning a different value or a Promise that resolves to a different value.

A thrown error or rejected Promise will bubble up and reject the Promise returned by destroy.

Parameters:
Name Type Description
mapper Object

The mapper argument passed to destroy.

id string | number

The id argument passed to destroy.

opts Object

The opts argument passed to destroy.

response undefined | Response

undefined or Response, depending on the value of opts.raw.

Properties:
Name Type Description
opts.op string

afterDestroy

Inherited From:

afterDestroyAll(mapper, query, opts, response)

Lifecycle method method called by destroyAll.

Override this method to add custom behavior for this lifecycle hook.

Returning a Promise causes destroyAll to wait for the Promise to resolve before continuing.

If opts.raw is true then response will be a detailed response object, otherwise response will be undefined.

response may be modified. You can also re-assign response to another value by returning a different value or a Promise that resolves to a different value.

A thrown error or rejected Promise will bubble up and reject the Promise returned by destroyAll.

Parameters:
Name Type Description
mapper Object

The mapper argument passed to destroyAll.

query Object

The query argument passed to destroyAll.

opts Object

The opts argument passed to destroyAll.

response undefined | Response

undefined or Response, depending on the value of opts.raw.

Properties:
Name Type Description
opts.op string

afterDestroyAll

Inherited From:

afterFind(mapper, id, opts, response)

Lifecycle method method called by find.

Override this method to add custom behavior for this lifecycle hook.

Returning a Promise causes find to wait for the Promise to resolve before continuing.

If opts.raw is true then response will be a detailed response object, otherwise response will be the found record, if any.

response may be modified. You can also re-assign response to another value by returning a different value or a Promise that resolves to a different value.

A thrown error or rejected Promise will bubble up and reject the Promise returned by find.

Parameters:
Name Type Description
mapper Object

The mapper argument passed to find.

id string | number

The id argument passed to find.

opts Object

The opts argument passed to find.

response Object | Response

The found record or Response, depending on the value of opts.raw.

Properties:
Name Type Description
opts.op string

afterFind

Inherited From:

afterFindAll(mapper, query, opts, response)

Lifecycle method method called by findAll.

Override this method to add custom behavior for this lifecycle hook.

Returning a Promise causes findAll to wait for the Promise to resolve before continuing.

If opts.raw is true then response will be a detailed response object, otherwise response will be the found records, if any.

response may be modified. You can also re-assign response to another value by returning a different value or a Promise that resolves to a different value.

A thrown error or rejected Promise will bubble up and reject the Promise returned by findAll.

Parameters:
Name Type Description
mapper Object

The mapper argument passed to findAll.

query Object

The query argument passed to findAll.

opts Object

The opts argument passed to findAll.

response Array.<Object> | Response

The found records or Response, depending on the value of opts.raw.

Properties:
Name Type Description
opts.op string

afterFindAll

Inherited From:

afterUpdate(mapper, id, props, opts, response)

Lifecycle method method called by update.

Override this method to add custom behavior for this lifecycle hook.

Returning a Promise causes update to wait for the Promise to resolve before continuing.

If opts.raw is true then response will be a detailed response object, otherwise response will be the updated record.

response may be modified. You can also re-assign response to another value by returning a different value or a Promise that resolves to a different value.

A thrown error or rejected Promise will bubble up and reject the Promise returned by update.

Parameters:
Name Type Description
mapper Object

The mapper argument passed to update.

id string | number

The id argument passed to update.

props Object

The props argument passed to update.

opts Object

The opts argument passed to update.

response Object | Response

The updated record or Response, depending on the value of opts.raw.

Properties:
Name Type Description
opts.op string

afterUpdate

Inherited From:

afterUpdateAll(mapper, props, query, opts, response)

Lifecycle method method called by updateAll.

Override this method to add custom behavior for this lifecycle hook.

Returning a Promise causes updateAll to wait for the Promise to resolve before continuing.

If opts.raw is true then response will be a detailed response object, otherwise response will be the updated records, if any.

response may be modified. You can also re-assign response to another value by returning a different value or a Promise that resolves to a different value.

A thrown error or rejected Promise will bubble up and reject the Promise returned by updateAll.

Parameters:
Name Type Description
mapper Object

The mapper argument passed to updateAll.

props Object

The props argument passed to updateAll.

query Object

The query argument passed to updateAll.

opts Object

The opts argument passed to updateAll.

response Array.<Object> | Response

The updated records or Response, depending on the value of opts.raw.

Properties:
Name Type Description
opts.op string

afterUpdateAll

Inherited From:

afterUpdateMany(mapper, records, opts, response)

Lifecycle method method called by updateMany.

Override this method to add custom behavior for this lifecycle hook.

Returning a Promise causes updateMany to wait for the Promise to resolve before continuing.

If opts.raw is true then response will be a detailed response object, otherwise response will be the updated records, if any.

response may be modified. You can also re-assign response to another value by returning a different value or a Promise that resolves to a different value.

A thrown error or rejected Promise will bubble up and reject the Promise returned by updateMany.

Parameters:
Name Type Description
mapper Object

The mapper argument passed to updateMany.

records Array.<Object>

The records argument passed to updateMany.

opts Object

The opts argument passed to updateMany.

response Array.<Object> | Response

The updated records or Response, depending on the value of opts.raw.

Properties:
Name Type Description
opts.op string

afterUpdateMany

Inherited From:

beforeCreate(mapper, props, opts)

Lifecycle method method called by create.

Override this method to add custom behavior for this lifecycle hook.

Returning a Promise causes create to wait for the Promise to resolve before continuing.

props may be modified. You can also re-assign props to another value by returning a different value or a Promise that resolves to a different value.

A thrown error or rejected Promise will bubble up and reject the Promise returned by create.

Parameters:
Name Type Description
mapper Object

The mapper argument passed to create.

props Object

The props argument passed to create.

opts Object

The opts argument passed to create.

Properties:
Name Type Description
opts.op string

beforeCreate

Inherited From:

beforeCreateMany(mapper, props, opts)

Lifecycle method method called by createMany.

Override this method to add custom behavior for this lifecycle hook.

Returning a Promise causes createMany to wait for the Promise to resolve before continuing.

props may be modified. You can also re-assign props to another value by returning a different value or a Promise that resolves to a different value.

A thrown error or rejected Promise will bubble up and reject the Promise returned by createMany.

Parameters:
Name Type Description
mapper Object

The mapper argument passed to createMany.

props Array.<Object>

The props argument passed to createMany.

opts Object

The opts argument passed to createMany.

Properties:
Name Type Description
opts.op string

beforeCreateMany

Inherited From:

beforeDestroy(mapper, id, opts)

Lifecycle method method called by destroy.

Override this method to add custom behavior for this lifecycle hook.

Returning a Promise causes destroy to wait for the Promise to resolve before continuing.

A thrown error or rejected Promise will bubble up and reject the Promise returned by destroy.

Parameters:
Name Type Description
mapper Object

The mapper argument passed to destroy.

id string | number

The id argument passed to destroy.

opts Object

The opts argument passed to destroy.

Properties:
Name Type Description
opts.op string

beforeDestroy

Inherited From:

beforeDestroyAll(mapper, query, opts)

Lifecycle method method called by destroyAll.

Override this method to add custom behavior for this lifecycle hook.

Returning a Promise causes destroyAll to wait for the Promise to resolve before continuing.

A thrown error or rejected Promise will bubble up and reject the Promise returned by destroyAll.

Parameters:
Name Type Description
mapper Object

The mapper argument passed to destroyAll.

query Object

The query argument passed to destroyAll.

opts Object

The opts argument passed to destroyAll.

Properties:
Name Type Description
opts.op string

beforeDestroyAll

Inherited From:

beforeFind(mapper, id, opts)

Lifecycle method method called by find.

Override this method to add custom behavior for this lifecycle hook.

Returning a Promise causes find to wait for the Promise to resolve before continuing.

A thrown error or rejected Promise will bubble up and reject the Promise returned by find.

Parameters:
Name Type Description
mapper Object

The mapper argument passed to find.

id string | number

The id argument passed to find.

opts Object

The opts argument passed to find.

Properties:
Name Type Description
opts.op string

beforeFind

Inherited From:

beforeFindAll(mapper, query, opts)

Lifecycle method method called by findAll.

Override this method to add custom behavior for this lifecycle hook.

Returning a Promise causes findAll to wait for the Promise to resolve before continuing.

A thrown error or rejected Promise will bubble up and reject the Promise returned by findAll.

Parameters:
Name Type Description
mapper Object

The mapper argument passed to findAll.

query Object

The query argument passed to findAll.

opts Object

The opts argument passed to findAll.

Properties:
Name Type Description
opts.op string

beforeFindAll

Inherited From:

beforeUpdate(mapper, id, props, opts)

Lifecycle method method called by update.

Override this method to add custom behavior for this lifecycle hook.

Returning a Promise causes update to wait for the Promise to resolve before continuing.

props may be modified. You can also re-assign props to another value by returning a different value or a Promise that resolves to a different value.

A thrown error or rejected Promise will bubble up and reject the Promise returned by update.

Parameters:
Name Type Description
mapper Object

The mapper argument passed to update.

id string | number

The id argument passed to update.

props Object

The props argument passed to update.

opts Object

The opts argument passed to update.

Properties:
Name Type Description
opts.op string

beforeUpdate

Inherited From:

beforeUpdateAll(mapper, props, query, opts)

Lifecycle method method called by updateAll.

Override this method to add custom behavior for this lifecycle hook.

Returning a Promise causes updateAll to wait for the Promise to resolve before continuing.

props may be modified. You can also re-assign props to another value by returning a different value or a Promise that resolves to a different value.

A thrown error or rejected Promise will bubble up and reject the Promise returned by updateAll.

Parameters:
Name Type Description
mapper Object

The mapper argument passed to updateAll.

props Object

The props argument passed to updateAll.

query Object

The query argument passed to updateAll.

opts Object

The opts argument passed to updateAll.

Properties:
Name Type Description
opts.op string

beforeUpdateAll

Inherited From:

beforeUpdateMany(mapper, props, opts)

Lifecycle method method called by updateMany.

Override this method to add custom behavior for this lifecycle hook.

Returning a Promise causes updateMany to wait for the Promise to resolve before continuing.

props may be modified. You can also re-assign props to another value by returning a different value or a Promise that resolves to a different value.

A thrown error or rejected Promise will bubble up and reject the Promise returned by updateMany.

Parameters:
Name Type Description
mapper Object

The mapper argument passed to updateMany.

props Array.<Object>

The props argument passed to updateMany.

opts Object

The opts argument passed to updateMany.

Properties:
Name Type Description
opts.op string

beforeUpdateMany

Inherited From:

create(mapper, props, opts)

Create a new record.

Parameters:
Name Type Argument Description
mapper Object

The mapper.

props Object

The record to be created.

opts Object <optional>

Configuration options.

Properties
Name Type Argument Default Description
insertOpts Object <optional>

Options to pass to r#insert.

raw boolean <optional>
false

Whether to return a more detailed response object.

runOpts Object <optional>

Options to pass to r#run.

Overrides:
Returns:
Type
Promise

createMany(mapper, props, opts)

Create multiple records in a single batch.

Parameters:
Name Type Argument Description
mapper Object

The mapper.

props Object

The records to be created.

opts Object <optional>

Configuration options.

Properties
Name Type Argument Default Description
insertOpts Object <optional>

Options to pass to r#insert.

raw boolean <optional>
false

Whether to return a more detailed response object.

runOpts Object <optional>

Options to pass to r#run.

Overrides:
Returns:
Type
Promise

dbg()

Shortcut for #log('debug'[, arg1[, arg2[, argn]]]).

Inherited From:

destroy(mapper, id, opts)

Destroy the record with the given primary key.

Parameters:
Name Type Argument Description
mapper Object

The mapper.

id string | number

Primary key of the record to destroy.

opts Object <optional>

Configuration options.

Properties
Name Type Argument Default Description
deleteOpts Object <optional>

Options to pass to r#delete.

raw boolean <optional>
false

Whether to return a more detailed response object.

runOpts Object <optional>

Options to pass to r#run.

Overrides:
Returns:
Type
Promise

destroyAll(mapper, query, opts)

Destroy the records that match the selection query.

Parameters:
Name Type Argument Description
mapper Object

the mapper.

query Object <optional>

Selection query.

Properties
Name Type Argument Description
where Object <optional>

Filtering criteria.

orderBy string | Array <optional>

Sorting criteria.

sort string | Array <optional>

Same as query.sort.

limit number <optional>

Limit results.

skip number <optional>

Offset results.

offset number <optional>

Same as query.skip.

opts Object <optional>

Configuration options.

Properties
Name Type Argument Default Description
deleteOpts Object <optional>

Options to pass to r#delete.

operators Object <optional>

Override the default predicate functions for specified operators.

raw boolean <optional>
false

Whether to return a more detailed response object.

runOpts Object <optional>

Options to pass to r#run.

Overrides:
Returns:
Type
Promise

filterSequence(mapper, query, opts)

Apply the specified selection query to the provided RQL sequence.

Parameters:
Name Type Argument Description
mapper Object

The mapper.

query Object <optional>

Selection query.

Properties
Name Type Argument Description
where Object <optional>

Filtering criteria.

orderBy string | Array <optional>

Sorting criteria.

sort string | Array <optional>

Same as query.sort.

limit number <optional>

Limit results.

skip number <optional>

Offset results.

offset number <optional>

Same as query.skip.

opts Object <optional>

Configuration options.

Properties
Name Type Argument Description
operators Object <optional>

Override the default predicate functions for specified operators.


find(mapper, id, opts)

Retrieve the record with the given primary key.

Parameters:
Name Type Argument Description
mapper Object

The mapper.

id string | number

Primary key of the record to retrieve.

opts Object <optional>

Configuration options.

Properties
Name Type Argument Default Description
raw boolean <optional>
false

Whether to return a more detailed response object.

runOpts Object <optional>

Options to pass to r#run.

with Array.<string> <optional>
[]

Relations to eager load.

Overrides:
Returns:
Type
Promise

findAll(mapper, query, opts)

Retrieve the records that match the selection query.

Parameters:
Name Type Argument Description
mapper Object

The mapper.

query Object <optional>

Selection query.

Properties
Name Type Argument Description
where Object <optional>

Filtering criteria.

orderBy string | Array <optional>

Sorting criteria.

sort string | Array <optional>

Same as query.sort.

limit number <optional>

Limit results.

skip number <optional>

Offset results.

offset number <optional>

Same as query.skip.

opts Object <optional>

Configuration options.

Properties
Name Type Argument Default Description
operators Object <optional>

Override the default predicate functions for specified operators.

raw boolean <optional>
false

Whether to return a more detailed response object.

runOpts Object <optional>

Options to pass to r#run.

with Array.<string> <optional>
[]

Relations to eager load.

Overrides:
Returns:
Type
Promise

getOperator(operator, opts)

Resolve the predicate function for the specified operator based on the given options and this adapter's settings.

Parameters:
Name Type Argument Description
operator string

The name of the operator.

opts Object <optional>

Configuration options.

Properties
Name Type Argument Description
operators Object <optional>

Override the default predicate functions for specified operators.

Returns:

The predicate function for the specified operator.

Type
*

getOpt(opt, opts)

Resolve the value of the specified option based on the given options and this adapter's settings. Override with care.

Parameters:
Name Type Argument Description
opt string

The name of the option.

opts Object <optional>

Configuration options.

Inherited From:
Returns:

The value of the specified option.

Type
*

loadBelongsTo()

Load a belongsTo relationship.

Override with care.

Inherited From:
Returns:
Type
Promise

loadHasMany()

Load a hasMany relationship.

Override with care.

Inherited From:
Returns:
Type
Promise

loadHasOne()

Load a hasOne relationship.

Override with care.

Inherited From:
Returns:
Type
Promise

log()

Logging utility method. Override this method if you want to send log messages to something other than the console.

Inherited From:

makeBelongsToForeignKey()

Return the foreignKey from the given record for the provided relationship.

Override with care.

Inherited From:
Returns:
Type
*

makeHasManyForeignKey()

Return the foreignKey from the given record for the provided relationship.

There may be reasons why you may want to override this method, like when the id of the parent doesn't exactly match up to the key on the child.

Override with care.

Inherited From:
Returns:
Type
*

respond(response, opts)

Parameters:
Name Type Description
response Object

Response object.

opts Object

Configuration options. return {Object} If opts.raw == true then return response, else return response.data.

Inherited From:

update(mapper, id, props, opts)

Apply the given update to the record with the specified primary key.

Parameters:
Name Type Argument Description
mapper Object

The mapper.

id string | number

The primary key of the record to be updated.

props Object

The update to apply to the record.

opts Object <optional>

Configuration options.

Properties
Name Type Argument Default Description
updateOpts Object <optional>

Options to pass to r#update.

raw boolean <optional>
false

Whether to return a more detailed response object.

runOpts Object <optional>

Options to pass to r#run.

Overrides:
Returns:
Type
Promise

updateAll(mapper, props, query, opts)

Apply the given update to all records that match the selection query.

Parameters:
Name Type Argument Description
mapper Object

The mapper.

props Object

The update to apply to the selected records.

query Object <optional>

Selection query.

Properties
Name Type Argument Description
where Object <optional>

Filtering criteria.

orderBy string | Array <optional>

Sorting criteria.

sort string | Array <optional>

Same as query.sort.

limit number <optional>

Limit results.

skip number <optional>

Offset results.

offset number <optional>

Same as query.skip.

opts Object <optional>

Configuration options.

Properties
Name Type Argument Default Description
operators Object <optional>

Override the default predicate functions for specified operators.

raw boolean <optional>
false

Whether to return a more detailed response object.

runOpts Object <optional>

Options to pass to r#run.

updateOpts Object <optional>

Options to pass to r#update.

Overrides:
Returns:
Type
Promise

updateMany(mapper, records, opts)

Update the given records in a single batch.

Parameters:
Name Type Argument Description
mapper Object

The mapper.

records Array.<Object>

The records to update.

opts Object <optional>

Configuration options.

Properties
Name Type Argument Default Description
insertOpts Object <optional>

Options to pass to r#insert.

raw boolean <optional>
false

Whether to return a more detailed response object.

runOpts Object <optional>

Options to pass to r#run.

Overrides:
Returns:
Type
Promise