[sqlalchemy] Moving from Mysql to postgresql and Case Insensitive querys
Hi, I am use to setup the collation in MySQL to ci_utf8 (Case Insensitive) I would like the same behaviour on PostgreSQL. I use Unicode (Or UnicodeText) as columntype If I leave the Collation empty it defaults to C which means it looks at bytecodes so it will NOT be case insensitive. Postgress supports (Since 8.4) the citext columntype. Is there any simple way of getting my queries to work in Case Insensitive mode Kind Regards, Martijn -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] moving from mapper extension to events
Looking at the events for instances. The on_expire passes a list of attributes being expired but the on_refresh does not have a list of attribute being refresh. Can the list of attribute being refreshed be add to on_refresh event ? I am looking to move from using mapperextension to instance events. I am using 2 methods: reconstruct_instance: find when a model is load for the first time populate_instance: find when a model is refresh/loading attributes and which attributes find when a model is loaded again with populate_existing looks like i can use on_load to replace reconstruct_instance. not sure about replacing populate_instance. The doc make me think that on_populate_instance should not be used. If this is the case then it would be nice if on_refresh had a list attribute being refreshed. populate_instance has a flag called only_load_props that i used to tell if just refresh attributes or rereading record from database using populate_existing. The last issues is how to catch reread of a record using populate_existing ? -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] moving from mapper extension to events
On Dec 29, 2010, at 5:04 PM, Mike Bernson wrote: Looking at the events for instances. The on_expire passes a list of attributes being expired but the on_refresh does not have a list of attribute being refresh. Can the list of attribute being refreshed be add to on_refresh event ? this is planned ! I am looking to move from using mapperextension to instance events. I am using 2 methods: reconstruct_instance: find when a model is load for the first time populate_instance: find when a model is refresh/loading attributes and which attributes find when a model is loaded again with populate_existing looks like i can use on_load to replace reconstruct_instance. reconstruct_instance is synonymous with on_load. on_refresh() means something that was already present was matched by an incoming row and had either expired attributes or populate_existing. not sure about replacing populate_instance. The doc make me think that on_populate_instance should not be used. yes that event was from 0.1 and isn't very event-like, it was meant as a put your own populate-the-instance-routine-here, and that's a really bad idea. The instance isn't necessarily yet populated when this is called. If this is the case then it would be nice if on_refresh had a list attribute being refreshed. this is planned ! populate_instance has a flag called only_load_props that i used to tell if just refresh attributes or rereading record from database using populate_existing. The last issues is how to catch reread of a record using populate_existing ? populate_existing() is the same as an expired record being populated with applicable rows that have come in.So these events look the same. The information would ultimately be if the QueryContext were passed through and you were to dig into it and look for the populate_existing flag.Adding this would imply its available to both on_refresh() and on_load(). It's probably worth adding context to on_load() and on_refresh(). -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] Moving (new) objects between sessions and committing?
Greetings SA community! I've got mapped objects being created and added to a session, but not committed. Once in a while, I'd like to do something a-la: oid = 42 object = MyClass(oid) sessionA.add(object) # ... time passes, things happen ... then object = get_obj_from_session(oid, sessionA) sessionA.expunge(object) sessionB = gimme_a_new_session() sessionB.add(object) sessionB.commit() sessionB.close() This fails to actually save the object to the db: nothing is inserted as SA seems to think the object is an up to date reflection of some (non-existent) row in the db. The problem, I think, is the InstanceState associated with this object from its initial residence in sessionA. This state has lotsa stuff in it, including a 'key' attribute that looks something like: (model.MyClass, 42) I've read elsewhere that the solution is do delete the instance state 'key', but this only hangs my program with no indication as to why. In any case, this seems like a solution that involves way to much knowledge of the internals for my taste. I've tried a number of things, everything from trying to merge() into the new session, deleting the entire instance state from the object, deleting + expunging from sessionA and other random things, to no avail. Doing a deep copy of the expunged object might be possible, to then add that to the new session, but would involve a lot of work for something that seems like it should be straightforward with SQLAlchemy... My questions are: - why does the instance state think it doesn't need to insert this object, that was never committed? - SA seems to be acting as if the object is in a Detached state after the expunge, even though it was never committed and does not exist in the db. Why and can I somehow force this to Transient before the sessionB.add() or Pending, after? - why doesn't expunge remove all references to the original session/ state -- is there a way to do this? - maybe I'm going about this completely wrong... any other method I should be using? Thanks in advance and regards, Pat Deegan --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] moving an object
Hi all, I wonder if SA can handle this use case: An Account can contain Entries ordered by 'position' attribute. mapper(Account, table_accounts, properties = dict( entries = relation(Entry, lazy=True, collection_class=ordering_list ('position'), order_by=[table_entries.c.position], passive_deletes='all', cascade='save-update', backref=backref('account', lazy=False), ), )) I'd like to move an entry from accountA to accountB and let SA remove the link between the entry and accountA: entry = accountA.entries[0] insort_right(accountB.entries, entry) assert not entry in accountA.entries# false, entry is still in accountA It is possible? Thank you, jean-philippe --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Moving On
Hi, I've had fun over the last 18 months doing odd bits of work on SQLAlchemy. It works pretty damn well on MSSQL now, although I never did quite get all the unit tests nailed. It's been great seeing the library continue to evolve, and particularly satisfying to see things I've started (e.g. AutoCode) being taken forward. Just of late, I've been reassessing priorities in my life, and open source development isn't going to be a big one going forward. In fact, I may even be giving up the computer completely for a year or two and going travelling. I'll be unsubscribing from the mailing list in a couple of days, although I'm happy to receive SA related emails at my personal address, for the next couple of months at least. Thanks for the interesting times, Paul --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] moving objects between sessions
Is it possible to move a pending object that is a child in a relation to a new sessions without flushing the objects original session? - import sqlalchemy from sqlalchemy import * from sqlalchemy.orm import * uri = 'sqlite:///:memory:' metadata = MetaData() genus_table = Table('genus', metadata, Column('id', Integer, primary_key=True), Column('genus', String(32), nullable=False)) species_table = Table('species', metadata, Column('id', Integer, primary_key=True), Column('sp', String(64)), Column('genus_id', Integer, ForeignKey('genus.id'), nullable=False)) class Genus(object): pass class Species(object): pass mapper(Genus, genus_table, properties = { 'species': relation(Species, cascade='all, delete-orphan', backref=backref('genus', uselist=False))}) mapper(Species, species_table) engine = create_engine(uri) engine.connect() metadata.bind = engine metadata.create_all() print 'SQLAlchemy: %s' % sqlalchemy.__version__ try: sqlalchemy.version sm = sessionmaker(bind=engine, autoflush=False, transactional=False) session = sm() new_session = sm() except: session = create_session() new_session = create_session() genus_table.insert().execute({'id': 1, 'genus': 'Somegenus'}) g = session.load(Genus, 1) if True: s = Species() s.genus = g else: s = Species() g.species.append(s) if False: s2 = Species() session.expunge(s) for prop in object_mapper(s).iterate_properties: name = prop.key value = getattr(s, name) if value not in (None, []) and hasattr(value, '_instance_key'): value = new_session.load(value.__class__, value.id) setattr(s2, name, value) new_session.save_or_update(s2) else: s2 = new_session.merge(s) session.expunge(s) new_session.flush() #session.flush() # uncomment this to make it work # should print [1] print [s.genus_id for s in g.species] --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---