[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 =

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

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

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