Extends
Members
Type:
string
_private
Type:
Object
_private
Type:
Object
Type:
StorageAdapter
Constructor
- name
- Type:
string name of the Model
- schema
- Type:
Object structure definition of stored data
- options optional
- Type:
Object - key optional
- Type:
Key - Default:
UUID4Key The strategy used for document's
keygeneration. Must inherit from baseKeyclass- refDocKey optional
- Type:
RefDocKey - Default:
RefDocKey The strategy used for reference document
keygeneration. Must inherit from baseRefDocKeyclass- timestamps optional
- Type:
boolean - Default:
true Adds automatically handled timestamp schema properties:
created_at,updated_atand ifparanoidoption is true,deleted_atproperty- paranoid optional
- Type:
boolean - Default:
false if
trueis set, a document is not actually removed frombucketbut ratherdeleted_atflag on the document is set. aka.soft delete- camelCase optional
- Type:
boolean - Default:
false if
trueis set, camel case notation is used for document's internal properties.- schemaSettings optional
- Type:
Object allows to modify default values used for document's
keygeneration and document's property names handled by ODM- key optional
- Type:
Object - prefix optional
- Type:
string defaults to Model's name
- postfix optional
- Type:
string - Default:
"" - delimiter optional
- Type:
string - Default:
"_" - doc optional
- Type:
Object - idPropertyName optional
- Type:
string - Default:
"_id" _idcontains generated id of document (not whole document's key)- typePropertyName optional
- Type:
string - Default:
"_type" _typecontains the name of a Model- hooks optional
- Type:
Object allows to add one or more hooks of a hook type (eg.
afterValidate)- classMethods optional
- Type:
Object custom method definitions which are bound to a Model.
- instanceMethods optional
- Type:
Object custom method definitions which are bound to a Instance.
- bucket optional
- Type:
Bucket must be instance of Couchbase.Bucket (from official nodejs couchbase sdk)
- indexes optional
- Type:
Object - refDocs optional
- Type:
Object reference documents definitions aka. custom application layer index support. ref. doc. is a document which reference parent document with its string value=key
Parameters:
Throws:
Methods
- data
- Type:
mixed In case an Object or an Array is provided, the data value is NOT cloned!
- options optional
- Type:
Object - isNewRecord optional
- Type:
boolean - Default:
true - sanitize optional
- Type:
boolean - Default:
false if true, data values are validated, an attempt is made to convert property values to correct type
- cas optional
- Type:
CAS - key optional
- Type:
Keyorstring instance of Key or valid string
id(-> dynamic part of Key) should be provided if the isNewRecord=false that meens the document is persisted in storage- id optional
- Type:
string - options optional
- Type:
Object - parse optional
- Type:
boolean - Default:
false if true,
idargument will be treated as whole document'skeystring. By defaultidis presumed to be only "dynamic part of document's key"- id optional
- Type:
stringorArray - options
- Type:
Object - index
- Type:
String index name - one of the keys from
options.indexes.refDocsobject of Model options- parse optional
- Type:
Boolean - Default:
false - data
- Type:
Object - options optional
- Type:
Object see
StorageAdaper#insertoptions- key optional
- Type:
stringorKey the key under which a document should be saved. Can be instance of
Keyor valid stringid(-> dynamic part of Key)- id
- Type:
stringorKey - options optional
- Type:
object - plain optional
- Type:
boolean if true, raw data are returned
- lockTime optional
- Type:
integer time in seconds (max=30)
- expiry optional
- Type:
integer time in seconds. if provided, the method performs
touchoperation on document, returning the most recent document data- hooks optional
- Type:
boolean - Default:
true if false,
hooksare not run- paranoid optional
- Type:
boolean - Default:
true if false, both deleted and non-deleted documents will be returned. Only applies if
options.paranoidis true for the model.- ids
- Type:
[(string | Key), ...] - options optional
- Type:
Object - plain optional
- Type:
boolean - Default:
false if true, Instances are not built and raw results are collected instead
- lockTime optional
- Type:
integer time in seconds (max=30)
- expiry optional
- Type:
integer time in seconds
- hooks optional
- Type:
boolean - Default:
true if false,
hooksare not run- indexed optional
- Type:
boolean - Default:
true if true, a results are indexed by document's
idvalue, otherwise an array of results is collected- individualHooks optional
- Type:
boolean - Default:
false if true,
hooksare run for each get query. if set to false, hooks are only run once before and aftergetMultioperation- paranoid optional
- Type:
boolean - Default:
true if false, both deleted and non-deleted documents will be returned. Only applies if
options.paranoidis true for the model.- id
- Type:
stringorKey - expiry
- Type:
integer See
StorageAdapter#touchfor more information
Instance
builds a new Model instance object
Parameters:
Throws:
Returns:Instance
Key
return a new instance of document's primary key
Parameters:
Key
RefDocKey
return a new instance of RefDocKey = primary key of a document referencing parent document with it's value
Parameters:
RefDocKey
Parameters:
Promise<Object>
if a key is not found, it returns resolved promise with null value
Model#getByIdOrFail arguments
if a key is not found, it returns rejected promise with StorageError which has appropriate error code
Parameters:
Promise<Object>
if a operation fails to get a id from ids array,
a StorageError is returned in place of resulting value
in returned collection/map.
Parameters:
Throws:
Returns:Promise<Object>
Example:
//PSEUDOCODE:
var ids = [
'829f52b2-f168-4538-8884-b5ad9054e391',
'nonexistent-id'
];
// Indexed results
Model.getMulti(ids, {indexed: true}).then((result) => {
console.log(result);
});
// The above prints:
{
data: {
'829f52b2-f168-4538-8884-b5ad9054e391': Document, // object
'nonexistent-id': Error // object
},
failed: ['nonexistend-id'],
resolved: [Document]
}
// Non-indexed results
Model.getMulti(ids, {indexed: false}).then((result) => {
console.log(result);
});
// The above prints:
{
data: [
Document, //object
Error //object
],
failed: [1], // collection of indexes referencing data array items
resolved: [Document]
}
Promise<Object>
Parameters:
Promise<Object>
Promise<Object>
Inherited Methods
- fn
- Type:
function hook function
- name
- Type:
string the identificator
- fn
- Type:
function hook function
- name
- Type:
string the identificator
- fn
- Type:
function hook function
- name
- Type:
string the identificator
- fn
- Type:
function hook function
- name
- Type:
string the identificator
- fn
- Type:
function hook function
- name
- Type:
string the identificator
- fn
- Type:
function hook function
- name
- Type:
string the identificator
- fn
- Type:
function hook function
- name
- Type:
string the identificator
- fn
- Type:
function hook function
- name
- Type:
string the identificator
- fn
- Type:
function hook function
- name
- Type:
string the identificator
- fn
- Type:
function hook function
- name
- Type:
string the identificator
- fn
- Type:
function hook function
- name
- Type:
string the identificator
- fn
- Type:
function hook function
- name
- Type:
string the identificator
- fn
- Type:
function hook function
- name
- Type:
string the identificator
- fn
- Type:
function hook function
- name
- Type:
string the identificator
- hookType
- Type:
stringorObject
this
adds hook function to the stack
Parameters:
this
this
adds hook function to the stack
Parameters:
this
this
adds hook function to the stack
Parameters:
this
this
adds hook function to the stack
Parameters:
this
this
adds hook function to the stack
Parameters:
this
this
adds hook function to the stack
Parameters:
this
this
adds hook function to the stack
Parameters:
this
this
adds hook function to the stack
Parameters:
this
this
adds hook function to the stack
Parameters:
this
this
adds hook function to the stack
Parameters:
this
this
adds hook function to the stack
Parameters:
this
this
adds hook function to the stack
Parameters:
this
this
adds hook function to the stack
Parameters:
this
this
adds hook function to the stack
Parameters:
this
Integer
runHooks
additional arguments passed to the function will be passed to the hook function