T
T
toddbarry2018-07-31 14:33:32
Python
toddbarry, 2018-07-31 14:33:32

Can you help me figure out things that are not fully understood from the Gino documentation?

Maybe there are Gino connoisseurs here? Gino hasn't received an email from the developers yet
- it's an orm using the asyncpg driver based on sqlalchemy. And the developers adhered to the idea of ​​​​not changing the principles of sqlalchemy I will
copy my question:
1) What are the differences between

import sqlalchemy
async def main():
        engine = await sqlalchemy.create_engine('postgresql://... , strategy='gino')

and
import gino
async def main():
        engine = await gino.create_engine('postgresql://...)

Which method is still preferable? Or are they completely identical?
Can I somehow explicitly indicate in the second method that I want to use psycopg2? For performance comparison
2) Why might await engine.pop_bind().close() be needed in the implementation of the logic? Are there any "hygiene rules" that GinoEngine needs to be stopped every time the backend server is stopped manually?
3) In what scenarios is it worth explicitly specifying a GinoConnection instance? That is, use async with engine.acquire() as conn: ?
For example simple
async with db.with_bind('postgresql://localhost/mydb') as engine:
        await db.gino.create_all()
        await User.create(name='jack', fullname='Jack Jones')

It also works quite well, and, as far as I understand, these GinoConnections are created one way or another under the hood, it’s just that there is no fine control over them in the code above.
Why, for example, it may be necessary to create such stacks from connections?
async with engine.acquire() as conn1
        async with engine.acquire() as conn2
                async with engine.acquire() as conn3 ...

And how will this stack fundamentally differ from such an implementation?
async with engine.acquire() as conn1:
        await inner(conn1)
async def inner()
        async with engine.acquire() as conn2

4) I would like to clarify - the following code implements a stack of 3 GinoConnections, where the top one will be a raw connection, the second one will be a reusable connection, and the 3rd one will be a reusing connection ?
async with engine.acquire() as conn
        await User.create(name='jack')
        await User.create(name='jane')
        await User.create(name='james')

5) Under what scenarios might you need to use lazy=True? or reusable=False? in the acquire() parameters?
I'm still satisfied with the principle of working with default parameters - timeout=None, reuse=False, lazy=False, reusable = true. But I want to understand in what cases it would be worth using lazy=True? or reusable=False? and why?
Yes, and also - do I understand correctly that in
async with engine.acquire() as conn1
        async with engine.acquire() as conn2
                async with engine.acquire() as conn3 ...

conn1, conn2, conn3 form a stack where conn1 is raw connection, conn2 is reusable connection and conn3 is reusing connection? or is it the other way around? Or is there no connection stack at all?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question