Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Tenancy ¶
func Tenancy(db *sql.DB, log Logger, getTenantIDFromCtx func(context.Context) string) func(next http.Handler) http.Handler
Tenancy is a middleware that injects a tenanted *sql.Conn into the context of each request. This middleware accepts a function which should extract the current tenant from context. The expectation is that you will have some auth middleware which can inject the current tenant into the ctx in a previous step.
When a query is made using the Pool, a new connection will be opened and tenancy applied to it. These connections are tracked internally and will be closed at the end of the request
If you start a transaction from the Pool, a single connection will be opened and used for all queries for the duration of the transaction ¶
You may also open a single Conn from the pool which will be closed when the pool is closed
Types ¶
Click to show internal directories.
Click to hide internal directories.