Connection pool: How to close single connection from pool
Peewee uses a connection-per-thread, so you get:

* connect() -> get conn from pool, or if none free create new one
* use connection for a while
* close() -> return connection back to pool

Calling `db.close()` will close the connection you've been using in the current thread. You use the exact same API when you're using the connection pool as you would when using a non-pooled peewee database implementation.

I'm not very familiar with fastapi/uvicorn, but for web applications you will use the same pattern I described above:

* request comes in, thread starts handling request
* open db connection (db.connect())
* do work
* return response
* close db connection (db.close())

Most web frameworks have some hooks for before/after request. There is a section on the peewee docs about how to do this with FastAPI:

http://docs.peewee-orm.com/en/latest/peewee/database.html#fastapi Thank you so much @coleifer  @coleifer 
One more query, even if we are passing database instance in peewee basemodel class, do we still need to call db.connect() before the request? You should always call `connect()` at the beginning of the connection lifecycle and `close()` at the end. Why? Read here:

http://docs.peewee-orm.com/en/latest/peewee/database.html#using-autoconnect

Please read the documentation. > You should always call `connect()` at the beginning of the connection lifecycle and `close()` at the end. Why? Read here:
> 
> http://docs.peewee-orm.com/en/latest/peewee/database.html#using-autoconnect
> 
> Please read the documentation.

Sure. Thanks again. 
Hello @coleifer 

First of all, thank you for developing this simple yet wonderful ORM app peewee. It made the database related coding so well. 

We are using postgres connection pool with peewee.
```
db = PooledPostgresqlExtDatabase(
            database=db_secret['name'],
            user=db_secret['uname'],
            password=db_secret['pwd'],
            host=db_secret['host'],
            port=db_secret['port'],
            max_connections=30, autocommit=True, autorollback=True)
```
Every time we are done with saving data to database, in finally of that method, we call 

```
db.close()
```
I have multiple questions/queries - 
1. Will this close the entire pool or just a single connection?
2. In the [documentation](http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#pool) it is mentioned that, 

> For web applications, this typically means that at the beginning of a request, you will open a connection, and when you return a response, you will close the connection.

We are using FastAPI and uvicorn for making it multi-threaded. Considering the above like, do we need to explicitly close the connection?