Constructor
new FirebaseObject(ref, snapshot)
Create a FirebaseObject
Parameters:
Name | Type | Description |
---|---|---|
ref |
object | The database reference. |
snapshot |
object | The snapshot of data from vanilla firebase db admin sdk. |
- Source:
Methods
(async, static) allExists(ref, keys) → {Promise.<boolean>}
Check if all objects exist or not
Parameters:
Name | Type | Description |
---|---|---|
ref |
object | database reference |
keys |
Array.<string> | key of the object |
- Source:
Returns:
- Type
- Promise.<boolean>
(async, static) createByAutoKey(ref, fieldToVal) → {Promise.<FirebaseObject>}
Create object by reference and with given value (assigns automatic key)
Parameters:
Name | Type | Description |
---|---|---|
ref |
object | database reference |
fieldToVal |
object | field of the object mapped to value of that field |
- Source:
Returns:
- Type
- Promise.<FirebaseObject>
(async, static) createByManualKey(ref, key, fieldToVal) → {Promise.<FirebaseObject>}
Create object by reference and with given value (assigns manual key)
Parameters:
Name | Type | Description |
---|---|---|
ref |
object | database reference |
key |
string | key of object |
fieldToVal |
object | field of the object mapped to value of that field |
- Source:
Returns:
- throws error if key is taken
- Type
- Promise.<FirebaseObject>
(async, static) deleteByKey(ref, key) → {Promise.<FirebaseObject>}
Delete object by reference and key
Parameters:
Name | Type | Description |
---|---|---|
ref |
object | database reference |
key |
string | key of the object |
- Source:
Returns:
- throws error if key does not exist
- Type
- Promise.<FirebaseObject>
(async, static) exists(ref, key) → {Promise.<boolean>}
Check if object exists or not
Parameters:
Name | Type | Description |
---|---|---|
ref |
object | database reference |
key |
string | key of the object |
- Source:
Returns:
- Type
- Promise.<boolean>
(async, static) getAll(ref) → {Promise.<Array.<FirebaseObject>>}
Get all objects by database reference
Parameters:
Name | Type | Description |
---|---|---|
ref |
object | database reference |
- Source:
Returns:
- Type
- Promise.<Array.<FirebaseObject>>
(async, static) getAllByBounds(ref, fieldToBound) → {Promise.<Array.<FirebaseObject>>}
Get all objects by database reference and bounds
Parameters:
Name | Type | Description |
---|---|---|
ref |
object | database reference |
fieldToBound |
object | field of the object mapped to bound of that field (bound is an array with 2 items: start and end (both exclusivley)) |
- Source:
Returns:
- Type
- Promise.<Array.<FirebaseObject>>
(async, static) getAllByFields(ref, fieldToVal) → {Promise.<Array.<FirebaseObject>>}
Get all objects by database reference and values
Parameters:
Name | Type | Description |
---|---|---|
ref |
object | database reference |
fieldToVal |
object | field of the object mapped to value of that field |
- Source:
Returns:
- Type
- Promise.<Array.<FirebaseObject>>
(async, static) getAllByKeys(ref, keys) → {Promise.<Array.<FirebaseObject>>}
Get all objects by database reference and keys
Parameters:
Name | Type | Description |
---|---|---|
ref |
object | database reference |
keys |
Array.<string> | keys of objects |
- Source:
Returns:
- Type
- Promise.<Array.<FirebaseObject>>
(async, static) getAllThatStartsWith(ref, field, value) → {Promise.<Array.<FirebaseObject>>}
Get all objects by database reference and field that starts with given value
Parameters:
Name | Type | Description |
---|---|---|
ref |
object | database reference |
field |
string | field of the object |
value |
string | the thing the field starts with |
- Source:
Returns:
- Type
- Promise.<Array.<FirebaseObject>>
(async, static) getByKey(ref, key) → {Promise.<FirebaseObject>}
Get object by database reference and key
Parameters:
Name | Type | Description |
---|---|---|
ref |
object | database reference |
key |
string | key of the object |
- Source:
Returns:
- throws error if key does not exist
- Type
- Promise.<FirebaseObject>
(static) jsonAll() → {Array.<JSON>}
Package objects into easy digestable jsons
- Source:
Returns:
- Type
- Array.<JSON>
(static) listenForQuery(ref, fieldopt, valueopt, emitCb, onceopt)
Initializes listener for all database event types (except 'value') with query
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
ref |
object | database reference | |
field |
string |
<optional> |
specific field you want to listen for (needed if value passed in) |
value |
<optional> |
value the field should be equal to (needed if field passed in) | |
emitCb |
function | callback that triggers when changes detected | |
once |
boolean |
<optional> |
set to true if you want event to only fire once |
- Source:
(async, static) transactAppendToList(ref, key, field, value, isUniqueListopt) → {Promise.<FirebaseObject>}
Run transaction (append item to list) on field of object
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
ref |
object | database reference | |
key |
string | key of object | |
field |
string | field you wish to commit the transaction on | |
value |
value you want to append to the array | ||
isUniqueList |
boolean |
<optional> |
True means its a Set, False means its a List |
- Source:
Returns:
- Type
- Promise.<FirebaseObject>
(async, static) transaction(ref, key, field, atomicFn) → {Promise.<FirebaseObject>}
Run transaction on field of object with atomic function
Parameters:
Name | Type | Description |
---|---|---|
ref |
object | database reference |
key |
string | key of object |
field |
string | field you wish to commit the transaction on |
atomicFn |
function | function that represents the transaction being done |
- Source:
Returns:
- Type
- Promise.<FirebaseObject>
(async, static) transactNum(ref, key, field, delta) → {Promise.<FirebaseObject>}
Run transaction (increase/decrease of number) on field of object
Parameters:
Name | Type | Description |
---|---|---|
ref |
object | database reference |
key |
string | key of object |
field |
string | field you wish to commit the transaction on |
delta |
number | amount to change the number by |
- Source:
Returns:
- Type
- Promise.<FirebaseObject>
(async, static) transactRemoveFromList(ref, key, field, value, isUniqueListopt) → {Promise.<FirebaseObject>}
Run transaction (remove item from list) on field of object
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
ref |
object | database reference | |
key |
string | key of object | |
field |
string | field you wish to commit the transaction on | |
value |
value you want to remove from the array | ||
isUniqueList |
boolean |
<optional> |
True means its a Set, False means its a List |
- Source:
Returns:
- Type
- Promise.<FirebaseObject>
(async, static) updateByKey(ref, key, fieldToVal) → {Promise.<FirebaseObject>}
Update object by reference, key, and values
Parameters:
Name | Type | Description |
---|---|---|
ref |
object | database reference |
key |
string | key of the object |
fieldToVal |
object | object with fields of the value you want to update |
- Source:
Returns:
- throws error if key does not exist
- Type
- Promise.<FirebaseObject>
(async) delete()
Deletes object locally and remotely
- Source:
(async) fetch()
Fetches changes to this object from database
- Source:
getEvent() → {string}
Possible event strings: 'value', 'added', 'changed', 'removed'.
'value' indicates its a one time value fetched objects.
'added' indicates the object was fetched in child_added listener.
'changed' indicates the object was fetched in child_changed listener.
'removed' indiciates the object was fetched in child_removed listener.
- Source:
Returns:
- Type
- string
getKey() → {string}
Returns key of the object.
- Source:
Returns:
- Type
- string
getTimeUpdated() → {null|number}
Returns epoch unix timestamp of when object was last changed, or null if no update field set.
- Source:
Returns:
- Type
- null | number
getValue() → {object}
Returns value of the object.
- Source:
Returns:
- Type
- object
isSynced() → {boolean}
Returns whether or not object is synced with database.
- Source:
Returns:
- Type
- boolean
json() → {JSON}
Package object into easy digestable json
- Source:
Returns:
- Type
- JSON
listenForChanges(field, emitCb, onceopt)
Initializes listener for all database event types (except 'value')
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
field |
string | specific field you want to listen for | |
emitCb |
function | callback that triggers when changes detected | |
once |
boolean |
<optional> |
set to true if you want event to only fire once |
- Source:
listenForChanges(emitCb, onceopt)
Initializes listener for all database event types (except 'value')
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
emitCb |
function | callback that triggers when changes detected | |
once |
boolean |
<optional> |
set to true if you want event to only fire once |
- Source:
(async) push()
Pushes changes to this object to database
- Source:
toString() → {string}
toString method for debugging purposes
- Source:
Returns:
- Type
- string
(async) transactAppendToList(field, value, isUniqueListopt)
Run transaction (append item to list) on field of object (applies changes locally and remotely)
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
field |
string | field you wish to commit the transaction on | |
value |
value you want to append to the array | ||
isUniqueList |
boolean |
<optional> |
True means its a Set, False means its a List |
- Source:
(async) transaction(field, atomicFn)
Run transaction on field of object with atomic function (applies changes locally and remotely)
Parameters:
Name | Type | Description |
---|---|---|
field |
string | field you wish to commit the transaction on |
atomicFn |
function | function that represents the transaction being done |
- Source:
(async) transactNum(field, delta)
Run transaction (increase/decrease of number) on field of object (applies changes locally and remotely)
Parameters:
Name | Type | Description |
---|---|---|
field |
string | field you wish to commit the transaction on |
delta |
number | amount to change the number by |
- Source:
(async) transactRemoveFromList(field, value, isUniqueListopt)
Run transaction (remove item from list) on field of object (applies changes locally and remotely)
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
field |
string | field you wish to commit the transaction on | |
value |
value you want to remove from the array | ||
isUniqueList |
boolean |
<optional> |
True means its a Set, False means its a List |
- Source:
(async) update(fieldToVal)
Updates object locally and remotely
Parameters:
Name | Type | Description |
---|---|---|
fieldToVal |
object | object with fields of the value you want to update |
- Source: