From fef874d9c8f7785a60faf7389b0366b0aefe6f1c Mon Sep 17 00:00:00 2001 From: Daniel Reis Date: Mon, 28 Oct 2024 13:50:13 -0300 Subject: [PATCH 1/2] docs: add data types and quick start --- README.md | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 82 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 75a8fc56b..ae27f0542 100644 --- a/README.md +++ b/README.md @@ -33,10 +33,12 @@ It also provides support for shard aware ports, a faster way to connect to all s - [1. Sunsetting Model](#1-sunsetting-model) - [2. Installation](#2-installation) -- [3. Configuration](#3-configuration) - - [3.1 Shard-aware port](#31-shard-aware-port) - - [3.2 Iterator](#32-iterator) -- [4. Contributing](#4-contributing) +- [3. Quick Start](#3-quick-start) +- [4. Data Types](#4-data-types) +- [5. Configuration](#5-configuration) + - [5.1 Shard-aware port](#51-shard-aware-port) + - [5.2 Iterator](#52-iterator) +- [6. Contributing](#6-contributing) ## 1. Sunsetting Model @@ -63,7 +65,79 @@ to evaluate `latest` to a concrete tag. Your project now uses the Scylla driver fork, make sure you are using the `TokenAwareHostPolicy` to enable the shard-awareness, continue reading for details. -## 3. Configuration +## 3. Quick Start + +Spawn a ScyllaDB Instance using Docker Run command: + +```sh +docker run --name node1 --network ws-scylla -p "9042:9042" -d scylladb/scylla:6.1.2 \ + --overprovisioned 1 \ + --smp 1 +``` + +Then, create a new connection using ScyllaDB GoCQL following the example below: + +```go +package main + +import ( + "fmt" + "github.com/gocql/gocql" +) + +func main() { + var cluster = gocql.NewCluster("localhost:9042") + + var session, err = cluster.CreateSession() + if err != nil { + panic("Failed to connect to cluster") + } + + defer session.Close() + + var query = session.Query("SELECT * FROM system.clients") + + if rows, err := query.Iter().SliceMap(); err == nil { + for _, row := range rows { + fmt.Printf("%v\n", row) + } + } else { + panic("Query error: " + err.Error()) + } +} +``` + +## 4. Data Types + +Here's an list of all ScyllaDB Types reflected in the GoCQL environment: + +| ScyllaDB Type | Go Type | +| ---------------- | ------------------ | +| `ascii` | `string` | +| `bigint` | `int64` | +| `blob` | `[]byte` | +| `boolean` | `bool` | +| `date` | `time.Time` | +| `decimal` | `inf.Dec` | +| `double` | `float64` | +| `duration` | `gocql.Duration` | +| `float` | `float32` | +| `uuid` | `gocql.UUID` | +| `int` | `int32` | +| `inet` | `string` | +| `list` | `[]int32` | +| `map` | `map[int32]string` | +| `set` | `[]int32` | +| `smallint` | `int16` | +| `text` | `string` | +| `time` | `time.Duration` | +| `timestamp` | `time.Time` | +| `timeuuid` | `gocql.UUID` | +| `tinyint` | `int8` | +| `varchar` | `string` | +| `varint` | `int64` | + +## 5. Configuration In order to make shard-awareness work, token aware host selection policy has to be enabled. Please make sure that the gocql configuration has `PoolConfig.HostSelectionPolicy` properly set like in the example below. @@ -89,7 +163,7 @@ if localDC != "" { // c.NumConns = 4 ``` -### 3.1 Shard-aware port +### 5.1 Shard-aware port This version of gocql supports a more robust method of establishing connection for each shard by using _shard aware port_ for native transport. It greatly reduces time and the number of connections needed to establish a connection per shard in some cases - ex. when many clients connect at once, or when there are non-shard-aware clients connected to the same cluster. @@ -136,7 +210,7 @@ Issues with shard-aware port not being reachable are not reported in non-debug m If you suspect that this feature is causing you problems, you can completely disable it by setting the `ClusterConfig.DisableShardAwarePort` flag to true. -### 3.2 Iterator +### 5.2 Iterator Paging is a way to parse large result sets in smaller chunks. The driver provides an iterator to simplify this process. @@ -163,6 +237,6 @@ In case of range and `ALLOW FILTERING` queries server can send empty responses f That is why you should never consider empty response as the end of the result set. Always check `iter.Scan()` result to know if there are more results, or `Iter.LastPage()` to know if the last page was reached. -## 4. Contributing +## 6. Contributing If you have any interest to be contributing in this GoCQL Fork, please read the [CONTRIBUTING.md](CONTRIBUTING.md) before initialize any Issue or Pull Request. From ca5af48d91a960a6f9362ea3840fe260fc94a38f Mon Sep 17 00:00:00 2001 From: Daniel Reis Date: Tue, 29 Oct 2024 11:58:55 -0300 Subject: [PATCH 2/2] docs: fix docker network name --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ae27f0542..62d8995f8 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ Your project now uses the Scylla driver fork, make sure you are using the `Token Spawn a ScyllaDB Instance using Docker Run command: ```sh -docker run --name node1 --network ws-scylla -p "9042:9042" -d scylladb/scylla:6.1.2 \ +docker run --name node1 --network your-network -p "9042:9042" -d scylladb/scylla:6.1.2 \ --overprovisioned 1 \ --smp 1 ```