Skip to content

Commit ed56418

Browse files
committed
brain/sqlbrain: don't use nulls when forgetting
1 parent ed173e2 commit ed56418

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

brain/braintest/braintest.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ func testForgetful(ctx context.Context, br Interface) func(t *testing.T) {
3838
Time: time.Unix(0, 0),
3939
}
4040
text := "bocchi ryou nijika kita"
41-
if err := brain.Learn(ctx, br, &msg, brain.Tokens(nil, text)); err != nil {
41+
toks := brain.Tokens(nil, text)
42+
if err := brain.Learn(ctx, br, &msg, toks); err != nil {
4243
t.Errorf("failed to learn: %v", err)
4344
}
4445
s, err := brain.Speak(ctx, br, tag, "")
@@ -48,14 +49,14 @@ func testForgetful(ctx context.Context, br Interface) func(t *testing.T) {
4849
if s != text {
4950
t.Errorf("surprise thought: %q", s)
5051
}
51-
if err := brain.Forget(ctx, br, tag, brain.Tokens(nil, text)); err != nil {
52+
if err := brain.Forget(ctx, br, tag, toks); err != nil {
5253
t.Errorf("failed to forget: %v", err)
5354
}
5455
// We don't really care about an error here, since the brain is empty.
5556
// All we care about is no thoughts.
5657
s, _ = brain.Speak(ctx, br, tag, "")
5758
if s != "" {
58-
t.Errorf("remembered that which must be forgotten: %v", err)
59+
t.Errorf("remembered that which must be forgotten: %q", s)
5960
}
6061
}
6162
}

brain/sqlbrain/forget.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
func (br *Brain) Forget(ctx context.Context, tag string, tuples []brain.Tuple) error {
2323
names := make([]sq.NamedArg, 2+br.order)
2424
names[0] = sql.Named("tag", tag)
25-
terms := make([]sq.NullString, 1+br.order)
25+
terms := make([]string, 1+br.order)
2626
for i := 0; i < br.order; i++ {
2727
names[i+1] = sql.Named("p"+strconv.Itoa(i), &terms[i])
2828
}
@@ -40,10 +40,8 @@ func (br *Brain) Forget(ctx context.Context, tag string, tuples []brain.Tuple) e
4040
// Note that each p[i] is a named arg, and those for the prefix and
4141
// suffix each point to an element of terms. So, updating terms is
4242
// sufficient to update the query parameters.
43-
for i, w := range tup.Prefix {
44-
terms[i] = sq.NullString{String: w, Valid: w != ""}
45-
}
46-
terms[br.order] = sq.NullString{String: tup.Suffix, Valid: tup.Suffix != ""}
43+
copy(terms, tup.Prefix)
44+
terms[br.order] = tup.Suffix
4745
// Execute the statements in order. We do this manually because the
4846
// arguments differ for some statements, and the SQLite3 driver
4947
// complains if we give the wrong ones.

0 commit comments

Comments
 (0)