Skip to content
Snippets Groups Projects
Commit 75127a78663e authored by Christophe de Vienne's avatar Christophe de Vienne
Browse files

Add database.InsertReturningNoPKey

parent dafdd8181250
No related branches found
No related tags found
No related merge requests found
Pipeline #121324 failed
......@@ -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.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment