feat(mysql)!: promote to v1.0.0 — BeginTx with isolation levels, Stats, bump all deps to v1.0.0
Add BeginTx(ctx, *sql.TxOptions) to Client interface for explicit transaction isolation level control; Begin refactored as a convenience wrapper calling BeginTx(ctx, nil). Add Stats() sql.DBStats to Component interface for connection pool observability. Bump all micro-lib dependencies (logz, health, launcher, xerrors) from v0.9.0 to v1.0.0. API committed as stable.
This commit is contained in:
20
mysql.go
20
mysql.go
@@ -33,6 +33,7 @@ type Tx interface {
|
||||
type Client interface {
|
||||
GetExecutor(ctx context.Context) Executor
|
||||
Begin(ctx context.Context) (Tx, error)
|
||||
BeginTx(ctx context.Context, opts *sql.TxOptions) (Tx, error)
|
||||
Ping(ctx context.Context) error
|
||||
HandleError(err error) error
|
||||
}
|
||||
@@ -42,6 +43,7 @@ type Component interface {
|
||||
launcher.Component
|
||||
health.Checkable
|
||||
Client
|
||||
Stats() sql.DBStats
|
||||
}
|
||||
|
||||
// UnitOfWork wraps operations in a single database transaction.
|
||||
@@ -192,20 +194,34 @@ func (c *mysqlComponent) GetExecutor(ctx context.Context) Executor {
|
||||
return db
|
||||
}
|
||||
|
||||
func (c *mysqlComponent) Begin(ctx context.Context) (Tx, error) {
|
||||
func (c *mysqlComponent) BeginTx(ctx context.Context, opts *sql.TxOptions) (Tx, error) {
|
||||
c.mu.RLock()
|
||||
db := c.db
|
||||
c.mu.RUnlock()
|
||||
if db == nil {
|
||||
return nil, fmt.Errorf("mysql: not initialized")
|
||||
}
|
||||
tx, err := db.BeginTx(ctx, nil)
|
||||
tx, err := db.BeginTx(ctx, opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &mysqlTx{Tx: tx}, nil
|
||||
}
|
||||
|
||||
func (c *mysqlComponent) Begin(ctx context.Context) (Tx, error) {
|
||||
return c.BeginTx(ctx, nil)
|
||||
}
|
||||
|
||||
func (c *mysqlComponent) Stats() sql.DBStats {
|
||||
c.mu.RLock()
|
||||
db := c.db
|
||||
c.mu.RUnlock()
|
||||
if db == nil {
|
||||
return sql.DBStats{}
|
||||
}
|
||||
return db.Stats()
|
||||
}
|
||||
|
||||
func (c *mysqlComponent) ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error) {
|
||||
c.mu.RLock()
|
||||
db := c.db
|
||||
|
||||
Reference in New Issue
Block a user