Oh that's really interesting. Thank you for that. I'll definitely tuck that away in my back pocket. My background is really heavy in raw SQL, and meta-programming raw SQL is *awful.* Debugging sql that writes sql and execs it is not fun. I'm not allowed to use sqlalchemy at work because no one else on the team uses python, and we can't go around implementing stuff in a way that only one person knows how to work on. But I really want to get away from the SQL-only approach in my personal/side projects. For some reason I often find myself really blocked when it comes to sqlalchemy. Every time I approach my databases I just flip to sql mode and totally forget that everything in sqla is just plain python, and I can treat it that way. I see the obvious-level mapping between the two and just kind of hit a block beyond that. I should probably sit down and read the source code to try and get past the block, that way I'm not so surprised by answer that Mike and people like you give me. Anyway, probably TMI. Cheers and thanks!
On Thu, Jun 27, 2019 at 11:09 AM Jonathan Vanasco <jonat...@findmeon.com> wrote: > > > On Wednesday, June 26, 2019 at 2:43:44 PM UTC-4, Andrew Martin wrote: >> >> That's very interesting, Jonathan. Could you show me a quick example of >> that approach? I'm not sure I *need* to do that, but I think I would learn >> about SQLAlchemy from such an example and trying to understand it. >> > > One large project has an 'internal api' that tries to centralize the > sqlalchemy interface. > > Let's say we're searching for a "user". I would create a dict for the > data like this: > > query_metadata = {'requester': 'site-admin', # admin interface, user > interface, user api, etc > 'filters': {'Username=': 'foo', # just an > internal notation > }, > 'query_data': {}, # information related to what is > in the query as it is built > } > > > This payload is basically the same stuff you'd pass to as queryargs to one > of your functions above. We essentially pass it to our version of your > CRUD service which then acts on it to generate the query. > > We don't implement this approach on every query - just on a handful of > queries that have intense logic with dozens of if/else statements and that > connect to multiple "filters". Stashing this in an easily accessible > manner has just been much easier than constantly trying to examine the > query to act on it. > > -- > 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 a topic in the > Google Groups "sqlalchemy" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/sqlalchemy/chGVkNwmKyQ/unsubscribe. > To unsubscribe from this group and all its topics, 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. > To view this discussion on the web visit > https://groups.google.com/d/msgid/sqlalchemy/39a4a326-c384-4c91-909a-40d9c3acb323%40googlegroups.com > <https://groups.google.com/d/msgid/sqlalchemy/39a4a326-c384-4c91-909a-40d9c3acb323%40googlegroups.com?utm_medium=email&utm_source=footer> > . > 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. To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/CAOVGraLheEcKaoKuwZRUBRQEgGaQ5dG7UuvV2YuW5czhzFLvqg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.