2025-04-29 06:03:47 +02:00
|
|
|
package database
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
)
|
|
|
|
|
2025-05-08 19:01:55 +02:00
|
|
|
// Pool is a connection pool. e.g. pgxpool
|
2025-04-29 06:03:47 +02:00
|
|
|
type Pool interface {
|
|
|
|
Beginner
|
|
|
|
QueryExecutor
|
|
|
|
|
|
|
|
Acquire(ctx context.Context) (Client, error)
|
|
|
|
Close(ctx context.Context) error
|
|
|
|
}
|
|
|
|
|
2025-05-08 19:01:55 +02:00
|
|
|
// Client is a single database connection which can be released back to the pool.
|
2025-04-29 06:03:47 +02:00
|
|
|
type Client interface {
|
|
|
|
Beginner
|
|
|
|
QueryExecutor
|
|
|
|
|
|
|
|
Release(ctx context.Context) error
|
|
|
|
}
|
|
|
|
|
2025-05-08 19:01:55 +02:00
|
|
|
// Querier is a database client that can execute queries and return rows.
|
2025-04-29 06:03:47 +02:00
|
|
|
type Querier interface {
|
|
|
|
Query(ctx context.Context, stmt string, args ...any) (Rows, error)
|
|
|
|
QueryRow(ctx context.Context, stmt string, args ...any) Row
|
|
|
|
}
|
|
|
|
|
2025-05-08 19:01:55 +02:00
|
|
|
// Executor is a database client that can execute statements.
|
2025-04-29 06:03:47 +02:00
|
|
|
type Executor interface {
|
|
|
|
Exec(ctx context.Context, stmt string, args ...any) error
|
|
|
|
}
|
|
|
|
|
2025-05-08 19:01:55 +02:00
|
|
|
// QueryExecutor is a database client that can execute queries and statements.
|
2025-04-29 06:03:47 +02:00
|
|
|
type QueryExecutor interface {
|
|
|
|
Querier
|
|
|
|
Executor
|
|
|
|
}
|
|
|
|
|
2025-05-08 19:01:55 +02:00
|
|
|
// Scanner scans a single row of data into the destination.
|
2025-04-29 06:03:47 +02:00
|
|
|
type Scanner interface {
|
|
|
|
Scan(dest ...any) error
|
|
|
|
}
|
|
|
|
|
2025-05-08 19:01:55 +02:00
|
|
|
// Row is an abstraction of sql.Row.
|
2025-04-29 06:03:47 +02:00
|
|
|
type Row interface {
|
|
|
|
Scanner
|
|
|
|
}
|
|
|
|
|
2025-05-08 19:01:55 +02:00
|
|
|
// Rows is an abstraction of sql.Rows.
|
2025-04-29 06:03:47 +02:00
|
|
|
type Rows interface {
|
|
|
|
Row
|
|
|
|
Next() bool
|
|
|
|
Close() error
|
|
|
|
Err() error
|
|
|
|
}
|