-
Notifications
You must be signed in to change notification settings - Fork 33
Repositories
Jasper Blues edited this page Feb 24, 2020
·
3 revisions
Repositories are a common pattern of structuring object-oriented code, in order to adhere to single responsibility principle (SRP). They logically group database operations for a particular type of entity.
Simply by using composition, the PersistenceManager can be used to implement repositories. Here is an example:
@Injectable()
export class HealthRepository {
constructor(@InjectPersistenceManager() readonly persistenceManager: NonTransactionalPersistenceManager) {}
async countAllVertices(): Promise<number> {
return this.persistenceManager.getOne<number>(
new QuerySpecification(`match (n) return count(n) as count`)
.map((it) => it.count);
);
}
}
Looking for a quick start? Try the sample application | Something not clear? Send us a tweet! | drivine.org