e = MetaData('sqlite://')
e.bind.echo = True
+Session = scoped_session(sessionmaker(transactional=True))
+
# this table represents Entity objects. each Entity gets a row in this table,
# with a primary key and a title.
entities = Table('entities', e,
the value to the underlying datatype of its EntityField."""
def __init__(self, key=None, value=None):
if key is not None:
- sess = create_session()
- self.field = sess.query(EntityField).get_by(name=key) or EntityField(key)
- # close the session, which will make a loaded EntityField a detached instance
- sess.close()
+ self.field = Session.query(EntityField).filter(EntityField.name==key).first() or EntityField(key)
if self.field.datatype is None:
if isinstance(value, int):
self.field.datatype = 'int'
# create two entities. the objects can be used about as regularly as
# any object can.
-session = create_session()
+session = Session()
entity = Entity()
entity.title = 'this is the first entity'
entity.name = 'this is the name'
if not hasattr(instance, '_instance_key'):
raise exceptions.InvalidRequestError("Instance '%s' is not persisted" % mapperutil.instance_str(instance))
elif self.identity_map.get(instance._instance_key, instance) is not instance:
- raise exceptions.InvalidRequestError("Could not update instance '%s', identity key %s; a different instance with the same identity key already exists in this session." % (mapperutil.instance_str(obj), obj._instance_key))
+ raise exceptions.InvalidRequestError("Could not update instance '%s', identity key %s; a different instance with the same identity key already exists in this session." % (mapperutil.instance_str(instance), instance._instance_key))
self._attach(instance)
def _save_or_update_impl(self, instance, entity_name=None):