Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make a convenient way for GinoConnection to generate and execute DDLs #749

Open
SantjagoCorkez opened this issue Dec 26, 2020 · 1 comment

Comments

@SantjagoCorkez
Copy link

Is your feature request related to a problem? Please describe.
The only way to create tables described is with db.gino.create_all(...) or it's alias db.gino.create(...). But in case one needs to execute an auto-generated DDL while being in a transaction there's no simple way to do that.

That took me a load of time of debugging to gain a working way:

async def go_another_context(tr: GinoTransaction):
  await tr.connection._run_visitor(AsyncSchemaGenerator, db, checkfirst=True, tables=[table1, table2, ...])

async with db.acquire() as conn, conn.transaction() as tr:
  await go_another_context(tr)

Here we call a "protected" method of GinoConnection class which violates coding guides since underscore methods are not intended to be called by class guests.

Describe the solution you'd like
For example, the AsyncSchemaGenerator (or it's subclass which is my case) could be bound to every GinoConnection yielded from a pool and then there be just a simple GinoConnection.create(self, tables, **kwargs) method that allows a user to execute DDL generated. The AsyncSchemaGenerator could of course be passed through from the very db down to GinoConnection constructor through whatever middlewares exist: Pools and so on.

@fantix
Copy link
Member

fantix commented Mar 21, 2021

Right, the "protected" shouldn't be used, as they will be gone in GINO 1.4 which will adopt SQLAlchemy 1.4 with its asynchronous support, we won't need the AsyncSchemaGenerator hack any more at that time. Please check the v2.0.x branch (and upcoming v1.4.x branch) for updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants