Re: [sqlalchemy] generate top-level python code for an alembic revision from render_item

2020-05-05 Thread Mike Bayer
it's pretty doable if you add a new ${thing} to your mako template. getting a 
value in there requires a trick, there's an example of it here: 
https://github.com/sqlalchemy/alembic/issues/686#issuecomment-616828129

which is to put a dictionary inside of another dictionary and pass that as 
"template_args" when you context.configure(); suppose you send it as 
template_args={"my_dictionary": {}}. then anywhere you are, in a render hook, 
in env.py, whatever, put whatever you want in that dictionary. then reference 
in your template as ${my_dictionary['some_value']} .



On Tue, May 5, 2020, at 5:24 PM, Adrian wrote:
> I have a custom type implementing enums (no idea if there's something better 
> now, but it's used in many places so
> replacing it is not an option atm). Currently I'm using render_item to simply 
> import the type and the enum and pass the
> enum to the type and it works fine.
> 
> However, in the alembic revision I'd prefer to define a copy of the enum how 
> it looked like at generation time since it may
> change and in that case running an older revision's upgrade would be broken 
> as it would generate the column based on
> a different enum.
> 
> In any case, I would like to have the enum definition inside my revision 
> file, either top-level or inside `upgrade`. But for neither
> of these options I found any way to do it properly as there doesn't seem to 
> be any way to provide code to be included in
> `upgrade` or variables for the mako template context used to render the 
> revision file.
> 
> I managed to do it using this **incredibly ugly** workaround, but I really 
> hope there's some better way... so if there is one, please
> let me know. Because not adding this abomination in my codebase would be 
> great:
> https://gist.github.com/ThiefMaster/3ad2a35b531ff5cada7d2232333619fa
> 
> Thanks for any help/suggestions!
> 

> --
>  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 view this discussion on the web visit 
> https://groups.google.com/d/msgid/sqlalchemy/fe2d88a4-f40d-411e-941f-44ceff7fdc9d%40googlegroups.com
>  
> .

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/65c1264f-158b-41c9-92b1-95ef4d29ee61%40www.fastmail.com.


[sqlalchemy] generate top-level python code for an alembic revision from render_item

2020-05-05 Thread Adrian
I have a custom type implementing enums (no idea if there's something 
better now, but it's used in many places so
replacing it is not an option atm). Currently I'm using render_item to 
simply import the type and the enum and pass the
enum to the type and it works fine.

However, in the alembic revision I'd prefer to define a copy of the enum 
how it looked like at generation time since it may
change and in that case running an older revision's upgrade would be broken 
as it would generate the column based on
a different enum.

In any case, I would like to have the enum definition inside my revision 
file, either top-level or inside `upgrade`. But for neither
of these options I found any way to do it properly as there doesn't seem to 
be any way to provide code to be included in
`upgrade` or variables for the mako template context used to render the 
revision file.

I managed to do it using this **incredibly ugly** workaround, but I really 
hope there's some better way... so if there is one, please
let me know. Because not adding this abomination in my codebase would be 
great:
https://gist.github.com/ThiefMaster/3ad2a35b531ff5cada7d2232333619fa

Thanks for any help/suggestions!

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/fe2d88a4-f40d-411e-941f-44ceff7fdc9d%40googlegroups.com.


Re: [sqlalchemy] sqlalchemy list connections inside connection pool

2020-05-05 Thread Oğuzhan Kaya
Thanks mate you are a life saver. I think you mean this about event 
listeners. 

-
what is dbapi_conn connection_rec and connection_proxy. I couldnt get it.

def my_on_checkout(dbapi_conn, connection_rec, connection_proxy):
"handle an on checkout event"

event.listen(Pool, 'checkout', my_on_checkout)






5 Mayıs 2020 Salı 19:52:09 UTC+3 tarihinde Mike Bayer yazdı:
>
> if you wanted to see the queue you could do this:
>
> >>> [rec.connection for rec in e.pool._pool.queue]
> [<_mysql.connection open to 'localhost' at 0x55ac3f6dfd20>, 
> <_mysql.connection open to 'localhost' at 0x55ac3f6f52f0>]
>
>
>
> but for more general tracking of connection pool connections you would use 
> the event listeners and track them yourself:  
> https://docs.sqlalchemy.org/en/13/core/events.html#sqlalchemy.events.PoolEvents
>
>
>
> On Tue, May 5, 2020, at 12:49 PM, Mike Bayer wrote:
>
> engine.pool has some metrics on it:
>
> >>> from sqlalchemy import create_engine
> >>> e = create_engine("mysql://scott:tiger@localhost/test")
> >>> e.pool.status()
> 'Pool size: 5  Connections in pool: 0 Current Overflow: -5 Current Checked 
> out connections: 0'
> >>> e.pool.checkedout()
> 0
> >>> c1 = e.connect()
> >>> e.pool.checkedout()
> 1
> >>> e.pool.status()
> 'Pool size: 5  Connections in pool: 0 Current Overflow: -4 Current Checked 
> out connections: 1'
> >>> c2 = e.connect()
> >>> e.pool.status()
> 'Pool size: 5  Connections in pool: 0 Current Overflow: -3 Current Checked 
> out connections: 2'
> >>> c1.close()
> >>> e.pool.status()
> 'Pool size: 5  Connections in pool: 1 Current Overflow: -3 Current Checked 
> out connections: 1'
> >>> c2.close()
> >>> e.pool.status()
> 'Pool size: 5  Connections in pool: 2 Current Overflow: -3 Current Checked 
> out connections: 0'
>
>
>
>
> On Tue, May 5, 2020, at 11:14 AM, Oğuzhan Kaya wrote:
>
> I made a connection with sqlalchemy to mssql and I used queue pool. I am 
> trying to understand this connetion pool is worked or not. and also I want 
> to see the connections and the queue inside connection pool how can I see?
>
> engine = sal.create_engine('IP',pool_size=1,max_overflow=0)
> result = engine.execute('select * from mytable')
> result.close()
>
>
> --
> 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 sqlal...@googlegroups.com .
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sqlalchemy/d565c8a9-0d34-46cb-971a-b08ecc1fc881%40googlegroups.com
>  
> 
> .
>
>
>
> --
> 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 sqlal...@googlegroups.com .
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sqlalchemy/903c57b2-d918-42f7-9d9e-704a0b95fd15%40www.fastmail.com
>  
> 
> .
>
>
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/e71f3db9-1baf-4f8a-a879-6879729c9971%40googlegroups.com.


Re: [sqlalchemy] sqlalchemy list connections inside connection pool

2020-05-05 Thread Oğuzhan Kaya
thanks mate you are the best. but still one last thing missing which is the 
query(data) inside pool.

5 Mayıs 2020 Salı 19:50:22 UTC+3 tarihinde Mike Bayer yazdı:
>
> engine.pool has some metrics on it:
>
> >>> from sqlalchemy import create_engine
> >>> e = create_engine("mysql://scott:tiger@localhost/test")
> >>> e.pool.status()
> 'Pool size: 5  Connections in pool: 0 Current Overflow: -5 Current Checked 
> out connections: 0'
> >>> e.pool.checkedout()
> 0
> >>> c1 = e.connect()
> >>> e.pool.checkedout()
> 1
> >>> e.pool.status()
> 'Pool size: 5  Connections in pool: 0 Current Overflow: -4 Current Checked 
> out connections: 1'
> >>> c2 = e.connect()
> >>> e.pool.status()
> 'Pool size: 5  Connections in pool: 0 Current Overflow: -3 Current Checked 
> out connections: 2'
> >>> c1.close()
> >>> e.pool.status()
> 'Pool size: 5  Connections in pool: 1 Current Overflow: -3 Current Checked 
> out connections: 1'
> >>> c2.close()
> >>> e.pool.status()
> 'Pool size: 5  Connections in pool: 2 Current Overflow: -3 Current Checked 
> out connections: 0'
>
>
>
>
> On Tue, May 5, 2020, at 11:14 AM, Oğuzhan Kaya wrote:
>
> I made a connection with sqlalchemy to mssql and I used queue pool. I am 
> trying to understand this connetion pool is worked or not. and also I want 
> to see the connections and the queue inside connection pool how can I see?
>
> engine = sal.create_engine('IP',pool_size=1,max_overflow=0)
> result = engine.execute('select * from mytable')
> result.close()
>
>
> --
> 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 sqlal...@googlegroups.com .
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sqlalchemy/d565c8a9-0d34-46cb-971a-b08ecc1fc881%40googlegroups.com
>  
> 
> .
>
>
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/391d06a6-0793-4b9c-bd25-d8bb32461384%40googlegroups.com.


Re: [sqlalchemy] sqlalchemy list connections inside connection pool

2020-05-05 Thread Mike Bayer
if you wanted to see the queue you could do this:

>>> [rec.connection for rec in e.pool._pool.queue]
[<_mysql.connection open to 'localhost' at 0x55ac3f6dfd20>, <_mysql.connection 
open to 'localhost' at 0x55ac3f6f52f0>]



but for more general tracking of connection pool connections you would use the 
event listeners and track them yourself: 
https://docs.sqlalchemy.org/en/13/core/events.html#sqlalchemy.events.PoolEvents



On Tue, May 5, 2020, at 12:49 PM, Mike Bayer wrote:
> engine.pool has some metrics on it:
> 
> >>> from sqlalchemy import create_engine
> >>> e = create_engine("mysql://scott:tiger@localhost/test")
> >>> e.pool.status()
> 'Pool size: 5 Connections in pool: 0 Current Overflow: -5 Current Checked out 
> connections: 0'
> >>> e.pool.checkedout()
> 0
> >>> c1 = e.connect()
> >>> e.pool.checkedout()
> 1
> >>> e.pool.status()
> 'Pool size: 5 Connections in pool: 0 Current Overflow: -4 Current Checked out 
> connections: 1'
> >>> c2 = e.connect()
> >>> e.pool.status()
> 'Pool size: 5 Connections in pool: 0 Current Overflow: -3 Current Checked out 
> connections: 2'
> >>> c1.close()
> >>> e.pool.status()
> 'Pool size: 5 Connections in pool: 1 Current Overflow: -3 Current Checked out 
> connections: 1'
> >>> c2.close()
> >>> e.pool.status()
> 'Pool size: 5 Connections in pool: 2 Current Overflow: -3 Current Checked out 
> connections: 0'
> 
> 
> 
> 
> On Tue, May 5, 2020, at 11:14 AM, Oğuzhan Kaya wrote:
>> I made a connection with sqlalchemy to mssql and I used queue pool. I am 
>> trying to understand this connetion pool is worked or not. and also I want 
>> to see the connections and the queue inside connection pool how can I see?
>> 
>> engine = sal.create_engine('IP',pool_size=1,max_overflow=0)
>> result = engine.execute('select * from mytable')
>> result.close()
>> 

>> --
>> 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 view this discussion on the web visit 
>> https://groups.google.com/d/msgid/sqlalchemy/d565c8a9-0d34-46cb-971a-b08ecc1fc881%40googlegroups.com
>>  
>> .
> 
> 

> --
>  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 view this discussion on the web visit 
> https://groups.google.com/d/msgid/sqlalchemy/903c57b2-d918-42f7-9d9e-704a0b95fd15%40www.fastmail.com
>  
> .

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/3864b576-1748-48e1-a054-95f774e1e7de%40www.fastmail.com.


Re: [sqlalchemy] sqlalchemy list connections inside connection pool

2020-05-05 Thread Mike Bayer
engine.pool has some metrics on it:

>>> from sqlalchemy import create_engine
>>> e = create_engine("mysql://scott:tiger@localhost/test")
>>> e.pool.status()
'Pool size: 5 Connections in pool: 0 Current Overflow: -5 Current Checked out 
connections: 0'
>>> e.pool.checkedout()
0
>>> c1 = e.connect()
>>> e.pool.checkedout()
1
>>> e.pool.status()
'Pool size: 5 Connections in pool: 0 Current Overflow: -4 Current Checked out 
connections: 1'
>>> c2 = e.connect()
>>> e.pool.status()
'Pool size: 5 Connections in pool: 0 Current Overflow: -3 Current Checked out 
connections: 2'
>>> c1.close()
>>> e.pool.status()
'Pool size: 5 Connections in pool: 1 Current Overflow: -3 Current Checked out 
connections: 1'
>>> c2.close()
>>> e.pool.status()
'Pool size: 5 Connections in pool: 2 Current Overflow: -3 Current Checked out 
connections: 0'




On Tue, May 5, 2020, at 11:14 AM, Oğuzhan Kaya wrote:
> I made a connection with sqlalchemy to mssql and I used queue pool. I am 
> trying to understand this connetion pool is worked or not. and also I want to 
> see the connections and the queue inside connection pool how can I see?
> 
> engine = sal.create_engine('IP',pool_size=1,max_overflow=0)
> result = engine.execute('select * from mytable')
> result.close()
> 

> --
>  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 view this discussion on the web visit 
> https://groups.google.com/d/msgid/sqlalchemy/d565c8a9-0d34-46cb-971a-b08ecc1fc881%40googlegroups.com
>  
> .

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/903c57b2-d918-42f7-9d9e-704a0b95fd15%40www.fastmail.com.


[sqlalchemy] sqlalchemy list connections inside connection pool

2020-05-05 Thread Oğuzhan Kaya
I made a connection with sqlalchemy to mssql and I used queue pool. I am 
trying to understand this connetion pool is worked or not. and also I want 
to see the connections and the queue inside connection pool how can I see?

engine = sal.create_engine('IP',pool_size=1,max_overflow=0)
result = engine.execute('select * from mytable')
result.close()

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/d565c8a9-0d34-46cb-971a-b08ecc1fc881%40googlegroups.com.