Skip to content

Commit

Permalink
Merge pull request #359 from abdusco/sqlite3-returning
Browse files Browse the repository at this point in the history
fix: Update sqlite dialect to allow RETURNING clauses
  • Loading branch information
funkyshu authored Dec 14, 2023
2 parents b4d7d0d + 3e921ab commit 7ff091d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion dialect/sqlite3/sqlite3.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 8 additions & 6 deletions dialect/sqlite3/sqlite3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 7ff091d

Please sign in to comment.