[sqlalchemy] Re: Reload mapper column definition

2018-03-04 Thread Tolstov Sergey
*Addition:*
This is a *relationship*

-- 
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] Reload mapper column definition

2018-03-04 Thread Tolstov Sergey
On my project, i use __getattr__ for adding column deifinition to object 
class
Such as: 

def __getattr__(self,attr):
...
  my_load_function(...)
  session.refresh(self)
   ...
return getattr(self,attr)

It works, but refresh loses changes on this object. I cannot flush, because 
it used for another function.

I found solution 
session.refresh(self, attribute_names=['attr_name'])

But it will raise exception
sqlalchemy.exc.InvalidRequestError: No column-based properties specified 
for refresh operation. Use session.expire() to reload collections and 
related items.]

I already tried use session.expire(self) and session.expire(self, 
attribute_names=['attr_name'])) before and after refresh, but nothing 
changed

Can someone help me with this eror?

-- 
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: Dynamically change table name to select from for query

2018-03-04 Thread Stanislav Lobanov
Thank you very much, your answer is very detailed as always. I think that 
this approach may fit to me, because this tables are read-only, because it 
is kind of datawarehouse.

Thanks!

суббота, 3 марта 2018 г., 10:45:45 UTC+3 пользователь Stanislav Lobanov 
написал:
>
> Hello!
>
> I have a database with 10 tables with same structure. This structure of a 
> tables are always the same.
>
> I want to be able to query this tables using one declarative mapper 
> instead of 10 similar mappers, but to do so i need a way to change table 
> name somehow.
>
> Desired code:
>
> class T(Base):
>some_column = Column(Integer)  # just an example
>
> table_a_results = 
> session.query(T).select_from_table('table_a').filter(T.some_column > 
> 10).count()
> table_b_results = 
> session.query(T).select_from_table('table_b').filter(T.some_column > 
> 10).count()
>
>
> Are there any possibility to implement such query feature? Are there any 
> alternative variants to this feature?
>
> Thanks!
>

-- 
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.