diff --git a/database/sql_helper.go b/database/sql_helper.go index dafdd8181250992287324bb47411329e29f2a10e_ZGF0YWJhc2Uvc3FsX2hlbHBlci5nbw==..75127a78663ed955fe5507adcb9d77a6336ce88c_ZGF0YWJhc2Uvc3FsX2hlbHBlci5nbw== 100644 --- a/database/sql_helper.go +++ b/database/sql_helper.go @@ -136,7 +136,14 @@ return h.Exec(query) } -// InsertReturning inserts instances and select the result +// InsertNoPKey inserts a Mapped into the db. +func (h *SQLHelper) InsertNoPKey(instances ...Mapped) (sql.Result, error) { + query := SQLInsertNoPKey(instances...) + + return h.Exec(query) +} + +// InsertReturning inserts instances and select the result. func (h *SQLHelper) InsertReturning(tgt interface{}, instances ...Mapped) error { if len(instances) == 0 { return nil @@ -146,6 +153,7 @@ if len(instances) == 1 { return h.Get(tgt, query) } + return h.Select(tgt, query) } @@ -149,7 +157,14 @@ return h.Select(tgt, query) } -// InsertNoPKey inserts a Mapped into the db. -func (h *SQLHelper) InsertNoPKey(instances ...Mapped) (sql.Result, error) { - query := SQLInsertNoPKey(instances...) +// InsertReturningNoPKey inserts instances and select the result. +func (h *SQLHelper) InsertReturningNoPKey(tgt interface{}, instances ...Mapped) error { + if len(instances) == 0 { + return nil + } + query := SQLInsertNoPKey(instances...). + Suffix("RETURNING " + strings.Join(instances[0].Columns(true), ", ")) + if len(instances) == 1 { + return h.Get(tgt, query) + } @@ -155,5 +170,5 @@ - return h.Exec(query) + return h.Select(tgt, query) } // Upsert upserts a Mapped into the db.