Jaymon / prom

A PostgreSQL or SQLite orm for Python
MIT License
22 stars 4 forks source link

add Query.one_field_name and get_field_name #112

Closed Jaymon closed 3 years ago

Jaymon commented 4 years ago

So we currently have get_pk() that acts as an alias for Query.is_pk(pk).one() but we should generic that, so you can do it for any field, the get_* version would return an iterator, and the one_* version would return the first match

Jaymon commented 3 years ago

Another approach would be to have get_<FIELDNAME> check the <FIELDNAME> against all the aliases and if it gets it then it would run one() against that field name.

If it didn't find it would check if the last character was an s, if it is it would strip it and do the check again, but use in_<FIELDNAME> to build the query instead.

If the endswith("s") check failed then it would try endswith("es") and do the same as above.

Jaymon commented 3 years ago

value_* and values_* can also be added to this list