helper utility for repository pattern of PofEAA
Project description
rebecca.repository
An implementation of repository pattern for SQLAlchemy.
Getting Started
install by pip:
$ pip install rebecca.repository
Implement 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)
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.
basic dict interface
create object for demonstration:
person1 = Person(name=u"person1") DBSession.add(person1) DBSession.flush() # to generate person.id
A repository has dict like interface:
person_repository[person.id] person_repository.get(person.id)
conditional repository
repository can configure to set condition:
person_repository = SQALRepository(Person, Person.id, DBSession(), condition=Person.age>30)
pyramid integration
rebecca.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')
Contributors
Atsushi Odagiri, Original Author
Changelog
0.2 (2013-08-25)
added pyramid config directive and venusian decorator
0.1.1 (2013-08-24)
fix packaging bug
0.1 (2013-08-24)
first release
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file rebecca.repository-0.2.zip
.
File metadata
- Download URL: rebecca.repository-0.2.zip
- Upload date:
- Size: 9.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa59b54d7c42dac748958aeeea22ab9f6448a3e9aab5e2966f2b8c98c6996922 |
|
MD5 | 7e09a019ba03f32665270356c8b67ddf |
|
BLAKE2b-256 | d6d319d8406aa69f4a8fdb9d223db2ab589f0e58dcf336702393085dca3b5e4d |