Home > @infiniteobjects/models > Repository
Base Repository
Signature:
export declare class Repository<EntityType extends BaseFirebaseEntity, CurrentSchema = Schema<EntityType>, AnySchema = CurrentSchema>
Constructor | Modifiers | Description |
---|---|---|
(constructor)(entity, migration) | Constructs a new instance of the Repository class |
Property | Modifiers | Type | Description |
---|---|---|---|
collectionId | readonly |
string | The collection ID in Firebase |
createOrUpdate | (entry: EntityType, findFn?: (entry: EntityType) => Promise<EntityType | null>) => Promise<EntityType> | Creates or updates a DB Entry | |
debug | readonly |
DebugInstance | A debugger function under the name io:model:name:db |
delete | (doc: EntityType) => Promise<EntityType> | Deletes an entity from the database | |
Entity | readonly |
ClassConstructor<EntityType> | The Entity this Repository manages |
entityName | readonly |
string | The name of the entity (kebabCase of Class name) |
GoogleCloud | <p>protected </p><p>readonly </p> |
GoogleCloud | A reference to the Google Cloud service connection |
initializeEntity | (entity: EntityType) => Promise<EntityType> | Prepares the entity after is being pulled from firebase. - runs initialize hooks - runs populate hooks | |
insert | (doc: EntityType) => Promise<EntityType> | Inserts a new entity in the database | |
log | readonly |
LoggerInstance | A logger instance under the name io:model:name:db |
Migration | readonly |
Migration<EntityType, CurrentSchema, AnySchema> | Migrations |
projectId | readonly |
string | The current google Project id |
protectedKeys | protected |
KeysArray<EntityType> | Keys that will never be updated |
update | (doc: EntityType, merge?: boolean) => Promise<EntityType> | Updates an entity in the database | |
upsert | (doc: EntityType, merge?: boolean) => Promise<EntityType> | (BETA) Upsert an entity in the database |
Method | Modifiers | Description |
---|---|---|
count() | Returns the number of documents in the collection | |
create(data, admin) | Creates and Saves an Entity | |
diffInstances(instanceA, instanceB) | Returns the difference between two instances | |
exists(id, reject, code) | Check if the document exist | |
findById(id) | Finds a document by ID | |
findById(id, reject) | ||
findById(id, reject, code) | ||
getAll(limit, offset) | Finds all documents in the collection | |
getCollectionRef() | A reference to collection with the converter already applied | |
getDefaultData() | Gets the default data of the collection | |
getDocumentRef(id) | A reference to a document in a collection | |
instanceFromModel(data) | Creates and instance of from the given plain object (partial Model) | |
instanceFromModel(data, admin) | ||
instanceFromModel(data, admin, useDefaultData) | ||
instanceFromModel(data, admin, useDefaultData) | ||
instanceFromSchema(data) | Creates and instance of from the given plain object (partial schema) | |
instanceFromSchema(data, useDefaultData) | ||
instanceFromSchema(data, useDefaultData) | ||
isInstance(obj) | Returns true if the given object is an instance of the Entity | |
setDefaultData(data) | Sets the default data of the collection | |
updateInstance(data, instance, admin) | Updates an entity with new data |