1// Package lock defines the Locker interface and implements the locking logic.
2package lock
3
4import (
5 "context"
6 "database/sql"
7 "errors"
8)
9
10var (
11 // ErrLockNotImplemented is returned when the database does not support locking.
12 ErrLockNotImplemented = errors.New("lock not implemented")
13 // ErrUnlockNotImplemented is returned when the database does not support unlocking.
14 ErrUnlockNotImplemented = errors.New("unlock not implemented")
15)
16
17// SessionLocker is the interface to lock and unlock the database for the duration of a session. The
18// session is defined as the duration of a single connection and both methods must be called on the
19// same connection.
20type SessionLocker interface {
21 SessionLock(ctx context.Context, conn *sql.Conn) error
22 SessionUnlock(ctx context.Context, conn *sql.Conn) error
23}