Repository: doug-martin/goqu (Go)

Issue:
SQLite supports `RETURNING` clauses
**Describe the bug**
SQLite3 dialect is declared as not supporting `RETURNING` clauses

https://github.com/doug-martin/goqu/blob/31d438d38230118d377f11cfaad9627aa3a23864/dialect/sqlite3/sqlite3.go#L13

but it actually does.

> The RETURNING syntax has been supported by SQLite since version 3.35.0 (2021-03-12).

https://www.sqlite.org/lang_returning.html

**To Reproduce**

Here's a test to reproduce the issue + the workaround I'm using:

```go
package main

import (
	"database/sql"
	"testing"

	_ "modernc.org/sqlite"

	"github.com/doug-martin/goqu/v9"
	_ "github.com/doug-martin/goqu/v9/dialect/sqlite3"
	goqusqlite3 "github.com/doug-martin/goqu/v9/dialect/sqlite3"
)

func TestPanic(t *testing.T) {
	conn := mustConn()
	defer conn.Close()

	db := goqu.New("sqlite3", conn)

	if _, err := db.Exec(`CREATE TABLE things(id INTEGER PRIMARY KEY AUTOINCREMENT, text TEXT)`); err != nil {
		panic(err)
	}

	if _, err := db.Insert("things").Rows(goqu.Record{"text": "hey"}).Returning("id").Executor().Exec(); err != nil {
		t.Fatal(err) // error: goqu: dialect does not support RETURNING clause [dialect=sqlite3]
	}
}

func TestWorkaround(t *testing.T) {
	conn := mustConn()
	defer conn.Close()

	opts := goqusqlite3.DialectOptions()
	opts.SupportsReturn = true
	goqu.RegisterDialect("sqlite_returning", opts)

	db := goqu.New("sqlite_returning", conn)
	if _, err := db.Exec(`CREATE TABLE things(id INTEGER PRIMARY KEY AUTOINCREMENT, text TEXT)`); err != nil {
		panic(err)
	}

	var id int64
	if _, err := db.Insert("things").Rows(goqu.Record{"text": "hey"}).Returning("id").Executor().ScanVal(&id); err != nil {
		panic(err)
	}
	if id == 0 {
		t.Error("RETURNING not working")
	}
}

func mustConn() *sql.DB {
	conn, err := sql.Open("sqlite", ":memory:")
	if err != nil {
		panic(err)
	}
	return conn
}

```

**Expected behavior**
I'd expect `sqlite3` dialect to allow using `RETURNING` clauses.

**Dialect:**

- [ ] postgres 
- [ ] mysql
- [x] sqlite3 



Discussion:

Patch:
diff --git a/dialect/sqlite3/sqlite3.go b/dialect/sqlite3/sqlite3.go
index 40ddb2a5..48d434f2 100644
--- a/dialect/sqlite3/sqlite3.go
+++ b/dialect/sqlite3/sqlite3.go
@@ -10,7 +10,7 @@ import (
 func DialectOptions() *goqu.SQLDialectOptions {
 	opts := goqu.DefaultDialectOptions()
 
-	opts.SupportsReturn = false
+	opts.SupportsReturn = true
 	opts.SupportsOrderByOnUpdate = true
 	opts.SupportsLimitOnUpdate = true
 	opts.SupportsOrderByOnDelete = true


Test patch:
diff --git a/dialect/sqlite3/sqlite3_test.go b/dialect/sqlite3/sqlite3_test.go
index d0b97188..7a229ec6 100644
--- a/dialect/sqlite3/sqlite3_test.go
+++ b/dialect/sqlite3/sqlite3_test.go
@@ -6,10 +6,11 @@ import (
 	"testing"
 	"time"
 
+	_ "github.com/mattn/go-sqlite3"
+
 	"github.com/doug-martin/goqu/v9"
 	"github.com/doug-martin/goqu/v9/dialect/mysql"
 	"github.com/doug-martin/goqu/v9/dialect/sqlite3"
-	_ "github.com/mattn/go-sqlite3"
 
 	"github.com/stretchr/testify/suite"
 )
@@ -362,13 +363,13 @@ func (st *sqlite3Suite) TestUpdateReturning() {
 	ds := st.db.From("entry")
 	var id uint32
 	_, err := ds.
-		Where(goqu.C("int").Eq(11)).
+		Where(goqu.C("id").Eq(1)).
 		Update().
-		Set(map[string]interface{}{"int": 9}).
+		Set(goqu.Record{"int": 11}).
 		Returning("id").
 		Executor().ScanVal(&id)
-	st.Error(err)
-	st.EqualError(err, "goqu: dialect does not support RETURNING clause [dialect=sqlite3]")
+	st.NoError(err)
+	st.GreaterOrEqual(id, uint32(0))
 }
 
 func (st *sqlite3Suite) TestDelete() {
@@ -397,7 +398,8 @@ func (st *sqlite3Suite) TestDelete() {
 
 	id = 0
 	_, err = ds.Where(goqu.C("id").Eq(e.ID)).Delete().Returning("id").Executor().ScanVal(&id)
-	st.EqualError(err, "goqu: dialect does not support RETURNING clause [dialect=sqlite3]")
+	st.NoError(err)
+	st.GreaterOrEqual(id, uint32(0))
 }
 
 func (st *sqlite3Suite) TestInsert_OnConflict() {