scylladb / scylla-go-driver

Experimental, high performance Scylla Driver, University of Warsaw students' project
Apache License 2.0
151 stars 7 forks source link

Query Execution not working on docker scylla #299

Open sujit-baniya opened 1 year ago

sujit-baniya commented 1 year ago

Platform: Linux (Docker) App Language: Golang (non-Docker) I'm trying to use this driver for operations but got stuck on error

panic: node &{[220 47 239 56 226 129 69 100 158 115 200 137 86 16 55 196] 172.21.0.2 datacenter1 rack1 <nil> {[] {[] 0}}} is down

Code:

package main

import (
    "context"
    "fmt"

    "github.com/scylladb/scylla-go-driver"
)

func main() {
    var Keyspace = "go_demo1"
//  var Port = 9042
    var Host = "127.0.0.1"
    ctx := context.Background()
    cfg := scylla.DefaultSessionConfig(Keyspace, []string{Host}...)
    session, err := scylla.NewSession(ctx, cfg)
    if err != nil {
        panic(err)
    }
    defer session.Close()
    stmts := []string{
        "CREATE KEYSPACE IF NOT EXISTS go_demo1 WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 1}",
        "CREATE TABLE IF NOT EXISTS go_demo1.users (user_id int, fname text, lname text, PRIMARY KEY((user_id)))",
        "INSERT INTO go_demo1.users(user_id, fname, lname) VALUES (1, 'rick', 'sanchez')",
        "INSERT INTO go_demo1.users(user_id, fname, lname) VALUES (4, 'rust', 'cohle')",
    }

    for _, stmt := range stmts {
        q := session.Query(stmt)
        if _, err := q.Exec(ctx); err != nil {
            panic(err.Error())
        }
    }

    q := session.Query("SELECT * FROM go_demo1.users")

    res, err := q.Exec(ctx)
    if err != nil {
        panic(err)
    }

    for _, row := range res.Rows {
        pk, err := row[0].AsInt32()
        if err != nil {
            panic(err)
        }
        name, err := row[1].AsText()
        if err != nil {
            panic(err)
        }
        surname, err := row[2].AsText()
        if err != nil {
            panic(err)
        }
        fmt.Println(pk, name, surname)
    }
}

The driver is not respecting the exported port.