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
key
generation. Must inherit from baseKey
class- refDocKey optional
- Type:
RefDocKey
- Default:
RefDocKey
The strategy used for reference document
key
generation. Must inherit from baseRefDocKey
class- timestamps optional
- Type:
boolean
- Default:
true
Adds automatically handled timestamp schema properties:
created_at
,updated_at
and ifparanoid
option is true,deleted_at
property- paranoid optional
- Type:
boolean
- Default:
false
if
true
is set, a document is not actually removed frombucket
but ratherdeleted_at
flag on the document is set. aka.soft delete
- camelCase optional
- Type:
boolean
- Default:
false
if
true
is set, camel case notation is used for document's internal properties.- schemaSettings optional
- Type:
Object
allows to modify default values used for document's
key
generation 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"
_id
contains generated id of document (not whole document's key)- typePropertyName optional
- Type:
string
- Default:
"_type"
_type
contains 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:
Key
orstring
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,
id
argument will be treated as whole document'skey
string. By defaultid
is presumed to be only "dynamic part of document's key"- id optional
- Type:
string
orArray
- options
- Type:
Object
- index
- Type:
String
index name - one of the keys from
options.indexes.refDocs
object of Model options- parse optional
- Type:
Boolean
- Default:
false
- data
- Type:
Object
- options optional
- Type:
Object
see
StorageAdaper#insert
options- key optional
- Type:
string
orKey
the key under which a document should be saved. Can be instance of
Key
or valid stringid
(-> dynamic part of Key)- id
- Type:
string
orKey
- 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
touch
operation on document, returning the most recent document data- hooks optional
- Type:
boolean
- Default:
true
if false,
hooks
are not run- paranoid optional
- Type:
boolean
- Default:
true
if false, both deleted and non-deleted documents will be returned. Only applies if
options.paranoid
is 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,
hooks
are not run- indexed optional
- Type:
boolean
- Default:
true
if true, a results are indexed by document's
id
value, otherwise an array of results is collected- individualHooks optional
- Type:
boolean
- Default:
false
if true,
hooks
are run for each get query. if set to false, hooks are only run once before and aftergetMulti
operation- paranoid optional
- Type:
boolean
- Default:
true
if false, both deleted and non-deleted documents will be returned. Only applies if
options.paranoid
is true for the model.- id
- Type:
string
orKey
- expiry
- Type:
integer
See
StorageAdapter#touch
for 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:
string
orObject
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