Connection management in the backend #731
Replies: 1 comment 3 replies
-
|
For DDL operations, I think registering them so they work easily with the alembic I think setting up a context object makes sense, or at least using the connection object as a context object. I'm not sure what context would be useful beyond the engine and connection currently in play, and those are both visible in the connection object. I don't think passing lots of operation-specific parameters via some context blob is a good idea, since it obscures what's actually being passed to / used in a function (kind of the same problem as star imports in a way). As far as global registration of DML operations, what would be the goal of that? It seems bound to cause namespacing problems (we're already experiencing that a bit). I might be missing how that would help with connection management, but I can't see it at the moment. Keep in mind that the SQLAlchemy |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm working on:
dbcode to work with existing connections #592I'm thinking through different ideas for managing connections, and here's what I think makes sense:
DDL Operations
Since we're already using
alembic, I think we should register all our DDL operations using their operation plugin API: https://alembic.sqlalchemy.org/en/latest/api/operations.html#operation-plugins. Alembic'sMigrationContextalready manages connections and we can run multiple operations in the same migration context if needed. This means that all our DDL operations will use the same API, which I like.DML Operations
I think we should set up something similar for DML operations where each operation is registered and needs a context to run. This will making setting up connections much more explicit, and we can cache instances of the DML context as needed.
We'd replace most direct uses of
engineandconnectionin our code with these operations.I'm not sure if this is clear enough, please feel free to ask questions.
Beta Was this translation helpful? Give feedback.
All reactions