1
0
Fork 0
gnuviechadmin-historic/test/ormaptest.py

33 lines
856 B
Python
Raw Normal View History

#!/usr/bin/python
# -*- coding: UTF-8 -*-
from sqlalchemy import *
meta = BoundMetaData('postgres://jan:heyyou97@localhost:5432/jan')
domains_table = Table('domains', meta, autoload=True)
records_table = Table('records', meta, autoload=True)
class Domain(object):
def __repr__(self):
return "%s(%r,%r)" % (
self.__class__.__name__, self.id, self.name)
class Record(object):
def __repr__(self):
return "%s(%r,%r,%r)" % (
self.__class__.__name__, self.id, self.domain_id, self.domain)
recordmapper = mapper(Record, records_table)
domainmapper = mapper(Domain, domains_table, properties = {
'records': relation(Record, backref='domain')
})
session = create_session()
query = session.query(Domain)
domain = query.get_by(name='dittberner.info')
if domain:
print domain.records
session.flush()