From c2fd98e43e61f66d91293c2c806b3cb32c233c85 Mon Sep 17 00:00:00 2001 From: Alexandros Filios Date: Thu, 16 Jan 2025 17:24:21 +0100 Subject: [PATCH] DB implementation for binding store Signed-off-by: Alexandros Filios --- .../services/db/driver/sql/common/binding.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/platform/view/services/db/driver/sql/common/binding.go b/platform/view/services/db/driver/sql/common/binding.go index 09597fced..24e474ee2 100644 --- a/platform/view/services/db/driver/sql/common/binding.go +++ b/platform/view/services/db/driver/sql/common/binding.go @@ -70,9 +70,9 @@ func (db *BindingPersistence) HaveSameBinding(this, that view.Identity) (bool, e func (db *BindingPersistence) PutBinding(ephemeral, longTerm view.Identity) error { query := fmt.Sprintf( "INSERT INTO %s (ephemeral_hash, long_term_id) "+ - "SELECT ($1, long_term_id) FROM %s WHERE ephemeral_hash=$2", - db.table, db.table) - result, err := db.writeDB.Exec(query, ephemeral.UniqueID(), longTerm.UniqueID()) + "SELECT '%s', long_term_id FROM %s WHERE ephemeral_hash=$1", + db.table, ephemeral.UniqueID(), db.table) + result, err := db.writeDB.Exec(query, longTerm.UniqueID()) if err != nil { return errors.Wrapf(err, "failed executing query [%s]", query) } @@ -91,8 +91,16 @@ func (db *BindingPersistence) PutBinding(ephemeral, longTerm view.Identity) erro } logger.Debugf("Long term ID not seen before. Registering it as long term...") - query = fmt.Sprintf("INSERT INTO %s (ephemeral_hash, long_term_id) VALUES (($1, $2), ($3, $4))", db.table) - if _, err = db.writeDB.Exec(query, longTerm.UniqueID(), longTerm, ephemeral.UniqueID(), longTerm); err != nil { + //query = fmt.Sprintf("INSERT INTO %s (ephemeral_hash, long_term_id) VALUES ($1, $2), ($3, $4)", db.table) + //if _, err = db.writeDB.Exec(query, longTerm.UniqueID(), longTerm, ephemeral.UniqueID(), longTerm); err != nil { + // return errors.Wrapf(err, "failed inserting long-term id and ephemeral id") + //} + query = fmt.Sprintf("INSERT INTO %s (ephemeral_hash, long_term_id) VALUES ($1, $2)", db.table) + if _, err = db.writeDB.Exec(query, longTerm.UniqueID(), longTerm); err != nil { + return errors.Wrapf(err, "failed inserting long-term id and ephemeral id") + } + query = fmt.Sprintf("INSERT INTO %s (ephemeral_hash, long_term_id) VALUES ($1, $2)", db.table) + if _, err = db.writeDB.Exec(query, ephemeral.UniqueID(), longTerm); err != nil { return errors.Wrapf(err, "failed inserting long-term id and ephemeral id") } logger.Infof("Long-term and ephemeral ids registered [%s,%s]", longTerm, ephemeral)