From a3cea488e65735943aa9d2589dc93e5511e82655 Mon Sep 17 00:00:00 2001 From: Sabbir Date: Thu, 17 Oct 2024 13:10:49 +0600 Subject: [PATCH] Remove Cassandra Data Delete Operation Signed-off-by: Sabbir --- cassandra/client.go | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/cassandra/client.go b/cassandra/client.go index bd6ce3c0..7e9f2e71 100644 --- a/cassandra/client.go +++ b/cassandra/client.go @@ -3,6 +3,7 @@ package cassandra import ( "fmt" "log" + "time" "k8s.io/klog/v2" health "kmodules.xyz/client-go/tools/healthchecker" @@ -27,18 +28,19 @@ func (c *Client) CreateTable() error { )`).Exec() } -// InsertUser inserts a user into the table -func (c *Client) InsertUser(name string, product string) error { - return c.Query(`INSERT INTO test_keyspace.test_table ( name, product) VALUES (?, ?)`, - name, product).Exec() -} +// UpdateData updates a record in the table +func (c *Client) UpdateData(name string, product string) error { + currentTime := time.Now().Format("2006-01-02 15:04:05") // Format as "YYYY-MM-DD HH:MM:SS" + + // Merge current time with product + updatedProduct := fmt.Sprintf("%s - %s", product, currentTime) -func (c *Client) DeleteUser(name string) error { - return c.Query(`DELETE FROM test_keyspace.test_table WHERE name = ?`, name).Exec() + return c.Query(`UPDATE test_keyspace.test_table SET name = ?, product = ? `, + name, updatedProduct).Exec() } -// queries a user by ID -func (c *Client) QueryUser(name string) error { +// queries a Data by ID +func (c *Client) QueryData(name string) error { var product string iter := c.Query(`SELECT product FROM test_keyspace.test_table WHERE name = ?`, name).Iter() @@ -58,17 +60,16 @@ func (c *Client) CheckDbReadWrite() error { if err := c.CreateTable(); err != nil { log.Fatal("Unable to create table:", err) } - if err := c.InsertUser("Appscode", "KubeDB"); err != nil { - log.Fatal("Unable to insert data:", err) + if err := c.UpdateData("Appscode", "KubeDB"); err != nil { + log.Println("Unable to update data:", err) } - err := c.QueryUser("Appscode") + err := c.QueryData("Appscode") if err != nil { return err } klog.Infoln("DB Read Write Successful") - err = c.DeleteUser("Appscode") - return err + return nil } func (c *Client) PingCassandra() error {