Repository: genjidb/genji (go)

Issue:
StructScan not working when struct has slice of pointer types
<!-- Please answer these questions before submitting your issue. Thanks! -->

### What version of Genji are you using?

<pre>
$ genji version 
Genji v0.10.0
Genji CLI v0.10.0
</pre>

### Does this issue reproduce with the latest release?

<!-- Yes/no -->
Yes 
### What did you do?

<!--
If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org or goplay.space is best. You may use
https://play.golang.org/p/_pr_rOXsAH3 as a starting point.
-->

```go
package main

import (
        "fmt"
        "log"

        "github.com/genjidb/genji"
        "github.com/genjidb/genji/document"
)

type User struct {
        Name    string
        Reviews []*Review
}

type Review struct {
        Item   string
        Review string
        Rating int
}


func main() {

        db, err := genji.Open(":memory:")
        if err != nil {
                log.Fatal(err)
        }

        db.Exec("CREATE table users")

        u := User{
                Name: "Foo",
                Reviews: []*Review{
                        &Review{"Harry Potter", "Great Book", 9},
                },
        }

        db.Exec("INSERT INTO users VALUES ?", &u)

        var users []User
        res, err := db.Query("SELECT * FROM users")
        if err != nil {
                log.Fatal(err)
        }

        defer res.Close()
        err = res.Iterate(func(d document.Document) error {
                var u User
                err = document.StructScan(d, &u)
                if err != nil {
                        return err
                }
                users = append(users, u)
                return nil
        })
        if err != nil {
                log.Fatal(err)
        }

        fmt.Println("Users:", users)
}

```


### What did you expect to see?

<!-- The expected behavior -->
`Users: [{Foo [0xc0000a4ab0]}]`
### What did you see instead?

<!-- The observed behavior -->
`panic: reflect.Set: value of type **main.Review is not assignable to type *main.Review`


### What Go version and environment are you using?

<pre>
$ go version
go version go1.15.7 linux/amd64
</pre>

<details><summary><code>go env</code> Output</summary><br><pre>
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/justin/.cache/go-build"
GOENV="/home/justin/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/justin/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/justin/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build523484142=/tmp/go-build -gno-record-gcc-switches"
</pre></details>


Pull request:
Fix scanning of slice of structs
Fixes #341 

Patch:
diff --git a/document/scan.go b/document/scan.go
index 42392f1d..27525e6f 100644
--- a/document/scan.go
+++ b/document/scan.go
@@ -156,11 +156,7 @@ func sliceScan(a Array, ref reflect.Value) error {
 				return err
 			}
 
-			if stp.Elem().Kind() == reflect.Ptr {
-				sref = reflect.Append(sref, newV)
-			} else {
-				sref = reflect.Append(sref, reflect.Indirect(newV))
-			}
+			sref = reflect.Append(sref, reflect.Indirect(newV))
 		}
 
 		return nil


Test patch:
diff --git a/document/scan_test.go b/document/scan_test.go
index 3c5a3998..4485e6a7 100644
--- a/document/scan_test.go
+++ b/document/scan_test.go
@@ -10,6 +10,14 @@ import (
 	"github.com/stretchr/testify/require"
 )
 
+func strPtr(s string) *string {
+	return &s
+}
+
+func boolPtr(b bool) *bool {
+	return &b
+}
+
 func TestScan(t *testing.T) {
 	now := time.Now()
 
@@ -67,7 +75,32 @@ func TestScan(t *testing.T) {
 		)).
 		Add("o", document.NewNullValue()).
 		Add("p", document.NewTextValue(now.Format(time.RFC3339Nano))).
-		Add("r", document.NewDocumentValue(codec.NewDocument(buf.Bytes())))
+		Add("r", document.NewDocumentValue(codec.NewDocument(buf.Bytes()))).
+		Add("s", document.NewArrayValue(document.NewValueBuffer(document.NewBoolValue(true), document.NewBoolValue(false)))).
+		Add("u", document.NewArrayValue(document.NewValueBuffer(
+			document.NewDocumentValue(
+				document.NewFieldBuffer().
+					Add("foo", document.NewTextValue("a")).
+					Add("bar", document.NewTextValue("b")),
+			),
+			document.NewDocumentValue(
+				document.NewFieldBuffer().
+					Add("foo", document.NewTextValue("c")).
+					Add("bar", document.NewTextValue("d")),
+			),
+		))).
+		Add("v", document.NewArrayValue(document.NewValueBuffer(
+			document.NewDocumentValue(
+				document.NewFieldBuffer().
+					Add("foo", document.NewTextValue("a")).
+					Add("bar", document.NewTextValue("b")),
+			),
+			document.NewDocumentValue(
+				document.NewFieldBuffer().
+					Add("foo", document.NewTextValue("c")).
+					Add("bar", document.NewTextValue("d")),
+			),
+		)))
 
 	type foo struct {
 		Foo string
@@ -92,8 +125,11 @@ func TestScan(t *testing.T) {
 	var o []int = []int{1, 2, 3}
 	var p time.Time
 	var r map[string]interface{}
+	var s []*bool
+	var u []foo
+	var v []*foo
 
-	err = document.Scan(doc, &a, &b, &c, &d, &e, &f, &g, &h, &i, &j, &k, &l, &m, &n, &o, &p, &r)
+	err = document.Scan(doc, &a, &b, &c, &d, &e, &f, &g, &h, &i, &j, &k, &l, &m, &n, &o, &p, &r, &s, &u, &v)
 	require.NoError(t, err)
 	require.Equal(t, a, []byte("foo"))
 	require.Equal(t, b, "bar")
@@ -105,10 +141,9 @@ func TestScan(t *testing.T) {
 	require.Equal(t, h, int64(10))
 	require.Equal(t, i, float64(10.5))
 	require.Equal(t, j, []bool{true})
-	bar := "bar"
-	require.Equal(t, foo{Foo: "foo", Pub: &bar}, k)
-	require.Equal(t, &foo{Foo: "foo", Pub: &bar}, l)
-	require.Equal(t, &foo{Foo: "foo", Pub: &bar}, m)
+	require.Equal(t, foo{Foo: "foo", Pub: strPtr("bar")}, k)
+	require.Equal(t, &foo{Foo: "foo", Pub: strPtr("bar")}, l)
+	require.Equal(t, &foo{Foo: "foo", Pub: strPtr("bar")}, m)
 	require.Equal(t, map[string]string{"foo": "foo", "bar": "bar"}, n)
 	require.Equal(t, []int(nil), o)
 	require.Equal(t, now.Format(time.RFC3339Nano), p.Format(time.RFC3339Nano))
@@ -121,6 +156,10 @@ func TestScan(t *testing.T) {
 			},
 		},
 	}, r)
+	require.Equal(t, []*bool{boolPtr(true), boolPtr(false)}, s)
+	require.Equal(t, foo{Foo: "foo", Pub: strPtr("bar")}, k)
+	require.Equal(t, []foo{{Foo: "a", Pub: strPtr("b")}, {Foo: "c", Pub: strPtr("d")}}, u)
+	require.Equal(t, []*foo{{Foo: "a", Pub: strPtr("b")}, {Foo: "c", Pub: strPtr("d")}}, v)
 
 	t.Run("DocumentScanner", func(t *testing.T) {
 		var ds documentScanner
@@ -136,14 +175,14 @@ func TestScan(t *testing.T) {
 		m := make(map[string]interface{})
 		err := document.MapScan(doc, m)
 		require.NoError(t, err)
-		require.Len(t, m, 17)
+		require.Len(t, m, 20)
 	})
 
 	t.Run("MapPtr", func(t *testing.T) {
 		var m map[string]interface{}
 		err := document.MapScan(doc, &m)
 		require.NoError(t, err)
-		require.Len(t, m, 17)
+		require.Len(t, m, 20)
 	})
 
 	t.Run("Small Slice", func(t *testing.T) {