Skip to content

Commit

Permalink
Merge pull request #954 from go-kivik/reduce
Browse files Browse the repository at this point in the history
Begin adding reduce support
  • Loading branch information
flimzy authored Apr 29, 2024
2 parents f6eb95f + 1f7cfe8 commit 33b382a
Show file tree
Hide file tree
Showing 8 changed files with 473 additions and 52 deletions.
2 changes: 1 addition & 1 deletion x/sqlite/designdocs.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (d *db) updateDesignDoc(ctx context.Context, tx *sql.Tx, rev revision, data
}

func (d *db) createViewMap(ctx context.Context, tx *sql.Tx, ddoc, name, rev string) error {
for _, query := range viewMapSchema {
for _, query := range viewSchema {
if _, err := tx.ExecContext(ctx, d.ddocQuery(ddoc, name, rev, query)); err != nil {
return err
}
Expand Down
32 changes: 22 additions & 10 deletions x/sqlite/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,39 +162,43 @@ func toUint64(in interface{}, msg string) (uint64, error) {
}
}

func toBool(in interface{}) bool {
func toBool(in interface{}) (value bool, ok bool) {
switch t := in.(type) {
case bool:
return t
return t, true
case string:
b, _ := strconv.ParseBool(t)
return b
b, err := strconv.ParseBool(t)
return b, err == nil
default:
return false
return false, false
}
}

func (o optsMap) direction() string {
if toBool(o["descending"]) {
if v, _ := toBool(o["descending"]); v {
return "DESC"
}
return "ASC"
}

func (o optsMap) includeDocs() bool {
return toBool(o["include_docs"])
v, _ := toBool(o["include_docs"])
return v
}

func (o optsMap) attachments() bool {
return toBool(o["attachments"])
v, _ := toBool(o["attachments"])
return v
}

func (o optsMap) latest() bool {
return toBool(o["latest"])
v, _ := toBool(o["latest"])
return v
}

func (o optsMap) revs() bool {
return toBool(o["revs"])
v, _ := toBool(o["revs"])
return v
}

const (
Expand Down Expand Up @@ -226,3 +230,11 @@ func (o optsMap) update() (string, error) {
}
return "", &internal.Error{Status: http.StatusBadRequest, Message: "invalid value for `update`"}
}

func (o optsMap) reduce() *bool {
v, ok := toBool(o["reduce"])
if !ok {
return nil
}
return &v
}
2 changes: 1 addition & 1 deletion x/sqlite/put_designdocs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func TestDBPut_designDocs(t *testing.T) {
SELECT COUNT(*)
FROM sqlite_master
WHERE type = 'table'
AND name LIKE 'foo_%_map_bar_%'
AND name LIKE 'foo_%_bar_map_%'
`).Scan(&viewCount)
if err != nil {
t.Fatal(err)
Expand Down
Loading

0 comments on commit 33b382a

Please sign in to comment.