Skip to content

Instantly share code, notes, and snippets.

@phillipsj
Created March 5, 2014 13:42
Show Gist options
  • Save phillipsj/9367366 to your computer and use it in GitHub Desktop.
Save phillipsj/9367366 to your computer and use it in GitHub Desktop.
Repository pattern example for Postgres-py
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