Skip to content

Commit

Permalink
Remove Cassandra Data Delete Operation
Browse files Browse the repository at this point in the history
Signed-off-by: Sabbir <sabbir@appscode.com>
  • Loading branch information
sabbir-hossain70 committed Oct 17, 2024
1 parent be4d6c8 commit a3cea48
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions cassandra/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cassandra
import (
"fmt"
"log"
"time"

"k8s.io/klog/v2"
health "kmodules.xyz/client-go/tools/healthchecker"
Expand All @@ -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()
Expand All @@ -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 {
Expand Down

0 comments on commit a3cea48

Please sign in to comment.