[sqlalchemy] how to return an array of dicts

2015-06-01 Thread Richard Gerd Kuesters
hello all! probably this was asked before, as I already grabbed some answers already from here and stackoverflow, but I don't really feel happy about it. problem: i have a query that it's result must go directly as a json (web / rpc usage), and I wonder if I must go from the cycle . class

Re: [sqlalchemy] how to return an array of dicts

2015-06-01 Thread Richard Gerd Kuesters
thanks Simon! yes, i'm already using hooks so I can pass datetime, decimal, enums and so on; of course, it can help if I have to go with the result proxy. i just wonder if there's another way of doing this without having sqlalchemy to provide me helpers of proxy objects. i'm thinking about

Re: [sqlalchemy] how to return an array of dicts

2015-06-01 Thread Simon King
On Mon, Jun 1, 2015 at 1:51 PM, Richard Gerd Kuesters rich...@pollux.com.br wrote: hello all! probably this was asked before, as I already grabbed some answers already from here and stackoverflow, but I don't really feel happy about it. problem: i have a query that it's result must go

Re: [sqlalchemy] Support for pysqlcipher3

2015-06-01 Thread Fayaz Yusuf Khan
Alright, thanks! I would try to submit the PR. But it does look like a transitional package to me. How do we generally handle such upstream changes anyway? On Monday, June 1, 2015 at 9:06:20 AM UTC+5:30, Michael Bayer wrote: On 5/31/15 8:58 PM, Fayaz Yusuf Khan wrote: On Sunday 31 May

[sqlalchemy] Inheritance and hydrid expression

2015-06-01 Thread Alexis Benoist
Hello, I'm trying to do create a class with joined inheritance. Some have their name in their table and have to access it from another table using a join. I did this mixin and what though it creates an expression error because the SQL generated is not the good one. class NameMixin(object):

Re: [sqlalchemy] how to return an array of dicts

2015-06-01 Thread Richard Gerd Kuesters
Thanks Jonathan, I agree with you, 100%. I have methods for that also, when I have to deal with the real objects and queries and stuff. The point, in my question, is that I have some services that are not vital to my application, but are used constantly -- and it just spits out data. I'm

Re: [sqlalchemy] how to return an array of dicts

2015-06-01 Thread Richard Gerd Kuesters
argh! results = map(lambda r: dict(r.items()), session.execute(my_select).fetchall()) much simplier :) but, the question persists: is this the best approach for a raw data dictionary result query? best regards, richard. On 06/01/2015 10:22 AM, Richard Gerd Kuesters wrote: well, i can

Re: [sqlalchemy] How to create table from select statements in sqlalchemy

2015-06-01 Thread Ranjith
I would like create table as select statement http://www.postgresql.org/docs/8.1/static/sql-createtableas.html On 1 June 2015 at 20:48, Mike Bayer mike...@zzzcomputing.com wrote: On 6/1/15 9:39 AM, Ranjith Ramachandra wrote: I am using sqlalchemy's core features do write some abstraction

[sqlalchemy] Re: ...and MVC

2015-06-01 Thread Jonathan Vanasco
On Sunday, May 31, 2015 at 4:48:09 AM UTC-4, Fayaz Yusuf Khan wrote: I do the former in cases which involve very long transactions. (Batch uploads and processing. I'm counting batch and background tasks as part of the controller layer here.) I manage transactions manually in the

Re: [sqlalchemy] how to return an array of dicts

2015-06-01 Thread Jonathan Vanasco
All my models inherit from an additional base class with this method: def columns_as_dict(self): return a dict of the columns; does not handle relationships return dict((col.name, getattr(self, col.name)) for col in sqlalchemy_orm.class_mapper(self.__class__).mapped_table.c)

Re: [sqlalchemy] How to create table from select statements in sqlalchemy

2015-06-01 Thread Mike Bayer
On 6/1/15 9:39 AM, Ranjith Ramachandra wrote: I am using sqlalchemy's core features do write some abstraction layer. The layer itself needs to be able to create tables from select statements. Sample code: metadata = MetaData(bind=engine) table = Table(table_name, metadata,

Re: [sqlalchemy] Inheritance and hydrid expression

2015-06-01 Thread Mike Bayer
On 6/1/15 5:56 AM, Alexis Benoist wrote: Hello, I'm trying to do create a class with joined inheritance. Some have their name in their table and have to access it from another table using a join. I did this mixin and what though it creates an expression error because the SQL generated is

Re: [sqlalchemy] How to create table from select statements in sqlalchemy

2015-06-01 Thread Mike Bayer
On 6/1/15 11:19 AM, Ranjith wrote: I would like create table as select statement http://www.postgresql.org/docs/8.1/static/sql-createtableas.html OK but also you want to use bound parameters, apparently. I've answered the question at http://stackoverflow.com/a/30577608/34549. On 1

[sqlalchemy] How to create table from select statements in sqlalchemy

2015-06-01 Thread Ranjith Ramachandra
I am using sqlalchemy's core features do write some abstraction layer. The layer itself needs to be able to create tables from select statements. Sample code: metadata = MetaData(bind=engine) table = Table(table_name, metadata, autoload=True, autoload_with=engine) s =

Re: [sqlalchemy] how to return an array of dicts

2015-06-01 Thread Richard Gerd Kuesters
well, i can use select and zip ... don't know if this is the best approach: foo = session.execute(my_select) # my_select have the same rules as the session.query(A..., A).filter(...).order_by(...).offset(...).limit() results = map(lambda r: dict(foo.keys(), r), foo.fetchall()) any

[sqlalchemy] Re: How to create table from select statements in sqlalchemy

2015-06-01 Thread Ranjith Ramachandra
I have also asked the question at http://stackoverflow.com/questions/30575111/how-to-create-a-new-table-from-select-statement-in-sqlalchemy On Monday, 1 June 2015 19:09:13 UTC+5:30, Ranjith Ramachandra wrote: I am using sqlalchemy's core features do write some abstraction layer. The layer

Re: [sqlalchemy] SQLAlchemy quoting of table names - Can't redefine 'quote' or 'quote_schema' arguments

2015-06-01 Thread Adam Darwin
Nailed it, removing quote;False and setting the quoting characters to [] did the job. Huge thanks for the help, On Friday, 29 May 2015 09:43:27 UTC+10, Michael Bayer wrote: On 5/28/15 7:13 PM, Adam Darwin wrote: Thanks for the response Michael as far as I can tell there is no