| 1 |
package db |
| 2 |
|
| 3 |
import ( |
| 4 |
"database/sql" |
| 5 |
"sync/atomic" |
| 6 |
) |
| 7 |
|
| 8 |
// Beginner is an interface for types that can begin a database transaction. |
| 9 |
// Both *sql.DB and *DB implement this. |
| 10 |
type Beginner interface { |
| 11 |
Begin() (*sql.Tx, error) |
| 12 |
} |
| 13 |
|
| 14 |
// Querier is an interface for types that can execute SQL queries. |
| 15 |
// *sql.DB, *sql.Tx, and *DB all implement this. |
| 16 |
type Querier interface { |
| 17 |
Query(query string, args ...any) (*sql.Rows, error) |
| 18 |
} |
| 19 |
|
| 20 |
// Host pairs a *sql.DB with the host:port it was opened against. |
| 21 |
type Host struct { |
| 22 |
Addr string // "host:port" |
| 23 |
DB *sql.DB |
| 24 |
healthy atomic.Bool |
| 25 |
} |