[sqlalchemy] Joined table inheritance - get inherited class object

2014-09-26 Thread Alexey Vihorev
Hi! I got this class arrangement: class Document(Base): doc_number = Column(:) doc_date = Column(:) : class Invoice(Document) class CashOrder(Document) class BankTransaction(Document) It's joined table inheritance, Document has a table with discriminator etc. So,

RE: [sqlalchemy] Listening for AttributeEvents: 'set'

2013-12-28 Thread Alexey Vihorev
u can use regular Python idioms for this kind of thing, such as overriding __setattr__() on classes. On Dec 28, 2013, at 8:43 AM, Alexey Vihorev wrote: Hi all! The line event.listen(MyClass.my_attr, 'set', my_listener_method) allows me to react on an attribute being

[sqlalchemy] Listening for AttributeEvents: 'set'

2013-12-28 Thread Alexey Vihorev
Hi all! The line event.listen(MyClass.my_attr, 'set', my_listener_method) allows me to react on an attribute being set. However, this event is fired BEFORE the attribute is actually set. And my app's logic requires me to catch the event AFTER the attribute is set (Using MVVM pattern, I need to not

RE: [sqlalchemy] m2m introspection

2013-12-09 Thread Alexey Vihorev
3, at 5:55 AM, Alexey Vihorev wrote: Hi again! I can do MyClass.iterate_properties()and check if a property is m2m relationship. But how can I find out which class it references? Thanks! -- You received this message because you are subscribed to the Google Groups "sqlalchemy&

[sqlalchemy] m2m introspection

2013-12-08 Thread Alexey Vihorev
Hi again! I can do MyClass.iterate_properties()and check if a property is m2m relationship. But how can I find out which class it references? Thanks! -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receivin

RE: [sqlalchemy] Many2many, referential integrity and introspection

2013-12-08 Thread Alexey Vihorev
sqlalchemy@googlegroups.com] On Behalf Of Michael Bayer Sent: Sunday, December 08, 2013 1:46 AM To: sqlalchemy@googlegroups.com Subject: Re: [sqlalchemy] Many2many, referential integrity and introspection On Dec 7, 2013, at 6:18 PM, Alexey Vihorev wrote: In my case, table 'tags'

RE: [sqlalchemy] Many2many, referential integrity and introspection

2013-12-07 Thread Alexey Vihorev
egroups.com] On Behalf Of Michael Bayer Sent: Saturday, December 07, 2013 11:51 PM To: sqlalchemy@googlegroups.com Subject: Re: [sqlalchemy] Many2many, referential integrity and introspection On Dec 7, 2013, at 2:22 PM, Alexey Vihorev wrote: Here is the full code: from sqlalchemy.

RE: [sqlalchemy] Re: Many2many, referential integrity and introspection

2013-12-07 Thread Alexey Vihorev
Here is the full code: from sqlalchemy.ext.declarative import declarative_base from sqlalchemy import * from sqlalchemy.orm import relationship, sessionmaker Base = declarative_base() product_tags = Table( 'product_tags', Base.metadata, Column('product_id', Integer, ForeignK

[sqlalchemy] Many2many, referential integrity and introspection

2013-12-06 Thread Alexey Vihorev
Hi! A couple of questions. 1. I've got a "Product" class and a "Tag" class, related as m2m. If I delete a product, all rows referencing that product will be removed from the secondary table - which is good. However, the same will happen if I delete a tag (all references to the tag will be removed

[sqlalchemy] Introspection: finding out more about relationships

2013-10-11 Thread Alexey Vihorev
Hi! I'm trying to do some introspection on a class's one-to-many relationships. I'm trying to find out which attribute in "many" table points to the "one" table. Is that possible? Thanks! -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubsc

RE: [sqlalchemy] How to check if relationship is many-to-many?

2013-10-01 Thread Alexey Vihorev
-many the relationship will have a non-None "secondary" attribute - relationship.secondary. Or you could check for "relationship.direction is sqlalchemy.orm.interfaces.MANYTOMANY". On Oct 1, 2013, at 9:41 AM, Alexey Vihorev wrote: Hi! I'm trying to adapt my GUI

[sqlalchemy] How to check if relationship is many-to-many?

2013-10-01 Thread Alexey Vihorev
Hi! I'm trying to adapt my GUI app for handling sqla many-to-many relationships. GUI is auto generated, so I have to find out at run time what relationships should be presented as table views. I tried to use inspection.inspect(MyClass.attribute).uselist to check for it, it it works fine so far, but

RE: [sqlalchemy] Alembic 0.6.0 released

2013-07-25 Thread Alexey Vihorev
Hi! In the former USSR, there is a popular commercial development framework, called 1C:Enterprise. They too have what can be called "code first" approach (more like "set up through GUI first" in their case). For many years they used quite successfully the "freezing" system - they dump metadata in

RE: [sqlalchemy] Alembic 0.6.0 released

2013-07-20 Thread Alexey Vihorev
Very glad to hear it, thanks. Autogenerate improvements would be welcome indeed. -Original Message- From: sqlalchemy@googlegroups.com [mailto:sqlalchemy@googlegroups.com] On Behalf Of Michael Bayer Sent: Saturday, July 20, 2013 1:00 AM To: sqlalchemy@googlegroups.com; sqlalchemy-alem...@go

[sqlalchemy] Inheritance and mltiple references to parent table

2013-07-03 Thread Alexey Vihorev
Hi! Got this setup: class Document(Base): __tablename__ = 'document' discriminator = Column('type', String(30)) __mapper_args__ = {'polymorphic_identity':'document', 'polymorphic_on': discriminator} id = Column(Integer, primary_key=True) numbe

RE: [sqlalchemy] Self-referencing row and CircularDependencyError

2013-05-27 Thread Alexey Vihorev
AM, Alexey Vihorev wrote: Hi! Can I handle this situation properly, if at all? Base = declarative_base() class Person(Base): __tablename__ = 'persons' id = Column(Integer, primary_key=True) best_friend_id = Column(Integer, ForeignKey('persons.id'

[sqlalchemy] Self-referencing row and CircularDependencyError

2013-05-27 Thread Alexey Vihorev
Hi! Can I handle this situation properly, if at all? Base = declarative_base() class Person(Base): __tablename__ = 'persons' id = Column(Integer, primary_key=True) best_friend_id = Column(Integer, ForeignKey('persons.id')) best_friend = relationship('Person', remote_

RE: [sqlalchemy] Enum example

2013-05-12 Thread Alexey Vihorev
to3 -w decl_enum.py On May 12, 2013, at 1:31 PM, Alexey Vihorev wrote: Hi! I'm trying to run enum example provided here <http://techspot.zzzeek.org/files/2011/decl_enum.py> http://techspot.zzzeek.org/files/2011/decl_enum.py and it fails with this: C:\Pyth

[sqlalchemy] Enum example

2013-05-12 Thread Alexey Vihorev
-packages\sqlalchemy\types.py", line 758, in process return process_param(value, dialect) File "C:/Users/Alexey/experimental/ decl_enum.py ", line 86, in process_bind_param return value.value AttributeError: 'tuple' object has no attribute 'value'

RE: [sqlalchemy] Self-referencing augmented class

2013-04-07 Thread Alexey Vihorev
Thanks! From: sqlalchemy@googlegroups.com [mailto:sqlalchemy@googlegroups.com] On Behalf Of Michael Bayer Sent: Sunday, April 07, 2013 5:46 PM To: sqlalchemy@googlegroups.com Subject: Re: [sqlalchemy] Self-referencing augmented class On Apr 7, 2013, at 8:27 AM, Alexey Vihorev wrote

[sqlalchemy] Self-referencing augmented class

2013-04-07 Thread Alexey Vihorev
Hi! I've got this setup: cs = "sqlite:///:memory:" sa_engine = create_engine(cs) Base = declarative_base() class Person(Base): __abstract__ = True id = Column(Integer, primary_key=True) name = Column(String(30)) class Employee(Person): __tablename__ = 'employee

Re: [sqlalchemy] Update object with results of a server-side processing [pgsql]

2013-04-02 Thread Alexey Vihorev
thing like a trigger: > > from sqlalchemy import FetchedValue > > class MyClass(Base): ># ... > >some_col = Column(Integer, server_default=FetchedValue()) > > > > http://docs.sqlalchemy.org/en/rel_0_8/core/schema.html#triggered-columns > > On Apr 1,

[sqlalchemy] Update object with results of a server-side processing [pgsql]

2013-04-01 Thread Alexey Vihorev
Hi! I've got a server-side trigger function (before insert) - it changes some fields of the inserted record, and I need this info back in my SA entity object (akin to what SA does with ID's). SA uses RETURNING whenever it is supported, maybe I can use it as well? Or am I limited to refreshing the

[sqlalchemy] Aggregating results of a union

2013-03-21 Thread Alexey Vihorev
Hi! I have this query: q1 = (s.query() .add_columns( Movement.customer_id, Movement.document_id, func.sum(Movement.debt).label('debt_moved'), literal(

RE: [sqlalchemy] Placeholder values

2013-03-20 Thread Alexey Vihorev
Thanks! Exactly what I needed. -Original Message- From: Ladislav Lenart [mailto:lenart...@volny.cz] Sent: Wednesday, March 20, 2013 8:01 PM To: sqlalchemy@googlegroups.com Cc: Alexey Vihorev Subject: Re: [sqlalchemy] Placeholder values Hello. I think you want this: http

[sqlalchemy] Placeholder values

2013-03-20 Thread Alexey Vihorev
Hi! I've got to unite two tables preserving some of their columns as distinct, so to comply with the "same number, same type" requirement of the UNION operator I use placeholder values, like this: SELECT united.customer_id, united.document_id, SUM(united.debt_moved) AS debt

RE: [sqlalchemy] Couple of questions about filtering...

2013-01-23 Thread Alexey Vihorev
-Original Message- From: sqlalchemy@googlegroups.com [mailto:sqlalchemy@googlegroups.com] On Behalf Of Werner Sent: Wednesday, January 23, 2013 2:00 PM To: sqlalchemy@googlegroups.com Subject: Re: [sqlalchemy] Couple of questions about filtering... On 23/01/2013 07:47, Alexey Vihorev

RE: [sqlalchemy] Couple of questions about filtering...

2013-01-22 Thread Alexey Vihorev
chemy] Couple of questions about filtering... On Tue, 2013-01-22 at 19:58:15 +0200, Alexey Vihorev wrote: > > That's what you want in this case, that this hybrid property would > > get a class, because Query works with classes. Try adding echo=True > > to create_engine() t

RE: [sqlalchemy] Couple of questions about filtering...

2013-01-22 Thread Alexey Vihorev
, 2013, at 08:26 , Alexey Vihorev wrote: Hi. Couple of questions... 1. Does SQLA support "deep filtering", i.e. something like this: query(Invoice).filter(Invoice.Customer.Country.name=='France') You'll need to use a join to do this: query(Invoice).

RE: [sqlalchemy] Couple of questions about filtering...

2013-01-22 Thread Alexey Vihorev
>> Apparently, Person.full_name receives a class as an argument instead >> of an instance. Is there other way? > >That's what you want in this case, that this hybrid property would get a >class, because Query works with classes. Try adding echo=True to create_engine() to see the actual SQL emitt

[sqlalchemy] Couple of questions about filtering...

2013-01-21 Thread Alexey Vihorev
Hi. Couple of questions... 1. Does SQLA support "deep filtering", i.e. something like this: query(Invoice).filter(Invoice.Customer.Country.name=='France') This does not work as it is, but is there something along this lines (except of going with query.filter(.query.filter(.query.filter(

[sqlalchemy] Initiate re-numeration of related records using sqlalchemy.ext.orderinglist

2013-01-08 Thread Alexey Vihorev
Hi all! Apparently, a relation declared using sqlalchemy.ext.orderinglist does not track sorting: 1. class Parent(Base): . 2. name = Column(Text) 3. children = relationship('Child', backref='parent', 4. collection_class=ordering_list('position', 1), 5.

Re: [sqlalchemy] Strange behaviour while trying to swap related records, or am I doing it wrong?

2013-01-08 Thread Alexey Vihorev
e having this > as perhaps an option on relationship(), track_dupes=True, we'd have to > recommend it in conjunction with ordering_list. > > Some ways to work around include, assigning a slice, so that both items > are removed first: > > p.children[1:2] = [c2, c1] > >

RE: [sqlalchemy] Strange behaviour while trying to swap related records, or am I doing it wrong?

2013-01-07 Thread Alexey Vihorev
To: sqlalchemy@googlegroups.com Subject: Re: [sqlalchemy] Strange behaviour while trying to swap related records, or am I doing it wrong? On Jan 7, 2013, at 7:05 PM, Alexey Vihorev wrote: p.children[1], p.children[2] = p.children[2], p.children[1] print(p.children) #prints [Mary, Kenny

[sqlalchemy] Strange behaviour while trying to swap related records, or am I doing it wrong?

2013-01-07 Thread Alexey Vihorev
Hi all! I'm trying to use sqlalchemy.ext.orderinglist as per instructions here , and but I've encountered a loss of data while trying to swap positions of related records inside a related property list. I thought it was relat

RE: [sqlalchemy] Keeping open connections alive

2012-12-23 Thread Alexey Vihorev
ckout" events, and only do the "ping" if a connection is not in "checkout" state. On Dec 23, 2012, at 11:03 AM, Alexey Vihorev wrote: Hi, all! I've got a problem in my GUI app - if a connection stayes open for too long, and is inactive (

[sqlalchemy] Keeping open connections alive

2012-12-23 Thread Alexey Vihorev
Hi, all! I've got a problem in my GUI app - if a connection stayes open for too long, and is inactive (user opened an editing window and went away for a cofee brake etc), firewall/other network machinery will close the connection and the session will fail with 'connection abnormally terminated'. S

[sqlalchemy] Oracle dblink reflection

2012-11-27 Thread Alexey Ismailov
Hi, i have a very bad issue on SA using Oracle database link. I have 2 Oracle (11g) database instances, one used for my app, in other stored some data, which i need to use. I've created a dblink: CREATE DATABASE LINK CONNECT TO IDENTIFIED BY USING 'localhost:1521/ORCL' And synonym for table

RE: [sqlalchemy] Inheriting a functionality in SQLA

2012-11-21 Thread Alexey Vihorev
Thanks for the clarification, it works now. From: sqlalchemy@googlegroups.com [mailto:sqlalchemy@googlegroups.com] On Behalf Of Michael Bayer Sent: 21 ноября 2012 г. 3:58 To: sqlalchemy@googlegroups.com Subject: Re: [sqlalchemy] Inheriting a functionality in SQLA On Nov 20, 2012, at 4:31

RE: [sqlalchemy] Inheriting a functionality in SQLA

2012-11-21 Thread Alexey Vihorev
Yes, I tried mix-in approach, and it works, thanks. From: sqlalchemy@googlegroups.com [mailto:sqlalchemy@googlegroups.com] On Behalf Of Robert Forkel Sent: 20 ноября 2012 г. 17:09 To: sqlalchemy@googlegroups.com Subject: Re: [sqlalchemy] Inheriting a functionality in SQLA As far as i know e

[sqlalchemy] Flushing all sessions

2009-10-07 Thread Alexey
Hello. I'm using SQL Alchemy as a persistence engine for my multi-threaded desktop application with sqlite backend. ScopedSession acts very well, but there is a problem: 1) I have 2 tables: categories_table = Table('category', metadata, Column('id', Integer, primary_key=True), Column(

[sqlalchemy] Re: How to mix declarative_base with orm.mapper?

2009-03-31 Thread Alexey Maslov
Thanks, it works when I added the MetaData instance to the declarative_meta() call. Have a great day! Regards, Alexey Maslov On Tue, Mar 31, 2009 at 6:02 PM, Michael Bayer wrote: > user_profiles_tbl and your declarative_meta need to share same MetaData > instance. > > On Mar 31, 2

[sqlalchemy] Re: How to mix declarative_base with orm.mapper?

2009-03-31 Thread Alexey Maslov
relation(City), 'skills' : relation(Skill, secondary=user_profile_skills_tbl, order_by=Skill.name), }) The Country class is: Base = declarative_base() class Country(Base): __tablename__ = 'countries' id = Column(Integer, primary_key=True) name = C