Preferred way to do `database.execute_sql` ?
Peewee has been on 3.0 for about 3 years now, so you might want to upgrade as there are many improvements.

That said, as long as you're opening the pool connection before the request starts, and closing it (returning it back to the pool) after the request, then your code should work just fine.
We're using a DB connection pool with peewee 2.8.0.
We needed to optimize a query by writing handwritten SQL to our PostgreSQL db.

What is the preferred way of doing such a query?
We're using peewee together with a Flask app, if that helps.

Right now, the code is:

```python
database = PooledPostgresqlExtDatabase(...)
# Lots of code...
def func():
    cursor = database.execute_sql('SELECT ...')  # More code obviously.
    result = cursor.fetchall()
    # ...
```

Note that we're not closing the db cursor manually.