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.

port number <optional>
28015

RethinkDB port.

raw boolean <optional>
false

Whether to return detailed result objects instead of just record data.

Source:
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')

Members


authKey :string

RethinkDB authorization key.

Type:
  • string
Source:

bufferSize :number

Buffer size for connection pool.

Type:
  • number
Default Value:
  • 10
Source:

db :string

Default database.

Type:
  • string
Default Value:
  • "test"
Source:

debug :boolean

Whether to log debugging information.

Type:
  • boolean
Default Value:
  • false
Source:

deleteOpts :Object

Default options to pass to r#delete.

Type:
  • Object
Default Value:
  • {}
Source:

host :string

RethinkDB host.

Type:
  • string
Default Value:
  • "localhost"
Source:

insertOpts :Object

Default options to pass to r#insert.

Type:
  • Object
Default Value:
  • {}
Source:

max :number

Maximum connections in pool.

Type:
  • number
Default Value:
  • 50
Source:

min :number

Minimum connections in pool.

Type:
  • number
Default Value:
  • 10
Source:

port :number

RethinkDB port.

Type:
  • number
Default Value:
  • 10
Source:

r :Object

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

Type:
  • Object
Source:

raw :boolean

Whether to return a more detailed response object.

Type:
  • boolean
Default Value:
  • false
Source:

runOpts :Object

Default options to pass to r#run.

Type:
  • Object
Default Value:
  • {}
Source:

updateOpts :Object

Default options to pass to r#update.

Type:
  • Object
Default Value:
  • {}
Source:

Methods


afterCreate()

Source:

afterCreateMany()

Source:

afterDestroy()

Source:

afterDestroyAll()

Source:

afterFind()

Source:

afterFindAll()

Source:

afterUpdate()

Source:

afterUpdateAll()

Source:

afterUpdateMany()

Source:

beforeCreate()

Source:

beforeCreateMany()

Source:

beforeDestroy()

Source:

beforeDestroyAll()

Source:

beforeFind()

Source:

beforeFindAll()

Source:

beforeUpdate()

Source:

beforeUpdateAll()

Source:

beforeUpdateMany()

Source:

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.

Source:
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.

Source:
Returns:
Type
Promise

dbg()

Source:

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.

Source:
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.

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.

Source:
Returns:
Type
Promise

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.

Source:
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

Selection query.

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.

Source:
Returns:
Type
Promise

getOpt(opt, opts)

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

Parameters:
Name Type Argument Description
opt string

The name of the option.

opts Object <optional>

Configuration options.

Source:
Returns:

The value of the specified option.

Type
*

loadBelongsTo()

Load a belongsTo relationship.

Source:
Returns:
Type
Promise

loadHasMany()

Load a hasMany relationship.

Source:
Returns:
Type
Promise

loadHasOne()

Load a hasOne relationship.

Source:
Returns:
Type
Promise

log()

Logging utility method.

Source:

makeBelongsToForeignKey()

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

Source:
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.

Source:
Returns:
Type
*

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.

Source:
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.

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.

Source:
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.

Source:
Returns:
Type
Promise