long2ice / asyncmy

A fast asyncio MySQL/MariaDB driver with replication protocol support
https://github.com/long2ice/asyncmy
Apache License 2.0
264 stars 32 forks source link

Use enum (or any type) as argumenets #30

Closed trim21 closed 2 years ago

trim21 commented 2 years ago

I'm trying to build a query like this Table.column == TopicState.TOPIC_STATE_NONE, but I got a ValueError

TypeError: Argument 'value' has incorrect type (expected str, got TopicState)

  File "asyncmy\connection.pyx", line 426, in asyncmy.connection.Connection.literal
  File "asyncmy\connection.pyx", line 419, in asyncmy.connection.Connection.escape
  File "asyncmy\converters.pyx", line 10, in asyncmy.converters.escape_item
  File "asyncmy\converters.pyx", line 25, in asyncmy.converters.escape_item
TypeError: Argument 'value' has incorrect type (expected str, got TopicState)

To avoid this, I need to Table.column == TopicState.TOPIC_STATE_NONE.value to get enum's underlying value.

In aiomysql, I can add a method translate(self, _escape_table) to support any type, is there any way in asyncmy we can do this?

long2ice commented 2 years ago

Could you give link for that?

trim21 commented 2 years ago

do you mean translate?

long2ice commented 2 years ago

Yes

trim21 commented 2 years ago

https://github.com/PyMySQL/PyMySQL/blob/f24cb9aa7295921bcd8f34f752c8a05b981d3125/pymysql/converters.py#L81

trim21 commented 2 years ago

didn't find doc about this, but it's raised in the exception message

long2ice commented 2 years ago

OK

trim21 commented 2 years ago

Maybe it's a undefined behavior? What ever, it would be better if we can use enum value directly.

long2ice commented 2 years ago

Fixed