I've seen it and thought that some ways available...
пт, 13 окт. 2017 г. в 17:30, Mike Bayer <mike...@zzzcomputing.com>:

> On Fri, Oct 13, 2017 at 8:43 AM, Антонио Антуан <a.ch....@gmail.com>
> wrote:
> > I use such code to generate raw SQL from SQLA-queries:
> >
> > def compile_statement(statement):
> >     comp = statement.compile(dialect=postgresql.dialect())
> >     params = {}
> >     for k, v in comp.params.items():
> >         if isinstance(v, unicode):
> >             v = v.encode(cls.encoding)
> >         params[k] = adapt(v)
> >     return (comp.string.encode(cls.encoding) %
> params).decode(cls.encoding)
> >
> >
> > def compile_query(query):
> >     return cls.compile_statement(query.statement)
> >
> >>>> print(compile_query(Foo.query.filter(Foo.bar ==
> >>>> 'zoo').with_entities(Foo.bar))
> > SELECT foos.bar as foos_bar
> > FROM foos
> > WHERE foos.bar = 'zoo'
> >
> >
> > Is there any way to generate raw SQL insert statement, generated by this
> > code?
> > Foo(bar='zoo').save()
>
> if you mean that save() is the flask-sqlalchemy thing that calls
> flush(), and you want to get the INSERT that the ORM uses directly,
> there's not really a way to get that on the fly.   The insert is
> generated internally based on a scan of what's in the object and it
> occurs across several private functions which pass lots of internal
> state around.
>
>
>
> >
> > --
> > 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 -
> 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 - 
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.

Reply via email to