Package: rebecca.repository
Contentsrebecca.repositoryGetting StartedRepository for SQLAlchemybasic repositoryconditional repositoryrepository factoryRepository for Filesystemrepository interfacepyramid integrationContributorsChangelog0.4 (2013-09-22)0.3 (2013-08-29)0.2 (2013-08-25)0.1.1 (2013-08-24)0.1 (2013-08-24)rebecca.repositoryAn implementation of repository pattern for SQLAlchemy.Getting Startedinstall by pip:$ pip install rebecca.repositoryRepository for SQLAlchemybasic repositoryImplement your model by SQLAlchemy:from sqlalchemy import Column, Integer, Unicode
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()
DBSession = scoped_session(sessionmaker())

class Person(Base):
    __tablename__ = "person"
    id = Column(Integer, primary_key=True)
    name = Column(Unicode(255))
    age = Column(Integer, default=0)
    job = Column(Unicode(255))Get repository:from rebecca.repository.sqla import SQLARepository

person_repository = SQALRepository(Person, Person.id, DBSession())this repository for Person model.
To get person, use Person.id as key.conditional repositoryrepository can configure to set condition:person_repository = SQALRepository(Person, Person.id, DBSession(), condition=Person.age>30)repository factoryIf you pass the parameters during request time, use factory.class JobPersonRepository(SQLARepository):
    def __init__(self, db_session, job):
        super(JobPersonRepository, self).__init__(Person, Person.id, dbsession,
                                                  condition=Person.job==job)The parameterjobwill be passed from request attribute.To register repository factory, add_repository_factory directive:config.add_repository_factory(JobPersonRepository, "job-person", args=(DBSession,))or repository_factory_config decorator:@repository_factory_config("job-person", args=(DBSession,))
class JobPersonRepository(SQLARepository):
    ....To create repository from registered factory, call create_repository API:job = request.matchdict["job"]
repository = create_repository("person", args=(job,))Repository for Filesystemrebecca.repository.fs.FileSystemRepositoryis repository for FileSystem:>>> repository = FileSystemRepository(directory="/path/to/data")
>>> item = repository.new_item("new-item")
>>> item.data = b"testing-binary-data"
>>> import transaction
>>> transaction.commit()FileSystemRepository.new_itemis create new file system entry.item.datais binary data that saved in the file.
That’s transactional withtransaction.NoteFileSystemRepositoryusesrepoze.filesafethat not supports py3k yet.repository interfacecreate object for demonstration:person1 = Person(name=u"person1")
DBSession.add(person1)
DBSession.flush() # to generate person.idA repository has dict like interface:person_repository[person.id]
person_repository.get(person.id)and utility methods:person_repository.get_many([1, 2, 3])
new_person = person_repository.new_item()pyramid integrationrebecca.repository provides directive for pyramid registry.:config.include('rebecca.repository')
config.add_repository(person_repository, 'person')or using repository_config decorator:@repository_config(name="person", args=(DBSession,))
class PersonRepository(SQLARepository):
    def __init__(self, dbsession):
        super(PersonRepository, self).__init__(Person, Person.id, dbsession)To get registered repositories, use get_repository:get_repository(request, 'person')ContributorsAtsushi Odagiri, Original AuthorChangelog0.4 (2013-09-22)file repository(yet)0.3 (2013-08-29)added repository factory APIadded get_many method0.2 (2013-08-25)added pyramid config directive and venusian decorator0.1.1 (2013-08-24)fix packaging bug0.1 (2013-08-24)first release