From 301ecec814c1a5f08358c2a93ead75a6a31f9298 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Wed, 2 Jun 2021 18:50:17 +0100 Subject: [PATCH] . (#137) * [WIP] DB service * F * F * F * F * F * F * F * F * F * F * F * F * F * F * F * F * F * F * F * F * F * F * F * F * fixup db and return id in create response * add delete method and some error checking * Add the update method * fix panic * use record for the data field Co-authored-by: Janos Dobronszki --- db/handler/db.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/db/handler/db.go b/db/handler/db.go index 623736c..95477b5 100644 --- a/db/handler/db.go +++ b/db/handler/db.go @@ -71,14 +71,17 @@ func (e *Db) Update(ctx context.Context, req *db.UpdateRequest, rsp *db.UpdateRe return err } + // do we really need to remarshal this? + data, _ := json.Marshal(m) + // where ID is specified do a single update record update if id, ok := m["ID"].(string); ok { // apply the update to a single record - return db.Table(req.Table).First(&Record{ID: id}).Updates(m).Error + return db.Table(req.Table).First(&Record{ID: id}).Updates(Record{Data: data}).Error } // apply all the updates - return db.Table(req.Table).Updates(m).Error + return db.Table(req.Table).Updates(Record{Data: data}).Error } func (e *Db) Read(ctx context.Context, req *db.ReadRequest, rsp *db.ReadResponse) error {