nidus-sync/db/tx.go
Eli Ribble 10046f1edb lint: remove unused items from resource, sync, platform, db
- Remove contentUploadList/Placeholder/Detail from resource/upload.go
- Remove toImageURLs, userURI from resource/communication.go
- Remove responseListUser from resource/user.go
- Remove contentSignin/getSignin from sync/signin.go (re-add contentSignin used elsewhere)
- Delete sync/service-request.go (entirely unused)
- Remove _rowWithID from platform/signal.go
- Remove unused tag field from db/tx.go Rows struct
2026-05-09 17:19:38 +00:00

82 lines
1.8 KiB
Go

package db
import (
"context"
"database/sql"
"fmt"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgconn"
"github.com/rs/zerolog/log"
//"github.com/stephenafamo/scan"
)
type Ex interface {
Exec(ctx context.Context, sql string, arguments ...any) (commandTag pgconn.CommandTag, err error)
Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)
}
type Tx struct {
pgx.Tx
}
func (txn Tx) ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error) {
result, err := txn.Tx.Exec(ctx, query, args...)
if err != nil {
return Result{}, fmt.Errorf("exec: %w", err)
}
return Result{
tag: result,
}, nil
}
/*
func (txn Tx) QueryContext(ctx context.Context, query string, args ...any) (scan.Rows, error) {
result, err := txn.Tx.Exec(ctx, query, args...)
return Rows{
tag: result,
}, err
}
*/
type Result struct {
tag pgconn.CommandTag
}
func (r Result) LastInsertId() (int64, error) {
log.Debug().Msg("queried last insert id. erroring...")
return 0, fmt.Errorf("not implemented")
}
func (r Result) RowsAffected() (int64, error) {
rows := r.tag.RowsAffected()
log.Debug().Int64("rows", rows).Msg("queried rows affected")
return rows, nil
}
type Rows struct {
}
func (r Rows) Close() error {
log.Debug().Msg("requested close of rows")
return nil
}
func (r Rows) Columns() ([]string, error) {
log.Debug().Msg("requested columns")
return []string{}, nil
}
func (r Rows) Err() error {
log.Debug().Msg("requested err")
return nil
}
func (r Rows) Next() bool {
log.Debug().Msg("requested next")
return false
}
func (r Rows) Scan(args ...any) error {
log.Debug().Msg("requested scan")
return fmt.Errorf("scan not implemented")
}
func BeginTxn(ctx context.Context) (Tx, error) {
txn, err := PGInstance.PGXPool.BeginTx(ctx, pgx.TxOptions{})
return Tx{
Tx: txn,
}, err
}