Skip to content

Commit c0288ad

Browse files
authored
Remove Select* functions other than SelectOne (#14)
The deleted functions had the unfortunate quirk that they would return `nil, nil` if there were no results, where `SelectOne` returns `nil, sql.ErrNoRows`. This created confusion about error handling. Boulder only used one of these functions, `SelectNullInt`, and that is being replaced by `SelectOne`. Deletions (including initial test cleanup) implemented by Claude based on the prompt "Please delete these functions: <list of functions>." I updated TestSelectVal to maintain the original spirit. I had to add a new row containing nulls for the various fields, because many of the existing test cases were testing for "no rows found" as opposed to "null values." Now we test both of those.
1 parent 7962ead commit c0288ad

5 files changed

Lines changed: 115 additions & 452 deletions

File tree

db.go

Lines changed: 0 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -624,90 +624,6 @@ func (m *DbMap) ExecContext(ctx context.Context, query string, args ...interface
624624
return maybeExpandNamedQueryAndExec(ctx, m, query, args...)
625625
}
626626

627-
// SelectInt is a convenience wrapper around the borp.SelectInt function
628-
func (m *DbMap) SelectInt(ctx context.Context, query string, args ...interface{}) (int64, error) {
629-
if m.ExpandSliceArgs {
630-
expandSliceArgs(&query, args...)
631-
}
632-
633-
args, err := m.convertArgs(args...)
634-
if err != nil {
635-
return 0, err
636-
}
637-
638-
return SelectInt(ctx, m, query, args...)
639-
}
640-
641-
// SelectNullInt is a convenience wrapper around the borp.SelectNullInt function
642-
func (m *DbMap) SelectNullInt(ctx context.Context, query string, args ...interface{}) (sql.NullInt64, error) {
643-
if m.ExpandSliceArgs {
644-
expandSliceArgs(&query, args...)
645-
}
646-
647-
args, err := m.convertArgs(args...)
648-
if err != nil {
649-
return sql.NullInt64{}, err
650-
}
651-
652-
return SelectNullInt(ctx, m, query, args...)
653-
}
654-
655-
// SelectFloat is a convenience wrapper around the borp.SelectFloat function
656-
func (m *DbMap) SelectFloat(ctx context.Context, query string, args ...interface{}) (float64, error) {
657-
if m.ExpandSliceArgs {
658-
expandSliceArgs(&query, args...)
659-
}
660-
661-
args, err := m.convertArgs(args...)
662-
if err != nil {
663-
return 0, err
664-
}
665-
666-
return SelectFloat(ctx, m, query, args...)
667-
}
668-
669-
// SelectNullFloat is a convenience wrapper around the borp.SelectNullFloat function
670-
func (m *DbMap) SelectNullFloat(ctx context.Context, query string, args ...interface{}) (sql.NullFloat64, error) {
671-
if m.ExpandSliceArgs {
672-
expandSliceArgs(&query, args...)
673-
}
674-
675-
args, err := m.convertArgs(args...)
676-
if err != nil {
677-
return sql.NullFloat64{}, err
678-
}
679-
680-
return SelectNullFloat(ctx, m, query, args...)
681-
}
682-
683-
// SelectStr is a convenience wrapper around the borp.SelectStr function
684-
func (m *DbMap) SelectStr(ctx context.Context, query string, args ...interface{}) (string, error) {
685-
if m.ExpandSliceArgs {
686-
expandSliceArgs(&query, args...)
687-
}
688-
689-
args, err := m.convertArgs(args...)
690-
if err != nil {
691-
return "", err
692-
}
693-
694-
return SelectStr(ctx, m, query, args...)
695-
}
696-
697-
// SelectNullStr is a convenience wrapper around the borp.SelectNullStr function
698-
func (m *DbMap) SelectNullStr(ctx context.Context, query string, args ...interface{}) (sql.NullString, error) {
699-
if m.ExpandSliceArgs {
700-
expandSliceArgs(&query, args...)
701-
}
702-
703-
args, err := m.convertArgs(args...)
704-
if err != nil {
705-
return sql.NullString{}, err
706-
}
707-
708-
return SelectNullStr(ctx, m, query, args...)
709-
}
710-
711627
// SelectOne is a convenience wrapper around the borp.SelectOne function
712628
func (m *DbMap) SelectOne(ctx context.Context, holder interface{}, query string, args ...interface{}) error {
713629
if m.ExpandSliceArgs {

gorp.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,6 @@ type SqlExecutor interface {
7070
Update(ctx context.Context, list ...interface{}) (int64, error)
7171
Delete(ctx context.Context, list ...interface{}) (int64, error)
7272
Select(ctx context.Context, i interface{}, query string, args ...interface{}) ([]interface{}, error)
73-
SelectInt(ctx context.Context, query string, args ...interface{}) (int64, error)
74-
SelectNullInt(ctx context.Context, query string, args ...interface{}) (sql.NullInt64, error)
75-
SelectFloat(ctx context.Context, query string, args ...interface{}) (float64, error)
76-
SelectNullFloat(ctx context.Context, query string, args ...interface{}) (sql.NullFloat64, error)
77-
SelectStr(ctx context.Context, query string, args ...interface{}) (string, error)
78-
SelectNullStr(ctx context.Context, query string, args ...interface{}) (sql.NullString, error)
7973
SelectOne(ctx context.Context, holder interface{}, query string, args ...interface{}) error
8074

8175
// These method signatures are shared with *sql.DB.

0 commit comments

Comments
 (0)