From 5e2e1b3ac3739a8060435ae9e469d0626aff8ce3 Mon Sep 17 00:00:00 2001 From: RuteSantos <1160663@isep.ipp.pt> Date: Mon, 23 Jan 2023 22:24:20 +0000 Subject: [PATCH] return leak id in the insert --- pkg/database/database.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pkg/database/database.go b/pkg/database/database.go index 253769e..8068975 100644 --- a/pkg/database/database.go +++ b/pkg/database/database.go @@ -55,7 +55,7 @@ func (ctx DatabaseContext[R]) NewTransactionContext() (TransactionContext[R], er return TransactionContext[R]{Tx: tx}, err } -func (ctx DatabaseContext[Record]) Insert(i Import) error { +func (ctx DatabaseContext[Record]) Insert(i Import) (AutoGenKey, error) { var tx *sql.Tx @@ -75,6 +75,8 @@ func (ctx DatabaseContext[Record]) Insert(i Import) error { } }() + var leakId AutoGenKey + func() { us := make([]User, len(i.AffectedUsers)) cr := make([]Credentials, len(i.AffectedUsers)) @@ -125,6 +127,7 @@ func (ctx DatabaseContext[Record]) Insert(i Import) error { ps := pts[4].(PrimaryTable[Platform]).Records l := ls[0] + leakId = l.LeakId afu := map[User]Credentials{} for k := range us { @@ -166,7 +169,7 @@ func (ctx DatabaseContext[Record]) Insert(i Import) error { err = tx.Commit() } - return err + return leakId, err } func (ctx DatabaseContext[Record]) InsertSubscription(s Subscription) error {