Constructor
new RethinkDBDashDriver(r,)
Returns a DBDriver instance (for use by Apollo Passport). Parameters are driver-specific and should be clearly specificied in the README. This documents the RethinkDBDash DBDriver specifically, although some options are relevant for all drivers.
Parameters:
Name | Type | Description |
---|---|---|
r, |
rethinkdbdash | e.g. var r = require('rethinkdbdash')(); |
options.userTableName |
string | default: 'users' |
options.configTableName |
string | default: 'apolloPassportConfig' |
options.dbName |
string | default: current database |
Methods
_assertTableExists(name)
Internal method, documented for benefit of driver authors. Asserts (and awaits) that the given table name exists. This is a convenience for the user but with RethinkDB there is no safe way to do this other than creating the table in advance (outside of the app). It's fine if the table is created with only one app instance running, which is usually the case for initial setup.
Parameters:
Name | Type | Description |
---|---|---|
name |
string | the name of the table to assert |
_init()
Internal method, documented for benefit of driver authors. Most important is to call fetchConfig() (XXX unfinished), but may also assert that all tables exist, and run ready callbacks.
_ready()
Internal method, documented for benefit of driver authors. An awaitable promise that returns if the driver is ready (or when it becomes ready).
assertUserEmailData(userId, email, data)
Given a userId, ensures the user record contains the given email address, and updates it with optional data.
Parameters:
Name | Type | Description |
---|---|---|
userId |
string | the id of the user to assert |
email |
string | the email address to ensure exists |
data |
object | optional, e.g. { type: 'work', verified: true } |
assertUserServiceData(userId, service, data)
Given a userId, ensure the user record contains the given service record, and updates it with the given data.
Parameters:
Name | Type | Description |
---|---|---|
userId |
string | the id of the user to assert |
service |
string | the name of the service, e.g. "facebook" |
data |
object | e.g. { id: "4321", displayName: "John Sheppard" } |
createUser(user) → {string}
Given a user record, save it to the database, and return its given id. NoSQL databases should store the entire object, schema-based databases should honor the 'emails' and 'services' keys and store as necessary in another table.
Parameters:
Name | Type | Description |
---|---|---|
user |
object | { emails: [ { address: "me@me.com" } ], services: [ { facebook: { id: 1, ...profile } } ] ...anyOtherDataForUserRecordAtCreationTimeFromAppHooks } |
Returns:
the id of the inserted user record
- Type
- string
fetchConfig() → {object}
Retrieves all configuration from the database.
Returns:
A nested dictionary arranged by type, i.e.
{
service: { // type
facebook: { // id
...data // value (de-JSONified if from non-document DB)
}
}
}
- Type
- object
fetchUserByEmail(email) → {object}
Given a single "email" param, returns the matching user record if one exists, or null, otherwise.
Parameters:
Name | Type | Description |
---|---|---|
email |
string | the email address to search for, e.g. "me@me.com" |
Returns:
user object in the same format expected by RethinkDBDashDriver#createUser, or null if none found.
- Type
- object
fetchUserById(id) → {object}
Fetches a user record by id. Schema-based databases should merge
appropriate user-data from e.g. user_emails
and user_services
.
Parameters:
Name | Type | Description |
---|---|---|
id |
string | the user record's id |
Returns:
user object in the same format expected by RethinkDBDashDriver#createUser, or null if none found.
- Type
- object
fetchUserByServiceIdOrEmail(service, id, email) → {object}
Returns a user who has either a matching email address or matching service record, or null, otherwise.
Parameters:
Name | Type | Description |
---|---|---|
service |
string | name of the service, e.g. "facebook" |
id |
string | id of the service record, e.g. "152356242" |
email |
string | the email address to search for, e.g. "me@me.com" |
Returns:
user object in the same format expected by RethinkDBDashDriver#createUser, or null if none found
- Type
- object
setConfigKey(type, id, value)
Creates or updates the key with the given value. NoSQL databases can store the destructured value as part of the record. Fixed-schema databases should JSON-encode the 'value' column.
Parameters:
Name | Type | Description |
---|---|---|
type |
string | e.g. "service" |
id |
string | e.g. "facebook" |
value |
object | e.g. { id: 1, ...profile } |