Re: [sqlalchemy] Remove all objects of specified type from session
On Tue, Jan 29, 2019 at 2:52 PM Daniel Leon wrote: > > There is the method expunge which removes specified object from session and > expunge_all which removes all objects from session. Is there a way I can > expunge all objects from certain type? > > We're transitioning from SQLObject, which reveals its cache dictionary. There > are many places where we 'expire' a table by removing all objects of that > type from the cache. the thing you'd call a "cache dictionary" is session.identity_map: https://docs.sqlalchemy.org/en/latest/orm/session_api.html?highlight=session%20identity_map#sqlalchemy.orm.session.Session.identity_map as far as the types you'd need to test the type of each object using isinstance() or something similar. > > -- > SQLAlchemy - > The Python SQL Toolkit and Object Relational Mapper > > http://www.sqlalchemy.org/ > > To post example code, please provide an MCVE: Minimal, Complete, and > Verifiable Example. See http://stackoverflow.com/help/mcve for a full > description. > --- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to sqlalchemy+unsubscr...@googlegroups.com. > To post to this group, send email to sqlalchemy@googlegroups.com. > Visit this group at https://groups.google.com/group/sqlalchemy. > For more options, visit https://groups.google.com/d/optout. -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.
[sqlalchemy] Remove all objects of specified type from session
There is the method expunge which removes specified object from session and expunge_all which removes all objects from session. Is there a way I can expunge all objects from certain type? We're transitioning from SQLObject, which reveals its cache dictionary. There are many places where we 'expire' a table by removing all objects of that type from the cache. -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.
[sqlalchemy] Re: How can I get the field names from an object?
This is almost but not quite what I want. In your example, if the dictionary includes keys that do not map to object fields, it will throw. I want to try and 'cherry-pick' fields of the object from the dictionary. With the introspect you gave me I can do that. Thanks, Dan On Monday, January 28, 2019 at 1:57:44 PM UTC+2, dan.b...@huawei.com wrote: > > > Lets say I have a class > > class Dog(AlchemyBase): > __tablename__ = 'dogs' > name = Column(String, primary_key=True) > color = Column(String) > flees = relationship("Flee", backref="dogs") > > > > How can I get the list of fields ['name', 'color', 'flees'] from the class? > > I'd like to write a generic load(Dog, dict) method, that will create a > Dog() with the field values that exist in dict. > > e.g. > d = {'name: 'snoopy', 'junk': 1} > dog = load(Dog, d) > is equivalent to dog = Dog(name = 'snoopy') > > d1 = {'alias' : 'kitti'} > but load(Cat, d1) > is equivalent to cat = Cat(alias = 'kitti) > > Load will pick field names that exist in the passed Object, and have a > value in dict > > Thanks, > Dan > > -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.
[sqlalchemy] Re: How can I get the field names from an object?
This is doing almost, but not quite what I want. If the dictionary includes entries which are NOT fields in the object, On Monday, January 28, 2019 at 1:57:44 PM UTC+2, dan.b...@huawei.com wrote: > > > Lets say I have a class > > class Dog(AlchemyBase): > __tablename__ = 'dogs' > name = Column(String, primary_key=True) > color = Column(String) > flees = relationship("Flee", backref="dogs") > > > > How can I get the list of fields ['name', 'color', 'flees'] from the class? > > I'd like to write a generic load(Dog, dict) method, that will create a > Dog() with the field values that exist in dict. > > e.g. > d = {'name: 'snoopy', 'junk': 1} > dog = load(Dog, d) > is equivalent to dog = Dog(name = 'snoopy') > > d1 = {'alias' : 'kitti'} > but load(Cat, d1) > is equivalent to cat = Cat(alias = 'kitti) > > Load will pick field names that exist in the passed Object, and have a > value in dict > > Thanks, > Dan > > -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.