[sqlalchemy] Getting Model Name from Query object

2017-03-24 Thread Vijaya Sekar
Hi everyone,

I have a 'sqlalchemy.orm.query.Query' object from that how can i know what 
model it uses 

from sqlalchemy import create_engine
from sqlalchemy.ext.automap import automap_base
from sqlalchemy.orm import Session
from sqlalchemy import MetaData

engine = create_engine("sqlite:///chinook.db",  echo = False)

metadata = MetaData()
model = 'employees'
metadata.reflect(engine, only=[model])
base = automap_base(metadata=metadata)
base.prepare()
map_model = base.classes[model]
session = Session(engine)
query = session.query(map_model.LastName,map_model.FirstName)


Here the model i am using is 'employees'. But how can achieve this by using 
'sqlalchemy.orm.query.Query' object in the program 
(i.e. query = session.query(map_model.LastName,map_model.FirstName)).

-- 
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] Performing filter by using string

2017-03-22 Thread Vijaya Sekar
Hi everyone,

I have an string which has the condition to be performed while retrieving 
from database. I automap my model and make reference to it by using another 
variable name.
How can achieve retrieve data by filter which is in string?

here is my code

from sqlalchemy import create_engine
from sqlalchemy.ext.automap import automap_base
from sqlalchemy.orm import Session
from sqlalchemy import MetaData


engine = create_engine("sqlite:///chinook.db",  echo = False)

metadata = MetaData()
model = 'employees'
condition = 'employees.City == "Chennai"'
metadata.reflect(engine, only=[model])
base = automap_base(metadata=metadata)
base.prepare()
map_model = base.classes[model]
session = Session(engine)
retrieve = session.query(map_model).filter(condition)
for i in retrieve:
print(i.EmployeeId)



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


Re: [sqlalchemy] automap_base with mapped class

2017-03-11 Thread Vijaya Sekar
Yeah I done it thank u mike

-- 
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] automap_base with mapped class

2017-03-10 Thread Vijaya Sekar


from sqlalchemy.ext.automap import automap_base
from sqlalchemy import create_engine, MetaData
lists = ['employees','address']
engine = create_engine("sqlite:///chinook.db")
metadata = MetaData()
metadata.reflect(engine, only=lists)
Base = automap_base(metadata=metadata)
Base.prepare()
User = Base.classes.employees



In the above How can i achieve mapping the classes without mention the class 
explicitly.

i.e User = Base.classes.employees

How can achieve same result by using the lists[0]

-- 
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] Perfoming join on multiple tables dynamically

2017-03-05 Thread Vijaya Sekar
Hello everyone,

I have parent table which holds the primary keys of several child 
tables.The child table are got as a list . Using SQLalchemy ORM, how can I 
join multiple child tables to this parent?

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