EHN: partially upgrade sql module for SQLAlchemy 2.0 compat
xref #40686

Hello @fangchenli! Thanks for updating this PR. We checked the lines you've touched for [PEP 8](https://www.python.org/dev/peps/pep-0008) issues, and found:





There are currently no PEP 8 issues detected in this Pull Request. Cheers! :beers: 

##### Comment last updated at 2021-08-20 04:05:22 UTC very nice @fangchenli 