Created
March 5, 2014 13:42
-
-
Save phillipsj/9367366 to your computer and use it in GitHub Desktop.
Repository pattern example for Postgres-py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from postgres.orm import Model | |
from postgres import Postgres | |
class Foo(Model): | |
typname = "foo" | |
class FooRepository(connection_string): | |
def __init__(self): | |
self.db = Postgres(connection_string) | |
self.db.register_model(Foo) | |
def get_all(self): | |
return self.db.all("SELECT foo.*::foo FROM foo") | |
repo = FooRepository("<connection-string>") | |
foos = repo.get_all() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment