#2 Setting up the database

Let’s set up the database now. As I mentioned in the first post, we will use CassandraDB.

I followed the steps for the installation from the official documentation site. I don’t want to deal with docker at the moment therefore I installed the Tarball binary file.

After extracting the .tar.gz file we can cd into it and start the database.

$ cd apache-cassandra-4.1.4/ && bin/cassandra

Let’s connect to the database using cqlsh. It is a command-line interface for interacting with Cassandra.

$ bin/cqlsh

Now, we can create a keyspace for our project by typing the following query.

CREATE KEYSPACE channels_db WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'}

Here we are creating a keyspace named “channels_db”. A keyspace in Cassandra is akin to a database in traditional relational database systems.

After creating keyspace we can type use channels_db command to connect to our database.

Let’s create a user table inside the database with the following query.

CREATE TABLE users (
    user_id uuid PRIMARY KEY,
    bio text,
    created_at timestamp,
    email text,
    password text,
    username text
)

We can display all the tables in database with DESCRIBE tables query.

Now, that we have a database ready. We can connect to it from our HTTP Server.