Skip to content

Commit 3d1eb2a

Browse files
authored
Merge pull request #1046 from go-kivik/dedupeSplit
x/sqlite: Update core kivik dep, and dedupe SplitKeys function
2 parents ada1fcc + 05336fb commit 3d1eb2a

File tree

4 files changed

+8
-82
lines changed

4 files changed

+8
-82
lines changed

x/sqlite/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.22.0
55
require (
66
github.com/cenkalti/backoff/v4 v4.3.0
77
github.com/dop251/goja v0.0.0-20240220182346-e401ed450204
8-
github.com/go-kivik/kivik/v4 v4.2.4-0.20240716145309-5be038df2f1e
8+
github.com/go-kivik/kivik/v4 v4.3.2-0.20240911141255-ada1fcc539f5
99
github.com/google/go-cmp v0.6.0
1010
github.com/google/uuid v1.6.0
1111
github.com/mitchellh/mapstructure v1.5.0

x/sqlite/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ github.com/dop251/goja_nodejs v0.0.0-20210225215109-d91c329300e7/go.mod h1:hn7BA
1818
github.com/dop251/goja_nodejs v0.0.0-20211022123610-8dd9abb0616d/go.mod h1:DngW8aVqWbuLRMHItjPUyqdj+HWPvnQe8V8y1nDpIbM=
1919
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
2020
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
21-
github.com/go-kivik/kivik/v4 v4.2.4-0.20240716145309-5be038df2f1e h1:1V2uq+tL0mnfCr01Lg6LLgznVxHXK4+5MmYywxMluAs=
22-
github.com/go-kivik/kivik/v4 v4.2.4-0.20240716145309-5be038df2f1e/go.mod h1:uPonn+OcrDYyZqPXZDTANaWPpmBWAIlpk6gEDnFnDpE=
21+
github.com/go-kivik/kivik/v4 v4.3.2-0.20240911141255-ada1fcc539f5 h1:3BgmgTbGbNIkqiO+g81SCQSjb+cFbUuPbo2dUPBteOo=
22+
github.com/go-kivik/kivik/v4 v4.3.2-0.20240911141255-ada1fcc539f5/go.mod h1:uPonn+OcrDYyZqPXZDTANaWPpmBWAIlpk6gEDnFnDpE=
2323
github.com/go-sourcemap/sourcemap v2.1.3+incompatible h1:W1iEw64niKVGogNgBN3ePyLFfuisuzeidWPMPWmECqU=
2424
github.com/go-sourcemap/sourcemap v2.1.3+incompatible/go.mod h1:F8jJfvm2KbVjc5NqelyYJmf/v5J0dwNLS2mL4sNA1Jg=
2525
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=

x/sqlite/json.go

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"strings"
2828

2929
internal "github.com/go-kivik/kivik/v4/int/errors"
30+
"github.com/go-kivik/kivik/v4/x/mango"
3031
)
3132

3233
type revision struct {
@@ -456,7 +457,7 @@ func (d *fullDoc) toRaw(fields ...string) json.RawMessage {
456457
if f == "_id" || f == "_rev" {
457458
continue
458459
}
459-
keys := splitKeys(f)
460+
keys := mango.SplitKeys(f)
460461
if v, ok := extractValue(doc, keys...); ok {
461462
insertValue(tmp, v, keys)
462463
}
@@ -495,36 +496,6 @@ func (d *fullDoc) toRaw(fields ...string) json.RawMessage {
495496
return result
496497
}
497498

498-
// splitKeys splits a field into its component keys. For example,
499-
// `splitKeys("foo.bar")` returns `["foo", "bar"]`. Escaped dots are treated as
500-
// a single key, so `splitKeys("foo\\.bar")` returns `["foo.bar"]`.
501-
func splitKeys(field string) []string {
502-
var escaped bool
503-
result := []string{}
504-
word := make([]byte, 0, len(field))
505-
for _, ch := range field {
506-
if escaped {
507-
word = append(word, byte(ch))
508-
escaped = false
509-
continue
510-
}
511-
if ch == '\\' {
512-
escaped = true
513-
continue
514-
}
515-
if ch == '.' {
516-
result = append(result, string(word))
517-
word = word[:0]
518-
continue
519-
}
520-
word = append(word, byte(ch))
521-
}
522-
if escaped {
523-
word = append(word, '\\')
524-
}
525-
return append(result, string(word))
526-
}
527-
528499
func extractValue(obj map[string]interface{}, keys ...string) (interface{}, bool) {
529500
for i, key := range keys {
530501
if i == len(keys)-1 {

x/sqlite/json_test.go

Lines changed: 3 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func Test_prepareDoc(t *testing.T) {
9898
t.Errorf("unexpected error = %v, wantErr %v", err, tt.wantErr)
9999
}
100100
if d := cmp.Diff(tt.want, got); d != "" {
101-
t.Errorf(d)
101+
t.Error(d)
102102
}
103103
})
104104
}
@@ -220,7 +220,7 @@ func Test_revsInfo_revs(t *testing.T) {
220220
got = append(got, r.String())
221221
}
222222
if d := cmp.Diff(tt.want, got); d != "" {
223-
t.Errorf(d)
223+
t.Error(d)
224224
}
225225
})
226226
}
@@ -262,7 +262,7 @@ func Test_mergeIntoDoc(t *testing.T) {
262262
t.Run(tt.name, func(t *testing.T) {
263263
got, _ := io.ReadAll(tt.doc.toReader())
264264
if d := cmp.Diff(tt.want, string(got)); d != "" {
265-
t.Errorf(d)
265+
t.Error(d)
266266
}
267267
})
268268
}
@@ -323,48 +323,3 @@ func Test_RevID(t *testing.T) {
323323
})
324324
}
325325
}
326-
327-
func Test_splitKeys(t *testing.T) {
328-
tests := []struct {
329-
input string
330-
want []string
331-
}{
332-
{
333-
input: "foo.bar.baz",
334-
want: []string{"foo", "bar", "baz"},
335-
},
336-
{
337-
input: "foo",
338-
want: []string{"foo"},
339-
},
340-
{
341-
input: "",
342-
want: []string{""},
343-
},
344-
{
345-
input: "foo\\.bar",
346-
want: []string{"foo.bar"},
347-
},
348-
{
349-
input: "foo\\\\.bar",
350-
want: []string{"foo\\", "bar"},
351-
},
352-
{
353-
input: "foo\\",
354-
want: []string{"foo\\"},
355-
},
356-
{
357-
input: "foo.",
358-
want: []string{"foo", ""},
359-
},
360-
}
361-
362-
for _, tt := range tests {
363-
t.Run(tt.input, func(t *testing.T) {
364-
got := splitKeys(tt.input)
365-
if d := cmp.Diff(tt.want, got); d != "" {
366-
t.Errorf("unexpected keys (-want, +got): %s", d)
367-
}
368-
})
369-
}
370-
}

0 commit comments

Comments
 (0)