Instance
Kind: global class
- Instance
- .raw() ⇒
Object - .toJSON() ⇒
string - .getValue(name) ⇒
* - .setValue(name, value)
- .get([name]) ⇒
* - .set(name, [value])
- .update(data, [options]) ⇒
Promise - .remove([options]) ⇒
Promise - .refresh([options]) ⇒
Promise - .save([options]) ⇒
Promise
instance.raw() ⇒ Object
Give the data relative to the instance in an object of the form { fieldName: value }
Kind: instance method of Instance
instance.toJSON() ⇒ string
JSON representation of the instance
Kind: instance method of Instance
instance.getValue(name) ⇒ *
Get the raw value of a field
Kind: instance method of Instance
| Param | Type | Description |
|---|---|---|
| name | string |
The name of the field |
instance.setValue(name, value)
Set the raw value of a field
Kind: instance method of Instance
| Param | Type | Description |
|---|---|---|
| name | string |
The name of the field |
| value | string | Number |
The value of the field |
instance.get([name]) ⇒ *
Get the value of a field using the getter if provided in the model. If the field is a reference it returns the according model instance. If no name is provided it returns an object filled with all values the same way
Kind: instance method of Instance
| Param | Type | Description |
|---|---|---|
| [name] | string |
The name of the field |
instance.set(name, [value])
Set the value of a field using the setter if provided in the model. If you pass an object as first argument then it calls set on each key / value. It is possible to set a reference by giving a model instance value or an object.
Kind: instance method of Instance
| Param | Type | Description |
|---|---|---|
| name | string | Object |
The name of the field |
| [value] | * |
The value of the field |
instance.update(data, [options]) ⇒ Promise
Update the instance with new data and save them in the database. This is equivalent to calling set + save
Kind: instance method of Instance
Resolve: ModelInstance
| Param | Type | Description |
|---|---|---|
| data | Object |
The updated data as { fieldName: value } |
| [options] | Object |
|
| [options.using] | PoolConnection |
Use this connection |
instance.remove([options]) ⇒ Promise
Remove the instance in database and reset it as new This means you can call still use this instance
Kind: instance method of Instance
Resolve: ModelInstance
| Param | Type | Description |
|---|---|---|
| [options] | Object |
|
| [options.using] | PoolConnection |
Use this connection |
instance.refresh([options]) ⇒ Promise
Refresh the instance by fetching data from the database. This does not affect references.
Kind: instance method of Instance
Resolve: ModelInstance
| Param | Type | Description |
|---|---|---|
| [options] | Object |
|
| [options.using] | PoolConnection |
Use this connection |
instance.save([options]) ⇒ Promise
Save the instance in the database. If the instance is marked as new it is inserted, otherwise it is updated. The updated data are only the fields that have been explicitly set.
Kind: instance method of Instance
Resolve: ModelInstance
| Param | Type | Description |
|---|---|---|
| [options] | Object |
|
| [options.using] | PoolConnection |
Use this connection |