|
|
12 роки тому | |
|---|---|---|
| uuid | 13 роки тому | |
| AUTHORS | 12 роки тому | |
| LICENSE | 13 роки тому | |
| README.md | 12 роки тому | |
| cluster.go | 12 роки тому | |
| conn.go | 12 роки тому | |
| doc.go | 12 роки тому | |
| frame.go | 12 роки тому | |
| gocql.go | 12 роки тому | |
| gocql_test.go | 12 роки тому | |
| marshal.go | 12 роки тому | |
| marshal_test.go | 12 роки тому | |
| session.go | 12 роки тому | |
| topology.go | 12 роки тому |
Package gocql implements a fast and robust Cassandra driver for the Go programming language.
go get github.com/tux21b/gocql
package main
import (
"fmt"
"github.com/tux21b/gocql"
"log"
)
func main() {
// connect to your cluster
db := gocql.NewSession(gocql.Config{
Nodes: []string{
"192.168.1.1",
"192.168.1.2",
"192.168.1.3",
},
Keyspace: "example", // (optional)
Consistency: gocql.ConQuorum, // (optional)
})
defer db.Close()
// simple query
var title, text string
if err := db.Query("SELECT title, text FROM posts WHERE title = ?",
"Lorem Ipsum").Scan(&title, &text); err != nil {
log.Fatal(err)
}
fmt.Println(title, text)
// iterator example
var titles []string
iter := db.Query("SELECT title FROM posts").Iter()
for iter.Scan(&title) {
titles = append(titles, title)
}
if err := iter.Close(); err != nil {
log.Fatal(err)
}
fmt.Println(titles)
// insertion example (with custom consistency level)
if err := db.Query("INSERT INTO posts (title, text) VALUES (?, ?)",
"New Title", "foobar").Consistency(gocql.ConAny).Exec(); err != nil {
log.Fatal(err)
}
// prepared queries
query := gocql.NewQuery("SELECT text FROM posts WHERE title = ?")
if err := db.Do(query, "New Title").Scan(&text); err != nil {
log.Fatal(err)
}
fmt.Println(text)
}
Copyright (c) 2012 The gocql Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.