Repository: genjidb/genji (go)

Issue:
SQL driver doesn't support timestamp (time.Time)
I have seen an issue about supporting `time.Time` in sql driver: https://github.com/genjidb/genji/issues/154.

But it seems that `time.Time` still doesn't work. Parser doesn't recognize keyword `TIMESTAMP` (not surprisingly, no changes was made in driver in corresponding MR for that issue).

```go
package main

import (
	"database/sql"
	"fmt"
	"time"

	_ "github.com/genjidb/genji/sql/driver"
)

func main() {
	db, err := sql.Open("genji", ":memory:")
	if err != nil {
		panic(err)
	}
	defer db.Close()

	_, err = db.Exec(`CREATE TABLE foo (created_at TIMESTAMP NOT NULL)`)
	if err != nil {
		panic(err)
	}
       //...
```

Prints: 

```sh
panic: found TIMESTAMP, expected ) at line 1, char 30
```

Scanning `time.Time` stored as `TEXT` doesn't work either:

```go
package main

import (
	"database/sql"
	"fmt"
	"time"

	_ "github.com/genjidb/genji/sql/driver"
)

func main() {
	db, err := sql.Open("genji", ":memory:")
	if err != nil {
		panic(err)
	}
	defer db.Close()

	_, err = db.Exec(`CREATE TABLE foo (created_at TEXT NOT NULL)`)
	if err != nil {
		panic(err)
	}

	_, err = db.Exec(`INSERT INTO foo (created_at) VALUES (?)`, time.Now().UTC())
	if err != nil {
		panic(err)
	}

	rows, err := db.Query(`SELECT created_at FROM foo`)
	if err != nil {
		panic(err)
	}
	defer rows.Close()
	for rows.Next() {
		var createdAt time.Time
		if err := rows.Scan(&createdAt); err != nil {
			panic(err)
		}
		fmt.Printf("foo found: (%v)", createdAt)
	}
	if err := rows.Err(); err != nil {
		panic(err)
	}
}
```

Prints: 

```sh
panic: sql: Scan error on column index 0, name "created_at": unsupported Scan, storing driver.Value type string into type *time.Time
```

Is this a bug or I misusing sql driver?

Pull request:
Fix scanning of time.Time in sql/driver
Fixes #258

Patch:
diff --git a/sql/driver/driver.go b/sql/driver/driver.go
index 6dc4ae84..27c8cfb6 100644
--- a/sql/driver/driver.go
+++ b/sql/driver/driver.go
@@ -426,15 +426,15 @@ func (rs *documentStream) Next(dest []driver.Value) error {
 }
 
 type valueScanner struct {
-	v interface{}
+	dest interface{}
 }
 
 func (v valueScanner) Scan(src interface{}) error {
 	switch t := src.(type) {
 	case document.Document:
-		return document.StructScan(t, v.v)
+		return document.StructScan(t, v.dest)
 	case document.Array:
-		return document.SliceScan(t, v.v)
+		return document.SliceScan(t, v.dest)
 	case document.Value:
 		return document.ScanValue(t, src)
 	}
@@ -444,7 +444,7 @@ func (v valueScanner) Scan(src interface{}) error {
 		return err
 	}
 
-	return document.ScanValue(vv, &src)
+	return document.ScanValue(vv, v.dest)
 }
 
 // Scanner turns a variable into a sql.Scanner.


Test patch:
diff --git a/sql/driver/driver_test.go b/sql/driver/driver_test.go
index eb087c13..b6ba9569 100644
--- a/sql/driver/driver_test.go
+++ b/sql/driver/driver_test.go
@@ -4,6 +4,7 @@ import (
 	"context"
 	"database/sql"
 	"testing"
+	"time"
 
 	"github.com/genjidb/genji/engine"
 	"github.com/stretchr/testify/require"
@@ -262,3 +263,22 @@ func TestDriver(t *testing.T) {
 		require.Equal(t, err, engine.ErrTransactionReadOnly)
 	})
 }
+
+func TestDriverWithTimeValues(t *testing.T) {
+	db, err := sql.Open("genji", ":memory:")
+	require.NoError(t, err)
+	defer db.Close()
+
+	now := time.Now().UTC()
+	_, err = db.Exec("CREATE TABLE test; INSERT INTO test (a) VALUES (?)", now)
+	require.NoError(t, err)
+
+	tx, err := db.BeginTx(context.Background(), &sql.TxOptions{ReadOnly: true})
+	require.NoError(t, err)
+	defer tx.Rollback()
+
+	var tt time.Time
+	err = tx.QueryRow(`SELECT a FROM test`).Scan(Scanner(&tt))
+	require.NoError(t, err)
+	require.Equal(t, now, tt)
+}