new Mapper(opts)
import {Mapper} from 'js-data'
The core of JSData's ORM/ODM implementation. Given a minimum amout of meta information about a resource, a Mapper can perform generic CRUD operations against that resource. Apart from its configuration, a Mapper is stateless. The particulars of various persistence layers has been abstracted into adapters, which a Mapper uses to perform its operations.
The term "Mapper" comes from the Data Mapper Pattern described in Martin Fowler's Patterns of Enterprise Application Architecture. A Data Mapper moves data between in-memory object instances and a relational or document-based database. JSData's Mapper can work with any persistence layer you can write an adapter for.
("Model" is a heavily overloaded term and is avoided in this documentation to prevent confusion.)
Parameters:
Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
opts |
Object | Configuration options. Properties
|
Extends
Members
-
_adapters
-
Hash of registered adapters. Don't modify directly. Use Mapper#registerAdapter.
-
_listeners :Object
-
Event listeners attached to this Component. Do not modify. Use Component#on and Component#off instead.
Type:
- Object
- Inherited From:
- Source:
-
applySchema :boolean
-
Whether to augment Mapper#recordClass with getter/setter property accessors according to the properties defined in Mapper#schema. This makes possible validation and change tracking on individual properties when using the dot (e.g.
user.name = "Bob"
) operator to modify a property.Type:
- boolean
-
debug :boolean
-
Whether to enable debug-level logs.
Type:
- boolean
-
defaultAdapter :string
-
The name of the registered adapter that this Mapper should used by default.
Type:
- string
-
idAttribute :string
-
The field used as the unique identifier on records handled by this Mapper.
Type:
- string
-
name :string
-
Minimum amount of meta information required for a Mapper to be able to execute CRUD operations for a "Resource".
Type:
- string
-
notify :boolean
-
Whether this Mapper should emit operational events.
Defaults to
true
in the browser andfalse
in Node.jsType:
- boolean
-
raw :boolean
-
Whether Mapper#create, Mapper#createMany, Mapper#save, Mapper#update, Mapper#updateAll, Mapper#updateMany, Mapper#find, Mapper#findAll, Mapper#destroy, and Mapper#destroyAll should return a raw result object that contains both the instance data returned by the adapter and metadata about the operation.
The default is to NOT return the result object, and instead return just the instance data.
Type:
- boolean
-
recordClass
-
Set the
false
to force the Mapper to work with POJO objects only.import {Mapper, Record} from 'js-data' const UserMapper = new Mapper({ recordClass: false }) UserMapper.recordClass // false const user = UserMapper#createRecord() user instanceof Record // false
Set to a custom class to have records wrapped in your custom class.
import {Mapper, Record} from 'js-data' // Custom class class User { constructor (props = {}) { for (var key in props) { if (props.hasOwnProperty(key)) { this[key] = props[key] } } } } const UserMapper = new Mapper({ recordClass: User }) UserMapper.recordClass // function User() {} const user = UserMapper#createRecord() user instanceof Record // false user instanceof User // true
Extend the Record class.
import {Mapper, Record} from 'js-data' // Custom class class User extends Record { constructor () { super(props) } } const UserMapper = new Mapper({ recordClass: User }) UserMapper.recordClass // function User() {} const user = UserMapper#createRecord() user instanceof Record // true user instanceof User // true
Methods
-
afterCount(query, opts, result)
-
Mapper lifecycle hook called by Mapper#count. If this method returns a promise then Mapper#count will wait for the promise to resolve before continuing.
Parameters:
Name Type Description query
Object The
query
argument passed to Mapper#count.opts
Object The
opts
argument passed to Mapper#count.result
* The result, if any.
-
afterCreate(props, opts, result)
-
Mapper lifecycle hook called by Mapper#create. If this method returns a promise then Mapper#create will wait for the promise to resolve before continuing.
Parameters:
Name Type Description props
Object The
props
argument passed to Mapper#create.opts
Object The
opts
argument passed to Mapper#create.result
* The result, if any.
-
afterCreateMany(records, opts, result)
-
Mapper lifecycle hook called by Mapper#createMany. If this method returns a promise then Mapper#createMany will wait for the promise to resolve before continuing.
Parameters:
Name Type Description records
Array The
records
argument passed to Mapper#createMany.opts
Object The
opts
argument passed to Mapper#createMany.result
* The result, if any.
-
afterDestroy(id, opts, result)
-
Mapper lifecycle hook called by Mapper#destroy. If this method returns a promise then Mapper#destroy will wait for the promise to resolve before continuing.
Parameters:
Name Type Description id
string | number The
id
argument passed to Mapper#destroy.opts
Object The
opts
argument passed to Mapper#destroy.result
* The result, if any.
-
afterDestroyAll(data, query, opts, result)
-
Mapper lifecycle hook called by Mapper#destroyAll. If this method returns a promise then Mapper#destroyAll will wait for the promise to resolve before continuing.
Parameters:
Name Type Description data
* The
data
returned by the adapter.query
query The
query
argument passed to Mapper#destroyAll.opts
Object The
opts
argument passed to Mapper#destroyAll.result
* The result, if any.
-
afterFind(id, opts, result)
-
Mapper lifecycle hook called by Mapper#find. If this method returns a promise then Mapper#find will wait for the promise to resolve before continuing.
Parameters:
Name Type Description id
string | number The
id
argument passed to Mapper#find.opts
Object The
opts
argument passed to Mapper#find.result
* The result, if any.
-
afterFindAll(query, opts, result)
-
Mapper lifecycle hook called by Mapper#findAll. If this method returns a promise then Mapper#findAll will wait for the promise to resolve before continuing.
Parameters:
Name Type Description query
Object The
query
argument passed to Mapper#findAll.opts
Object The
opts
argument passed to Mapper#findAll.result
* The result, if any.
-
afterSum(query, opts, result)
-
Mapper lifecycle hook called by Mapper#sum. If this method returns a promise then Mapper#sum will wait for the promise to resolve before continuing.
Parameters:
Name Type Description query
Object The
query
argument passed to Mapper#sum.opts
Object The
opts
argument passed to Mapper#sum.result
* The result, if any.
-
afterUpdate(id, props, opts, result)
-
Mapper lifecycle hook called by Mapper#update. If this method returns a promise then Mapper#update will wait for the promise to resolve before continuing.
Parameters:
Name Type Description id
string | number The
id
argument passed to Mapper#update.props
props The
props
argument passed to Mapper#update.opts
Object The
opts
argument passed to Mapper#update.result
* The result, if any.
-
afterUpdateAll(props, query, opts, result)
-
Mapper lifecycle hook called by Mapper#updateAll. If this method returns a promise then Mapper#updateAll will wait for the promise to resolve before continuing.
Parameters:
Name Type Description props
Object The
props
argument passed to Mapper#updateAll.query
Object The
query
argument passed to Mapper#updateAll.opts
Object The
opts
argument passed to Mapper#updateAll.result
* The result, if any.
-
afterUpdateMany(records, opts, result)
-
Mapper lifecycle hook called by Mapper#updateMany. If this method returns a promise then Mapper#updateMany will wait for the promise to resolve before continuing.
Parameters:
Name Type Description records
Array The
records
argument passed to Mapper#updateMany.opts
Object The
opts
argument passed to Mapper#updateMany.result
* The result, if any.
-
beforeCount(query, opts)
-
Mapper lifecycle hook called by Mapper#count. If this method returns a promise then Mapper#count will wait for the promise to resolve before continuing.
Parameters:
Name Type Description query
Object The
query
argument passed to Mapper#count.opts
Object The
opts
argument passed to Mapper#count. -
beforeCreate(props, opts)
-
Mapper lifecycle hook called by Mapper#create. If this method returns a promise then Mapper#create will wait for the promise to resolve before continuing.
Parameters:
Name Type Description props
Object The
props
argument passed to Mapper#create.opts
Object The
opts
argument passed to Mapper#create. -
beforeCreateMany(records, opts)
-
Mapper lifecycle hook called by Mapper#createMany. If this method returns a promise then Mapper#createMany will wait for the promise to resolve before continuing.
Parameters:
Name Type Description records
Array The
records
argument passed to Mapper#createMany.opts
Object The
opts
argument passed to Mapper#createMany. -
beforeDestroy(id, opts)
-
Mapper lifecycle hook called by Mapper#destroy. If this method returns a promise then Mapper#destroy will wait for the promise to resolve before continuing.
Parameters:
Name Type Description id
string | number The
id
argument passed to Mapper#destroy.opts
Object The
opts
argument passed to Mapper#destroy. -
beforeDestroyAll(query, opts)
-
Mapper lifecycle hook called by Mapper#destroyAll. If this method returns a promise then Mapper#destroyAll will wait for the promise to resolve before continuing.
Parameters:
Name Type Description query
query The
query
argument passed to Mapper#destroyAll.opts
Object The
opts
argument passed to Mapper#destroyAll. -
beforeFind(id, opts)
-
Mappers lifecycle hook called by Mapper#find. If this method returns a promise then Mapper#find will wait for the promise to resolve before continuing.
Parameters:
Name Type Description id
string | number The
id
argument passed to Mapper#find.opts
Object The
opts
argument passed to Mapper#find. -
beforeFindAll(query, opts)
-
Mapper lifecycle hook called by Mapper#findAll. If this method returns a promise then Mapper#findAll will wait for the promise to resolve before continuing.
Parameters:
Name Type Description query
Object The
query
argument passed to Mapper#findAll.opts
Object The
opts
argument passed to Mapper#findAll. -
beforeSum(field, query, opts)
-
Mapper lifecycle hook called by Mapper#sum. If this method returns a promise then Mapper#sum will wait for the promise to resolve before continuing.
Parameters:
Name Type Description field
string The
field
argument passed to Mapper#sum.query
Object The
query
argument passed to Mapper#sum.opts
Object The
opts
argument passed to Mapper#sum. -
beforeUpdate(id, props, opts)
-
Mapper lifecycle hook called by Mapper#update. If this method returns a promise then Mapper#update will wait for the promise to resolve before continuing.
Parameters:
Name Type Description id
string | number The
id
argument passed to Mapper#update.props
props The
props
argument passed to Mapper#update.opts
Object The
opts
argument passed to Mapper#update. -
beforeUpdateAll(props, query, opts)
-
Mapper lifecycle hook called by Mapper#updateAll. If this method returns a promise then Mapper#updateAll will wait for the promise to resolve before continuing.
Parameters:
Name Type Description props
Object The
props
argument passed to Mapper#updateAll.query
Object The
query
argument passed to Mapper#updateAll.opts
Object The
opts
argument passed to Mapper#updateAll. -
beforeUpdateMany(records, opts)
-
Mapper lifecycle hook called by Mapper#updateMany. If this method returns a promise then Mapper#updateMany will wait for the promise to resolve before continuing.
Parameters:
Name Type Description records
Array The
records
argument passed to Mapper#updateMany.opts
Object The
opts
argument passed to Mapper#updateMany. -
belongsTo()
-
Define a belongsTo relationship. Only useful if you're managing your Mappers manually and not using a Container or DataStore component.
Post.belongsTo(User, { localKey: 'myUserId' }) Comment.belongsTo(User) Comment.belongsTo(Post, { localField: '_post' })
-
count(query, opts)
-
Using the
query
argument, select records to pull from an adapter. Expects back from the adapter the array of selected records.Mapper#beforeCount will be called before calling the adapter. Mapper#afterCount will be called after calling the adapter.
Parameters:
Name Type Argument Default Description query
Object <optional>
{} Selection query.
Properties
Name Type Argument Description where
Object <optional>
Filtering criteria.
skip
number <optional>
Number to skip.
limit
number <optional>
Number to limit to.
orderBy
Array <optional>
Sorting criteria.
opts
Object <optional>
Configuration options.
Properties
Name Type Argument Default Description adapter
boolean <optional>
Mapper#defaultAdapter Name of the adapter to use.
notify
boolean <optional>
Mapper#notify Whether to emit lifecycle events.
raw
boolean <optional>
Mapper#raw If
false
, return the resulting data. Iftrue
return a response object that includes the resulting data and metadata about the operation.Returns:
- Type
- Promise
-
create(props, opts)
-
Create and save a new the record using the provided
props
.Mapper#beforeCreate will be called before calling the adapter. Mapper#afterCreate will be called after calling the adapter.
Parameters:
Name Type Argument Description props
Object The properties for the new record.
opts
Object <optional>
Configuration options.
Properties
Name Type Argument Default Description adapter
boolean <optional>
Mapper#defaultAdapter Name of the adapter to use.
notify
boolean <optional>
Mapper#notify Whether to emit lifecycle events.
raw
boolean <optional>
Mapper#raw If
false
, return the created data. Iftrue
return a response object that includes the created data and metadata about the operation.with
Array.<string> <optional>
[] Relations to create in a cascading create if
props
contains nested relations. NOT performed in a transaction. Each nested create will result in another Mapper#create or Mapper#createMany call.pass
Array.<string> <optional>
[] Relations to send to the adapter as part of the payload. Normally relations are not sent.
Returns:
- Type
- Promise
-
createMany(records, opts)
-
Given an array of records, batch create them via an adapter.
Mapper#beforeCreateMany will be called before calling the adapter. Mapper#afterCreateMany will be called after calling the adapter.
Parameters:
Name Type Argument Description records
Array Array of records to be created in one batch.
opts
Object <optional>
Configuration options.
Properties
Name Type Argument Default Description adapter
boolean <optional>
Mapper#defaultAdapter Name of the adapter to use.
notify
boolean <optional>
Mapper#notify Whether to emit lifecycle events.
raw
boolean <optional>
Mapper#raw If
false
, return the updated data. Iftrue
return a response object that includes the updated data and metadata about the operation.with
Array.<string> <optional>
[] Relations to create in a cascading create if
records
contains nested relations. NOT performed in a transaction. Each nested create will result in another Mapper#createMany call.pass
Array.<string> <optional>
[] Relations to send to the adapter as part of the payload. Normally relations are not sent.
Returns:
- Type
- Promise
-
createRecord(props, opts)
-
Create an unsaved, uncached instance of this Mapper's Mapper#recordClass.
Returns
props
ifprops
is already an instance of Mapper#recordClass.Parameters:
Name Type Argument Description props
Object | Array The properties for the Record instance or an array of property objects for the Record instances.
opts
Object <optional>
Configuration options.
Properties
Name Type Argument Default Description noValidate
boolean <optional>
false Whether to skip validation when the Record instances are created.
Returns:
The Record instance or Record instances.
- Type
- Object | Array
-
crud(method, args)
-
Lifecycle invocation method.
Parameters:
Name Type Argument Description method
string Name of the lifecycle method to invoke.
args
* <repeatable>
Arguments to pass to the lifecycle method.
Returns:
- Type
- Promise
-
dbg()
-
TODO
- Inherited From:
- Source:
-
destroy(id, opts)
-
Using an adapter, destroy the record with the primary key specified by the
id
argument.Mapper#beforeDestroy will be called before destroying the record. Mapper#afterDestroy will be called after destroying the record.
Parameters:
Name Type Argument Description id
string | number The primary key of the record to destroy.
opts
Object <optional>
Configuration options.
Properties
Name Type Argument Default Description adapter
boolean <optional>
Mapper#defaultAdapter Name of the adapter to use.
notify
boolean <optional>
Mapper#notify Whether to emit lifecycle events.
raw
boolean <optional>
Mapper#raw If
false
, return the ejected data (if any). Iftrue
return a response object that includes the ejected data (if any) and metadata about the operation.with
Array.<string> <optional>
[] Relations to destroy in a cascading delete. NOT performed in a transaction.
Returns:
- Type
- Promise
-
destroyAll(query, opts)
-
Using the
query
argument, destroy the selected records via an adapter. If noquery
is provided then all records will be destroyed.Mapper#beforeDestroyAll will be called before destroying the records. Mapper#afterDestroyAll will be called after destroying the records.
Parameters:
Name Type Argument Default Description query
Object <optional>
{} Selection query.
Properties
Name Type Argument Description where
Object <optional>
Filtering criteria.
skip
number <optional>
Number to skip.
limit
number <optional>
Number to limit to.
orderBy
Array <optional>
Sorting criteria.
opts
Object <optional>
Configuration options.
Properties
Name Type Argument Default Description adapter
boolean <optional>
Mapper#defaultAdapter Name of the adapter to use.
notify
boolean <optional>
Mapper#notify Whether to emit lifecycle events.
raw
boolean <optional>
Mapper#raw If
false
, return the ejected data (if any). Iftrue
return a response object that includes the ejected data (if any) and metadata about the operation.with
Array.<string> <optional>
[] Relations to destroy in a cascading delete. NOT performed in a transaction.
Returns:
- Type
- Promise
-
emit(event, args)
-
Trigger an event on this Component.
Parameters:
Name Type Argument Description event
string Name of event to emit.
args
* <optional>
<repeatable>
Arguments to pass to any listeners.
- Inherited From:
- Source:
-
find(id, opts)
-
Retrieve via an adapter the record with the given primary key.
Mapper#beforeFind will be called before calling the adapter. Mapper#afterFind will be called after calling the adapter.
Parameters:
Name Type Argument Description id
string | number The primary key of the record to retrieve.
opts
Object <optional>
Configuration options.
Properties
Name Type Argument Default Description adapter
boolean <optional>
Mapper#defaultAdapter Name of the adapter to use.
notify
boolean <optional>
Mapper#notify Whether to emit lifecycle events.
raw
boolean <optional>
Mapper#raw If
false
, return the updated data. Iftrue
return a response object that includes the updated data and metadata about the operation.with
Array.<string> <optional>
[] Relations to eager load in the request.
Returns:
- Type
- Promise
-
findAll(query, opts)
-
Using the
query
argument, select records to pull from an adapter. Expects back from the adapter the array of selected records.Mapper#beforeFindAll will be called before calling the adapter. Mapper#afterFindAll will be called after calling the adapter.
Parameters:
Name Type Argument Default Description query
Object <optional>
{} Selection query.
Properties
Name Type Argument Description where
Object <optional>
Filtering criteria.
skip
number <optional>
Number to skip.
limit
number <optional>
Number to limit to.
orderBy
Array <optional>
Sorting criteria.
opts
Object <optional>
Configuration options.
Properties
Name Type Argument Default Description adapter
boolean <optional>
Mapper#defaultAdapter Name of the adapter to use.
notify
boolean <optional>
Mapper#notify Whether to emit lifecycle events.
raw
boolean <optional>
Mapper#raw If
false
, return the resulting data. Iftrue
return a response object that includes the resulting data and metadata about the operation.with
Array.<string> <optional>
[] Relations to eager load in the request.
Returns:
- Type
- Promise
-
getAdapter(name)
-
Return the registered adapter with the given name or the default adapter if no name is provided.
Parameters:
Name Type Argument Description name
string <optional>
The name of the adapter to retrieve.
Returns:
The adapter.
- Type
- Adapter
-
getAdapterName(opts)
-
Return the name of a registered adapter based on the given name or options, or the name of the default adapter if no name provided.
Parameters:
Name Type Argument Description opts
Object | string <optional>
The name of an adapter or options, if any.
Returns:
The name of the adapter.
- Type
- string
-
getAdapters()
-
Returns:
This Mapper's adapters
- Type
- Object
-
hasMany()
-
Defines a hasMany relationship. Only useful if you're managing your Mappers manually and not using a Container or DataStore component.
User.hasMany(Post, { localField: 'my_posts' })
-
hasOne()
-
Defines a hasOne relationship. Only useful if you're managing your Mappers manually and not using a Container or DataStore component.
User.hasOne(Profile, { localField: '_profile' })
-
is(record)
-
Return whether
record
is an instance of this Mapper's recordClass.Parameters:
Name Type Description record
Object The record to check.
Returns:
Whether
record
is an instance of this Mapper's Mapper#recordClass.- Type
- boolean
-
log()
-
TODO
- Inherited From:
- Source:
-
off(event, listener)
-
Remove an event listener from this Component. If no listener is provided, then all listeners for the specified event will be removed. If no event is specified then all listeners for all events will be removed.
Parameters:
Name Type Argument Description event
string <optional>
Name of event to unsubsribe to.
listener
function <optional>
Listener to remove.
- Inherited From:
- Source:
-
on(event, listener, ctx)
-
Register a new event listener on this Component.
Parameters:
Name Type Argument Description event
string Name of event to subsribe to.
listener
function Listener function to handle the event.
ctx
* <optional>
Optional content in which to invoke the listener.
- Inherited From:
- Source:
-
registerAdapter(name, adapter, opts)
-
Register an adapter on this mapper under the given name.
Parameters:
Name Type Argument Description name
string The name of the adapter to register.
adapter
Adapter The adapter to register.
opts
Object <optional>
Configuration options.
Properties
Name Type Argument Default Description default
boolean <optional>
false Whether to make the adapter the default adapter for this Mapper.
-
sum(field, query, opts)
-
Using the
query
argument, select records to pull from an adapter. Expects back from the adapter the array of selected records.Mapper#beforeSum will be called before calling the adapter. Mapper#afterSum will be called after calling the adapter.
Parameters:
Name Type Argument Default Description field
string The field to sum.
query
Object <optional>
{} Selection query.
Properties
Name Type Argument Description where
Object <optional>
Filtering criteria.
skip
number <optional>
Number to skip.
limit
number <optional>
Number to limit to.
orderBy
Array <optional>
Sorting criteria.
opts
Object <optional>
Configuration options.
Properties
Name Type Argument Default Description adapter
boolean <optional>
Mapper#defaultAdapter Name of the adapter to use.
notify
boolean <optional>
Mapper#notify Whether to emit lifecycle events.
raw
boolean <optional>
Mapper#raw If
false
, return the resulting data. Iftrue
return a response object that includes the resulting data and metadata about the operation.Returns:
- Type
- Promise
-
toJSON(record, opts)
-
Return a plain object representation of the given record.
Parameters:
Name Type Argument Description record
Object Record from which to create a plain object representation.
opts
Object <optional>
Configuration options.
Properties
Name Type Argument Description with
Array.<string> <optional>
Array of relation names or relation fields to include in the representation.
Returns:
Plain object representation of the record.
- Type
- Object
-
update(id, props, opts)
-
Using an adapter, update the record with the primary key specified by the
id
argument.Mapper#beforeUpdate will be called before updating the record. Mapper#afterUpdate will be called after updating the record.
Parameters:
Name Type Argument Description id
string | number The primary key of the record to update.
props
Object The update to apply to the record.
opts
Object <optional>
Configuration options.
Properties
Name Type Argument Default Description adapter
boolean <optional>
Mapper#defaultAdapter Name of the adapter to use.
notify
boolean <optional>
Mapper#notify Whether to emit lifecycle events.
raw
boolean <optional>
Mapper#raw If
false
, return the updated data. Iftrue
return a response object that includes the updated data and metadata about the operation.with
Array.<string> <optional>
[] Relations to update in a cascading update if
props
contains nested updates to relations. NOT performed in a transaction.Returns:
- Type
- Promise
-
updateAll(props, query, opts)
-
Using the
query
argument, perform the a single updated to the selected records. Expects back from the adapter an array of the updated records.Mapper#beforeUpdateAll will be called before making the update. Mapper#afterUpdateAll will be called after making the update.
Parameters:
Name Type Argument Default Description props
Object Update to apply to selected records.
query
Object <optional>
{} Selection query.
Properties
Name Type Argument Description where
Object <optional>
Filtering criteria.
skip
number <optional>
Number to skip.
limit
number <optional>
Number to limit to.
orderBy
Array <optional>
Sorting criteria.
opts
Object <optional>
Configuration options.
Properties
Name Type Argument Default Description adapter
boolean <optional>
Mapper#defaultAdapter Name of the adapter to use.
notify
boolean <optional>
Mapper#notify Whether to emit lifecycle events.
raw
boolean <optional>
Mapper#raw If
false
, return the updated data. Iftrue
return a response object that includes the updated data and metadata about the operation.with
Array.<string> <optional>
[] Relations to update in a cascading update if
props
contains nested updates to relations. NOT performed in a transaction.Returns:
- Type
- Promise
-
updateMany(records, opts)
-
Given an array of updates, perform each of the updates via an adapter. Each "update" is a hash of properties with which to update an record. Each update must contain the primary key to be updated.
Mapper#beforeUpdateMany will be called before making the update. Mapper#afterUpdateMany will be called after making the update.
Parameters:
Name Type Argument Description records
Array Array up record updates.
opts
Object <optional>
Configuration options.
Properties
Name Type Argument Default Description adapter
boolean <optional>
Mapper#defaultAdapter Name of the adapter to use.
notify
boolean <optional>
Mapper#notify Whether to emit lifecycle events.
raw
boolean <optional>
Mapper#raw If
false
, return the updated data. Iftrue
return a response object that includes the updated data and metadata about the operation.with
Array.<string> <optional>
[] Relations to update in a cascading update if each record update contains nested updates for relations. NOT performed in a transaction.
Returns:
- Type
- Promise
-
validate(record, opts)
-
Validate the given record or records according to this Mapper's Schema. No return value means no errors.
Parameters:
Name Type Argument Description record
Object | Array The record or records to validate.
opts
Object <optional>
Configuration options. Passed to Schema#validate.
Returns:
Array of errors or undefined if no errors.
- Type
- Array
-
wrap(data, opts)
-
Method used to wrap data returned by an adapter with this Mapper's Record class.
Parameters:
Name Type Argument Description data
Object | Array The data to be wrapped.
opts
Object <optional>
Configuration options. Passed to Mapper#createRecord.
Returns:
- Type
- Object | Array