---
title: "Connect an application"
url: "https://docs.yugabyte.com/stable/develop/drivers-orms/ruby/ycql/"
---

# Connect an application

Connect an application using YugabyteDB Ruby driver for YCQL

- [YSQL](/stable/develop/drivers-orms/ruby/yb-ruby-pg/)
- [YCQL](/stable/develop/drivers-orms/ruby/ycql/)

<!--THE END-->

- [YugabyteDB Ruby Driver](/stable/develop/drivers-orms/ruby/ycql/)

[Yugabyte Ruby Driver for YCQL](https://github.com/yugabyte/cassandra-ruby-driver "Yugabyte Ruby Driver for YCQL") is based on [DataStax Ruby Driver](https://github.com/datastax/ruby-driver "DataStax Ruby Driver") with additional [smart driver](/stable/develop/drivers-orms/smart-drivers-ycql/ "smart driver") features.

YugabyteDB Aeon

To use the driver's partition-aware load balancing feature in a YugabyteDB Aeon cluster, applications must be deployed in a VPC that has been peered with the cluster VPC so that they have access to all nodes in the cluster. For more information, refer to [Using YCQL drivers with YugabyteDB Aeon](/stable/develop/drivers-orms/smart-drivers-ycql/#using-ycql-drivers-with-yugabytedb-aeon "Using YCQL drivers with YugabyteDB Aeon").

## Install the YugabyteDB Ruby Driver for YCQL

To install the [YugabyteDB Ruby Driver for YCQL](https://github.com/yugabyte/cassandra-ruby-driver "YugabyteDB Ruby Driver for YCQL"), run the following `gem install` command:

```sh
$ gem install yugabyte-ycql-driver
```

## Create a sample Ruby application

Create a file `yb-ycql-helloworld.rb` and copy the following content to it.

```ruby
require 'ycql'

# Create the cluster connection, connects to localhost by default.
cluster = Cassandra.cluster
session = cluster.connect()

# Create the keyspace.
session.execute('CREATE KEYSPACE IF NOT EXISTS ybdemo;')
puts "Created keyspace ybdemo"

# Create the table.
session.execute(
  """
  CREATE TABLE IF NOT EXISTS ybdemo.employee (id int PRIMARY KEY,
                                              name varchar,
                                              age int,
                                              language varchar);
  """)
puts "Created table employee"

# Insert a row.
session.execute(
  """
  INSERT INTO ybdemo.employee (id, name, age, language)
  VALUES (1, 'John', 35, 'Ruby');
  """)
puts "Inserted (id, name, age, language) = (1, 'John', 35, 'Ruby')"

# Query the row.
rows = session.execute('SELECT name, age, language FROM ybdemo.employee WHERE id = 1;')
rows.each do |row|
  puts "Query returned: %s %s %s" % [ row['name'], row['age'], row['language'] ]
end

# Close the connection.
cluster.close()
```

## Run the application

To use the application, run the following command:

```sh
$ ruby yb-cql-helloworld.rb
```

You should see the following output.

```output
Created keyspace ybdemo
Created table employee
Inserted (id, name, age, language) = (1, 'John', 35, 'Ruby')
Query returned: John 35 Ruby
```
