Changeset 991 for trunk/packages/sipb-xen-database/python
- Timestamp:
- Oct 1, 2008, 7:48:39 PM (16 years ago)
- Location:
- trunk/packages/sipb-xen-database/python/database
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/sipb-xen-database/python/database/__init__.py
r946 r991 5 5 def connect(uri = config.db.uri): 6 6 """ Connect to a given database URI""" 7 meta.bind = sqlalchemy.create_engine(uri) 7 engine = sqlalchemy.create_engine(uri) 8 meta.bind = engine 9 session.configure(bind=engine) -
trunk/packages/sipb-xen-database/python/database/models.py
r946 r991 1 1 from sqlalchemy import * 2 from sqlalchemy import orm 2 3 from sqlalchemy.orm import create_session, relation 3 4 … … 6 7 7 8 __all__ = ['meta', 8 ' ctx',9 'session', 9 10 'clear_cache', 10 11 'machine_table', … … 26 27 27 28 meta = ThreadLocalMetaData() 28 ctx = SessionContext(create_session)29 session = orm.scoped_session(orm.sessionmaker()) 29 30 30 31 machine_table = Table('machines', meta, … … 106 107 return "<Autoinstall %s: %s (%s)>" % (self.autoinstall_id, self.description, self.type.type_id) 107 108 108 assign_mapper(ctx,Machine, machine_table,109 session.mapper(Machine, machine_table, 109 110 properties={'nics': relation(NIC, backref="machine", lazy=False), 110 111 'disks': relation(Disk, backref="machine", lazy=False), 111 112 'type': relation(Type, lazy=False), 112 113 'acl': relation(MachineAccess, backref="machine", lazy=False, passive_deletes=True, cascade="all, delete-orphan")}); 113 assign_mapper(ctx,MachineAccess, machine_access_table)114 assign_mapper(ctx,NIC, nic_table)115 assign_mapper(ctx,Disk, disk_table)116 assign_mapper(ctx,Type, types_table)117 assign_mapper(ctx,CDROM, cdroms_table)118 assign_mapper(ctx,Autoinstall, autoinstalls_table)114 session.mapper(MachineAccess, machine_access_table) 115 session.mapper(NIC, nic_table) 116 session.mapper(Disk, disk_table) 117 session.mapper(Type, types_table) 118 session.mapper(CDROM, cdroms_table) 119 session.mapper(Autoinstall, autoinstalls_table) 119 120 120 121 def clear_cache(): … … 124 125 it. Why is this so obscure?""" 125 126 126 ctx.registry.clear() 127 # XXX maybe we still need to do this, but it's not doc'd how. 128 #ctx.registry.clear()
Note: See TracChangeset
for help on using the changeset viewer.