From 3e921ab43f680a7a6e4f6306868d9f21566cd33f Mon Sep 17 00:00:00 2001 From: Abdussamet Kocak Date: Mon, 26 Sep 2022 09:38:09 +0300 Subject: [PATCH] fix: Update sqlite dialect to allow RETURNING clauses --- dialect/sqlite3/sqlite3.go | 2 +- dialect/sqlite3/sqlite3_test.go | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) 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 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() {