Skip to content

Commit

Permalink
DB implementation for binding store
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandros Filios <[email protected]>
  • Loading branch information
alexandrosfilios committed Jan 16, 2025
1 parent 71b53d8 commit c2fd98e
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions platform/view/services/db/driver/sql/common/binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
Expand Down

0 comments on commit c2fd98e

Please sign in to comment.