Home Reference Source Repository
public class | source

RethinkAdapter

Extends:

@nrser/supermodel~Adapter → RethinkAdapter

Supermodel Adapter for RethinkDB.

Constructor Summary

Public Constructor
public

constructor(rethinkdb: rethinkdb, conn: rethinkdb.Net.Connection)

Member Summary

Public Members
public

conn: *

public

r: *

Method Summary

Public Methods
public

ensureDBSetup(recordClasses: *): *

ensure the DB is setup for the record classes.

public

ensureIndexes(recordClasses: *, objectPattern1: {"wait": *}): *

ensure all the indexes declared in the Record class exist, creating if necessary.

public

ensureTables(recordClasses: *): *

ensure tables for the Record classes have been created.

public

handleWriteResponse(response: *): *

handle write (insert, replace) response from RethinkDB, which has an errors field with the number of write errors.

public

insert(record: *): *

insert a Record into the database.

public

replace(record: *): *

replace a Record in the database.

public

table(recordClass: *): *

get the rethink table for a Record class.

public

tableName(recordClass: *): *

get the table name for a Record class; uses the tcomb type name.

Public Constructors

public constructor(rethinkdb: rethinkdb, conn: rethinkdb.Net.Connection) source

Params:

NameTypeAttributeDescription
rethinkdb rethinkdb
  • optional

the module returned from require('rethinkdb').

we need to pass it in so that we don't end up using a different instantiation than the one that created the connection.

conn rethinkdb.Net.Connection
  • optional

connection to the rethink database.

Public Members

public conn: * source

public r: * source

Public Methods

public ensureDBSetup(recordClasses: *): * source

ensure the DB is setup for the record classes.

includes:

  1. ensure the database exists.
  2. for each Record class:
    1. ensure the table exists.
    2. ensure the indexes exist.

Params:

NameTypeAttributeDescription
recordClasses *

Return:

*

public ensureIndexes(recordClasses: *, objectPattern1: {"wait": *}): * source

ensure all the indexes declared in the Record class exist, creating if necessary. if wait is true, uses rethinkdb.indexWait to wait for the index to be ready.

returns a Promise<void> that resolves when all done, or rejects on error.

Params:

NameTypeAttributeDescription
recordClasses *
objectPattern1 {"wait": *}
  • optional
  • default: {}

Return:

*

public ensureTables(recordClasses: *): * source

ensure tables for the Record classes have been created.

returns a Promise of an object with table names mapped to whether the table had to be created or not.

Params:

NameTypeAttributeDescription
recordClasses *

Return:

*

public handleWriteResponse(response: *): * source

handle write (insert, replace) response from RethinkDB, which has an errors field with the number of write errors.

convert it into a Promise rejection if present.

Params:

NameTypeAttributeDescription
response *

Return:

*

public insert(record: *): * source

insert a Record into the database.

returns a new Record instance that reflects the changes (setting updatedAt).

Params:

NameTypeAttributeDescription
record *

Return:

*

public replace(record: *): * source

replace a Record in the database.

returns a new Record instance that reflects the changes (setting updatedAt).

Params:

NameTypeAttributeDescription
record *

Return:

*

public table(recordClass: *): * source

get the rethink table for a Record class.

Params:

NameTypeAttributeDescription
recordClass *

Return:

*

public tableName(recordClass: *): * source

get the table name for a Record class; uses the tcomb type name.

Params:

NameTypeAttributeDescription
recordClass *

Return:

*