ActiveClass Methods
All ActiveClasses - that is, all ES6 classes that extend ActiveClass
- come with some default methods, used for interacting with your Firebase Realtime Database.
Have you initialized?
To interact with your Firebase Realtime Database, you must first initialize
a connection to your Firebase Realtime Database.
Basic CRUD methods
create
Creates a new model from an object and saves it to the database.
Parameters:
props
: an object of properties that conforms to the ActiveClass's Schema
Returns: Promise<ActiveDocument>
, a promise that resolves into the ActiveDocument that has been created
Example
- JavaScript
- TypeScript
delete
Deletes all matching documents that partially match the passed in object.
Parameters:
props
: an object of properties that is consistent with the ActiveClass's Schema (but needn't include all properties)
Returns: Promise<number>
, a promise that resolves with the count of matched documents deleted
Example
- JavaScript
- TypeScript
deleteOne
Deletes the first document that partially matches the passed in object.
Parameters:
props
: an object of properties that is consistent with the ActiveClass's Schema (but needn't include all properties)
Returns: Promise<boolean>
, a promise that resolves with whether or not a document was deleted
Example
- JavaScript
- TypeScript
find
Instantiates an ActiveDocument for every document in the database that partially matches the passed in object.
Parameters:
props
: an object of properties that is consistent with the ActiveClass's Schema (but needn't include all properties)
Returns: Promise<ActiveDocument[]>
, a promise that resolves with an array of ActiveDocuments
Example
- JavaScript
- TypeScript
findById
Instantiates an ActiveDocument for a document with the passed in id.
Parameters:
id
: string
Returns: Promise<ActiveDocument | null>
, a promise that resolves with the matching ActiveDocument if it exists, and null
otherwise
Example
- JavaScript
- TypeScript
findByIdOrFail
Instantiates an ActiveDocument for a document with the passed in id, throwing an error if no document matches.
Parameters:
id
: string
Returns: Promise<ActiveDocument>
, a promise that resolves with the matching ActiveDocument, or otherwise throws an error
Example
- JavaScript
- TypeScript
findOne
Instantiates an ActiveDocument for the first document in the database that partially matches the passed in object.
Parameters:
props
: an object of properties that is consistent with the ActiveClass's Schema (but needn't include all properties)
Returns: Promise<ActiveDocument | null>
, a promise that resolves with the first matching ActiveDocument if any exists, and null
otherwise
Example
- JavaScript
- TypeScript
update
Updates documents that partially match a first object using the properties of a second object.
Parameters:
matchProps
: an object of properties that is consistent with the ActiveClass's Schema (but needn't include all properties), used to match documents to updateupdateProps
: an object of properties that is consistent with the ActiveClass's Schema (but needn't include all properties), used to update all matched documents
Returns: Promise<ActiveDocument[]>
, a promise that resolves with an array of updated ActiveDocuments
Example
- JavaScript
- TypeScript
updateOne
Updates the first document that partially matches an object using the properties of a second object.
Parameters:
matchProps
: an object of properties that is consistent with the ActiveClass's Schema (but needn't include all properties), used to find a document to updateupdateProps
: an object of properties that is consistent with the ActiveClass's Schema (but needn't include all properties), used to update the first matching document
Returns: Promise<ActiveDocument | null>
, a promise that resolves with the updated ActiveDocument if it exists, or null
otherwise
Example
- JavaScript
- TypeScript
Other methods
ref
Returns a Firebase Realtime Database Reference for the ActiveClass 'table', or a specified child reference within it.
Parameters:
path
(string, optional): if specified, retrieves the Reference following thispath
from the root of the ActiveClass's Reference
Returns: Reference
, a Firebase Realtime Database Reference to the ActiveClass 'table', following the (optionally) specified child path
Example
- JavaScript
- TypeScript