Documentation
¶
Index ¶
- Variables
- func Close(ctx context.Context, p *Pool) error
- func GetID(ctx context.Context) string
- type Conn
- type Pool
- func (p *Pool) BeginTx(ctx context.Context, opts *sql.TxOptions) (*TTx, error)
- func (p *Pool) Conn(ctx context.Context) (*sql.Conn, error)
- func (p *Pool) Exec(query string, args ...interface{}) (sql.Result, error)
- func (p *Pool) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
- func (p *Pool) Query(query string, args ...interface{}) (*sql.Rows, error)
- func (p *Pool) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
- func (p *Pool) QueryRow(query string, args ...interface{}) *sql.Row
- func (p *Pool) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row
- type PoolOption
- type PoolOptions
- type TContextExecutor
- type TExecutor
- type TTransactor
- type TTx
Constants ¶
This section is empty.
Variables ¶
var ErrNoTenantSet = errors.New("tenant id not set in context")
Functions ¶
Types ¶
type Conn ¶
Conn implements the TContextExecutor interface
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool manages a connection pool until closed
func FromContext ¶
FromContext finds the tenanted database connection pool from the context. REQUIRES tenancy.Open() to have run.
func Open ¶
func Open(ctx context.Context, db *sql.DB, tenantID string, opts ...PoolOption) (*Pool, context.Context, error)
Open sets the tenant and returns a database connection scoped to the tenant it returns a new context which contains the tenant ID and the connection
func (*Pool) Conn ¶
Conn will create a new connection and apply the current tenant The opened connection is registered to a pool internally which is closed when tenancy.Close(ctx, Tconn) is called
func (*Pool) ExecContext ¶
func (p *Pool) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
Exec is implemented with background context to satisfy interface
func (*Pool) QueryContext ¶
func (p *Pool) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
Query is implemented with background context to satisfy interface
type PoolOption ¶
type PoolOption func(*PoolOptions)
func WithSingleConnection ¶
func WithSingleConnection() PoolOption
configures tenancy to use a single connection rather than a pool
type PoolOptions ¶
type PoolOptions struct {
// contains filtered or unexported fields
}
type TContextExecutor ¶
type TContextExecutor interface { TExecutor ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row }
TContextExecutor can perform SQL queries with context and is tenant-scoped.
type TExecutor ¶
type TExecutor interface { Exec(query string, args ...interface{}) (sql.Result, error) Query(query string, args ...interface{}) (*sql.Rows, error) QueryRow(query string, args ...interface{}) *sql.Row // contains filtered or unexported methods }
Executor can perform SQL queries and is tenant-scoped.
type TTransactor ¶
Transactor can commit and rollback, on top of being able to execute queries and is tenant-scoped.