Skip to content

Commit 7f9f6c3

Browse files
committed
Fix row count stmt when it's returning emtpy
1 parent 3e362b6 commit 7f9f6c3

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

internal/google/store/row_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ package store
33
import (
44
"context"
55
"fmt"
6-
"github.com/FreeLeh/GoFreeDB/internal/common"
7-
"github.com/FreeLeh/GoFreeDB/internal/models"
86
"strconv"
97
"testing"
108
"time"
119

10+
"github.com/FreeLeh/GoFreeDB/internal/common"
11+
"github.com/FreeLeh/GoFreeDB/internal/models"
12+
1213
"github.com/FreeLeh/GoFreeDB/google/auth"
1314
"github.com/stretchr/testify/assert"
1415
)
@@ -43,6 +44,11 @@ func TestGoogleSheetRowStore_Integration(t *testing.T) {
4344
_ = db.Close(context.Background())
4445
}()
4546

47+
time.Sleep(time.Second)
48+
res, err := db.Count().Exec(context.Background())
49+
assert.Equal(t, uint64(0), res)
50+
assert.Nil(t, err)
51+
4652
var out []testPerson
4753

4854
time.Sleep(time.Second)

internal/google/store/stmt.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ import (
44
"context"
55
"errors"
66
"fmt"
7-
"github.com/FreeLeh/GoFreeDB/internal/common"
8-
"github.com/FreeLeh/GoFreeDB/internal/models"
97
"reflect"
108
"strconv"
119
"strings"
1210

11+
"github.com/FreeLeh/GoFreeDB/internal/common"
12+
"github.com/FreeLeh/GoFreeDB/internal/models"
13+
1314
"github.com/FreeLeh/GoFreeDB/internal/google/sheets"
1415
)
1516

@@ -604,8 +605,9 @@ func (s *GoogleSheetCountStmt) Exec(ctx context.Context) (uint64, error) {
604605
return 0, err
605606
}
606607

608+
// When COUNT() returns 0, somehow it returns empty row slice.
607609
if len(result.Rows) != 1 || len(result.Rows[0]) != 1 {
608-
return 0, errors.New("")
610+
return 0, nil
609611
}
610612

611613
count := result.Rows[0][0].(float64)

0 commit comments

Comments
 (0)