Can you send us an example how your myModel is?
j
Mehdi wrote:
How could i guess the proper aliased column name then?
In your example your table is "specie" and column name is "codice", so
you used "specie_codice=42". but as i said i have joins and longer
column names, so sometimes i get like "table1.somelongcolumn AS
table1_somelong_7".
On Monday, January 12, 2015 at 3:09:22 PM UTC+3:30, jo wrote:
Why don't you pass the params to session.query as a dictionary
into filter_by as in:
In [1]: by_where_clause=dict(specie_codice='42',
specie_descrizione='Nutrie')
In [2]: print session.query(Specie).filter_by( **by_where_clause
).count()
2015-01-12 12:37:40,518 INFO sqlalchemy.engine.base.Engine SELECT
count(*) AS count_1
FROM (SELECT specie.codice AS specie_codice, specie.descrizione AS
specie_descrizione, specie.cod_gruppo_specie AS
specie_cod_gruppo_specie, specie.categoria_prodotto AS
specie_categoria_prodotto, specie.interparto AS specie_interparto,
specie.gestazione AS specie_gestazione, specie.codice_bdn AS
specie_codice_bdn
FROM specie
WHERE specie.codice = %(codice_1)s AND specie.descrizione =
%(descrizione_1)s) AS anon_1
2015-01-12 12:37:40,518 INFO sqlalchemy.engine.base.Engine
{'codice_1': '42', 'descrizione_1': 'Nutrie'}
1
In [3]:
j
On 01/12/2015 11:45 AM, Mehdi wrote:
Hi
I want to make a query with given filters received from client
side. client side sends a json array like this:
| |
[
"0DA": {conditionType: null, column: "serialNumber",
operator: "GREATER_THAN", value: 50},
"1DG": {conditionType: "AND", column: "name", operator:
"EQUAL", value: "john" }
]
I've managed to convert the json array into string query with a
template like this:
| |
" {condition_type} {column} {operator} {value} "
But this is only the "WHERE" clause. for complete query i
use session.query(myModel) which myModel has two relationships
with lazy="joined" mix with text() for filters:
| |
session.query(myModel).filter(text(sql_string))
But the problem is the session.query() uses alias column
names(with "AS" keyword) which my filter part with exact column
names couln'd find those aliased columns.
So Is there a way to tell session.query() use the exact column
names? or i should change my way?
Thanks.
--
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 [email protected] <javascript:>.
To post to this group, send email to [email protected]
<javascript:>.
Visit this group at http://groups.google.com/group/sqlalchemy
<http://groups.google.com/group/sqlalchemy>.
For more options, visit https://groups.google.com/d/optout
<https://groups.google.com/d/optout>.
--
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 [email protected]
<mailto:[email protected]>.
To post to this group, send email to [email protected]
<mailto:[email protected]>.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
--
Jose Soares Da Silva _/_/
Sferacarta Net
Via Bazzanese 69 _/_/ _/_/_/
40033 Casalecchio di Reno _/_/ _/_/ _/_/
Bologna - Italy _/_/ _/_/ _/_/
Ph +39051591054 _/_/ _/_/ _/_/ _/_/
fax +390516131537 _/_/ _/_/ _/_/ _/_/
web:www.sferacarta.com _/_/_/ _/_/_/
Le informazioni contenute nella presente mail ed in ogni eventuale file
allegato sono riservate e, comunque, destinate esclusivamente alla persona o
ente sopraindicati, ai sensi del decreto legislativo 30 giugno 2003, n. 196. La
diffusione, distribuzione e/o copiatura della mail trasmessa, da parte di
qualsiasi soggetto diverso dal destinatario, sono vietate. La correttezza,
l’integrità e la sicurezza della presente mail non possono essere garantite. Se
avete ricevuto questa mail per errore, Vi preghiamo di contattarci
immediatamente e di eliminarla. Grazie.
This communication is intended only for use by the addressee, pursuant to
legislative decree 30 June 2003, n. 196. It may contain confidential or
privileged information. You should not copy or use it to disclose its contents
to any other person. Transmission cannot be guaranteed to be error-free,
complete and secure. If you are not the intended recipient and receive this
communication unintentionally, please inform us immediately and then delete
this message from your system. Thank you.
--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.