Coder Social home page Coder Social logo

scylladb-and-go's Introduction

ScyllaDB and Go

Using ScyllaDB with Go.

➡️ 👷🚧 Under Construction...

Technologies

goclq

gocql is the driver to use ScyllaDB with Golang.

goclqx

gocqlx is a wrapper for gocql that provides developer productivity without sacrificing performance.

Installation

Firstly, be sure to have both Docker, Docker Compose and Golang installed.

Git clone this repository:

git clone https://github.com/Guilospanck/scylladb-and-go.git

Change directory into it:

cd scylladb-and-go/

Then put Scylla cluster UP by using docker-compose:

# docker compose v1
sudo docker-compose -f docker-compose.yml up -d --build

# docker compose v2
sudo docker compose -f docker-compose.yml up -d --build

After some time (may take really some time, like 5min total) you'll be able to have a Scylla cluster up and running. To verify that:

sudo docker exec -it scylla-node1 nodetool status

You should see something like:

Sometimes you may see some error like "Could not connect. Connection refused". In order to change that, do:

sudo nano /etc/sysctl.conf

# Then add this line at the end of the file
fs.aio-max-nr = 1048576

# save it and to activate the config
sudo sysctl -p /etc/sysctl.conf

# after that, kill the containers and put them up again:
sudo docker-compose kill
sudo docker-compose rm -f
sudo docker-compose -f docker-compose.yml up -d --build

How to use the application

Once you have all the above section setted up, follow this one.

Running the Go HTTPS server

Change directory into the project directory

cd scylladb-and-go/

And then run

go run .

Queries

Using gocqlx to create our queries we have the following:

type T any

type IQueryBuilder[t T] interface {
	Insert(insertData *t) error
	Delete(dataToBeDeleted *t) error
	DeleteAllFromPartitioningKey(dataToBeDeleted *t) error
	Select(dataToGet *t) ([]t, error)
	Get(dataToGet *t) ([]t, error)
	SelectAll() ([]t, error)
}
  • Insert: will insert a new item into the database
  • Delete: will delete an item based on the Primary Key (Partitioning Key + Clustering Key)
  • DeleteAllFromPartitioningKey: will delete an item based on the Partitioning Key
  • Select: will return data based on the Partitioning Key
  • Get: will return data based on the Primary Key (PK + CK)
  • SelectAll: will return all data from table

Making requests

You can use either the simple curl function or the Insomnia program.

If using Insomnia, be sure to go to Applications > Preferences and then uncheck "Validate certificates" under "Request/Response" section. This is needed in order to make requests to the HTTPS localhost. To make requests from Edge, navigate to edge://flags/#allow-insecure-localhost and allow it.

POST /api/v1/tracking

Endpoint used to insert tracking data.

➡️ Request

  • curl
    curl --location --request POST 'https://localhost:4444/api/v1/tracking' \
    --header 'Content-Type: application/json' \
    --data-raw '{
        "firstName": "Post",
        "lastName": "Test",
        "timestamp": "2022-04-10 09:10:00 +0000 UTC",
        "location": "Brazil",
        "speed": 10,
        "heat": 25,
        "telepathyPowers": 222
    }'
  • Insomnia: run Insert tracking data

DELETE /api/v1/tracking

Endpoint used to delete tracking data by Primary Key (Partition Key + Clustering Key).

➡️ Request

  • curl
    curl --location --request DELETE 'https://localhost:4444/api/v1/tracking' \
    --header 'Content-Type: application/json' \
    --data-raw '{
        "firstName": "Post",
        "lastName": "Test",
        "timestamp": "2022-04-10 09:10:00 +0000 UTC"
    }'
  • Insomnia: run Delete tracking data by Primary Key

DELETE /api/v1/tracking/bypartition

Endpoint used to delete tracking data by Partition Key.

➡️ Request

  • curl
    curl --location --request DELETE 'https://localhost:4444/api/v1/tracking/bypartition' \
    --header 'Content-Type: application/json' \
    --data-raw '{
        "firstName": "Post",
        "lastName": "Test"
    }'
  • Insomnia: run Delete all tracking data by Partition Key

GET /api/v1/tracking

Endpoint used to get tracking data by Primary Key.

➡️ Request

  • curl
    curl --location --request GET 'https://localhost:4444/api/v1/tracking' \
    --header 'Content-Type: application/json' \
    --data-raw '{
        "firstName": "Post",
        "lastName": "Test",
        "timestamp": "2022-04-10 09:10:00 +0000 UTC"
    }'
  • Insomnia: run Get by Primary Key

GET /api/v1/tracking/bypartition

Endpoint used to get tracking data by Partition Key.

➡️ Request

  • curl
    curl --location --request GET 'https://localhost:4444/api/v1/tracking/bypartition' \
    --header 'Content-Type: application/json' \
    --data-raw '{
        "firstName": "Post",
        "lastName": "Test"
    }'
  • Insomnia: run Get All by Partition Key

GET /api/v1/tracking/all

Endpoint used to get all tracking data.

➡️ Request

  • curl
    curl --location --request GET 'https://localhost:4444/api/v1/tracking/all'
  • Insomnia: run Get All

scylladb-and-go's People

Contributors

guilospanck avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.