Go Cassandra – CRUD Example

Go Cassandra – CRUD Example

Using GoCQL driver, Go application connects with Cassandra database. In this example we will be creating CRUD application with the help of Go and Cassandra. To run this example you should have Cassandra instance running on your machine.  

Create keyspace and table in Cassandra

Create emps table in database using cql client. In this example, we have created Code2Succeed as a keyspace however you can use any other name.

Install GoCQL driver

To get GoCQL, use following command to install GoCQL driver

Database connection

We are going to create simple console application. So open any text editor and create a file db.go with Emp Struct and following methods
init() – contains code to establish connection with Cassandra database.
main() – contains code to run the application.

Create Employee

Create function createEmp to create a new row in emps table

Get All Employees

function to get All employees from database. We are using iterator with mapScan() to get all employees.

Update a Employee

Update a employee based on empid.

Delete a Employee

Delete employee using empid.

Main method to run the application



Download complete code Go Cassandra – CRUD Example

Stay tuned for more tutorials and examples !



One thought on “Go Cassandra – CRUD Example

  1. I think this is one of the most important info for me. And i am glad reading your article. But wanna remark on few general things, The web site style is ideal, the articles is really excellent D. Good job, cheers kkaaadbgbdfe

Leave a Reply to Johnc675 Cancel reply

Your email address will not be published. Required fields are marked *