Skip to content

Commit dc9979a

Browse files
authored
Empty row count returns error instead (#20)
* Fix default mode set KV V2 bug * Fix row count stmt when it's returning emtpy * Apply Code Coverage Badge --------- Co-authored-by: edocsss <[email protected]>
1 parent d54592a commit dc9979a

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
![Unit Test](https://github.com/FreeLeh/GoFreeDB/actions/workflows/unit_test.yml/badge.svg)
2121
![Integration Test](https://github.com/FreeLeh/GoFreeDB/actions/workflows/full_test.yml/badge.svg)
22-
![Coverage](https://img.shields.io/badge/Coverage-83.0%25-brightgreen)
22+
![Coverage](https://img.shields.io/badge/Coverage-83.1%25-brightgreen)
2323
[![Go Report Card](https://goreportcard.com/badge/github.com/FreeLeh/GoFreeDB)](https://goreportcard.com/report/github.com/FreeLeh/GoFreeDB)
2424
[![Go Reference](https://pkg.go.dev/badge/github.com/FreeLeh/GoFreeDB.svg)](https://pkg.go.dev/github.com/FreeLeh/GoFreeDB)
2525

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: 8 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,12 @@ 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.
609+
if len(result.Rows) < 1 || len(result.Rows[0]) < 1 {
610+
return 0, nil
611+
}
607612
if len(result.Rows) != 1 || len(result.Rows[0]) != 1 {
608-
return 0, errors.New("")
613+
return 0, errors.New("unexpected number of rows or columns")
609614
}
610615

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

0 commit comments

Comments
 (0)