import {RethinkAdapter} from '@nrser/supermodel-rethinkdb/src/RethinkAdapter.js'RethinkAdapter
Extends:
Supermodel Adapter for RethinkDB.
Constructor Summary
| Public Constructor | ||
| public |
constructor(rethinkdb: rethinkdb, conn: rethinkdb.Net.Connection) |
|
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
|
|
| 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:
| Name | Type | Attribute | Description |
| rethinkdb | rethinkdb |
|
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 |
|
connection to the rethink database. |
Public Methods
public ensureDBSetup(recordClasses: *): * source
ensure the DB is setup for the record classes.
includes:
- ensure the database exists.
- for each Record class:
- ensure the table exists.
- ensure the indexes exist.
Params:
| Name | Type | Attribute | Description |
| 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:
| Name | Type | Attribute | Description |
| recordClasses | * | ||
| objectPattern1 | {"wait": *} |
|
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:
| Name | Type | Attribute | Description |
| 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:
| Name | Type | Attribute | Description |
| response | * |
Return:
| * |
public insert(record: *): * source
insert a Record into the database.
returns a new Record instance that reflects the changes (setting
updatedAt).
Params:
| Name | Type | Attribute | Description |
| record | * |
Return:
| * |
public replace(record: *): * source
replace a Record in the database.
returns a new Record instance that reflects the changes (setting
updatedAt).
Params:
| Name | Type | Attribute | Description |
| record | * |
Return:
| * |
public table(recordClass: *): * source
get the rethink table for a Record class.
Params:
| Name | Type | Attribute | Description |
| recordClass | * |
Return:
| * |
public tableName(recordClass: *): * source
get the table name for a Record class; uses the tcomb type name.
Params:
| Name | Type | Attribute | Description |
| recordClass | * |
Return:
| * |