Re: [sqlalchemy] adjacency list to nested dictionary

2015-12-16 Thread Horcle
Thanks for the advice and for confirming my suspicions. I did find a solution here using CTEs, but yes, I know MySQL definitely does not support them. I'll definitely take a look at Marshmallow. Greg-- On Wednesday, December 16, 2015 at 6:48:10 PM UTC-6, Jeff Widman wrote: > > You've got to se

Re: [sqlalchemy] adjacency list to nested dictionary

2015-12-16 Thread Jeff Widman
You've got to separate issues here--one of retrieving the data, and the second of serializing it to JSON. They're related, but perhaps easier to solve if you mentally think of them as distinct problems. Since you're storing the data as an adjacency list, then you'll need to either use a recursive

Re: [sqlalchemy] adjacency list to nested dictionary

2015-12-16 Thread Horcle
We're using MySQL and need retrieval of all data from the table in the format given (nested JSON). Simplest solution would be good (whether in app or SQLAlchemy). I tried using the JsonSerializer as noted here http://stackoverflow.com/questions/30367450/how-to-create-a-json-object-from-tree-data

Re: [sqlalchemy] adjacency list to nested dictionary

2015-12-16 Thread Jeff Widman
What database are you using? Are you trying to solve data insert or retrieval? Do you want to do your traversal in your app or use SQLAlchemy to generate a SQL query that does all the work within the DB and then returns the result? ᐧ On Wed, Dec 16, 2015 at 1:28 PM, Horcle wrote: > I have th

Re: [sqlalchemy] Isolating event listeners on Engine

2015-12-16 Thread Kai Groner
On Wed, Dec 16, 2015 at 4:32 PM, Mike Bayer wrote: > > This works ok, and it's leaking less memory than it was before. > > OK well it's not like we're trying to seal with duct tape, any leak > means, "it's broke" :) Well, I expect we're responsible for causing some, if not most, of these memory

Re: [sqlalchemy] Isolating event listeners on Engine

2015-12-16 Thread Mike Bayer
On 12/16/2015 04:07 PM, Kai Groner wrote: > Hi, > > I work on a project that uses dependency injection. We want to log > queries in the context of a particular instantiation of the injector. > This means that when we register an event listener, that listener has > references to a unique logger

[sqlalchemy] adjacency list to nested dictionary

2015-12-16 Thread Horcle
I have the following SQLAlchemy class representing an adjacency list: class Node(db.Model): __tablename__ = 'meds' id = Column(Integer, primary_key=True) type = Column(String(64)) name = Column(String(64)) parent_id = Column(Integer, ForeignKey('node.id')) children = relati

[sqlalchemy] Isolating event listeners on Engine

2015-12-16 Thread Kai Groner
Hi, I work on a project that uses dependency injection. We want to log queries in the context of a particular instantiation of the injector. This means that when we register an event listener, that listener has references to a unique logger configuration and we don't want that listener to leak i

[sqlalchemy] Re: Reflection of table/columns comments

2015-12-16 Thread Lele Gaifax
Mike Bayer writes: > The column_reflect event supports this - you can populate the info > dictionary right there from information that you get out of the > col_description system view. Thank you Mike, as always, you (and consequently SQLAlchemy) shine! ciao, lele. -- nickname: Lele Gaifax | Q

[sqlalchemy] Re: Difference between insert().values() and connection.execute(insert, values) using psycopg2

2015-12-16 Thread Jonathan Vanasco
On Wednesday, December 16, 2015 at 8:33:18 AM UTC-5, viktor@gmail.com wrote: > > As an application developer you would expect that these code snippets > would have the same performance characteristics and we were very surprised > at first at the results. > No, you shouldn't - especially

Re: [sqlalchemy] Difference between insert().values() and connection.execute(insert, values) using psycopg2

2015-12-16 Thread Mike Bayer
On 12/16/2015 08:33 AM, viktor.fors...@gmail.com wrote: > Hi, > > Today we increased the performance of one of our services eightfold by > changing the row: > > connection.execute(insert_statement, values=[...]) > > into > > insert_statement = table.insert().values(values) > connection.execu

Re: [sqlalchemy] Association Proxy

2015-12-16 Thread Mike Bayer
On 12/16/2015 05:40 AM, Jitesh Nair wrote: > I am trying to convert my association table to a class view and using > associationproxy to link them. When i try to append them, it fails. > *My code:* > | > > classHospitalList(db.Model): > id=db.Column(db.Integer,primary_key=True) > doctor_

[sqlalchemy] Difference between insert().values() and connection.execute(insert, values) using psycopg2

2015-12-16 Thread viktor . forsman
Hi, Today we increased the performance of one of our services eightfold by changing the row: connection.execute(insert_statement, values=[...]) into insert_statement = table.insert().values(values) connection.execute(insert_statement) We are using the db driver psycopg2. The reason for this