Skip to content
VoltDB Golang Client Library
Go Python Makefile
Branch: master
Clone or download
benjaminballard Merge pull request #57 from basvanbeek/rows-next-result-set
adds implementation of driver.RowsNextResultSet interface
Latest commit 91d980e Jul 8, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples
tools ENG-13505: Update copyright to 2018 Jan 2, 2018
voltdbclient added compile time assertion for satisfying driver.Rows and driver.Ro… Jun 20, 2019
wire ENG-12854: Unreasonable memory usage of the Go driver in sync mode (#41) Jul 24, 2017
.gitignore ENG-12759: faster and better tested serialization implementation (#35) Jun 30, 2017
CONTRIBUTING.md add contributing guidelines Aug 8, 2017
LICENSE Initial commit May 10, 2016
Makefile fix voter benchmarks Jun 5, 2018
README.md Updated Required Go Version May 29, 2018

README.md

GoDoc

VoltDB Golang Client Library

The VoltDB golang client library implements the native VoltDB wire protocol. You can use the library to connect to a VoltDB cluster, invoke stored procedures and read responses.

Installation

go get -v -u github.com/VoltDB/voltdb-client-go/voltdbclient

Requirements

Recommend version:
go version >= 1.9

Usage

As database/sql driver

package main

import (
	"database/sql"
	"fmt"
	"log"
	"os"

	_ "github.com/VoltDB/voltdb-client-go/voltdbclient"
)

func main() {
	// If using a version of VoltDB server prior to 5.2, then
	// set the version of the wire protocol to 0.  The default
	// value 1, indicates a server version of 5.2 or later.
	// voltdbclient.ProtocolVersion = 0

	db, err := sql.Open("voltdb", "localhost:21212")
	if err != nil {
		log.Fatal(err)
	}
	defer db.Close()

	err = db.Ping()
	if err != nil {
		log.Fatal(err)
	}
	rows, err := db.Query("HELLOWORLD.select", "French")
	if err != nil {
		log.Fatal(err)
	}
	printRows(rows)

	// with prepared statement
	stmt, err := db.Prepare("select * from HELLOWORLD where dialect = ?")
	if err != nil {
		log.Fatal(err)
	}

	rows, err = stmt.Query("French")
	if err != nil {
		log.Fatal(err)
	}
	printRows(rows)

}

func printRows(rows *sql.Rows) {
	for rows.Next() {
		var hello string
		var world string
		var dialect string
		err := rows.Scan(&hello, &world, &dialect)
		if err != nil {
			fmt.Println(err)
			break
		}
		fmt.Printf("SUCCESS: %s %s %s\n", hello, world, dialect)
	}
}

Client API

The VoltDB golang client implements the interfaces specified in the database/sql/driver package. The interfaces specified by database/sql/driver are typically used to implement a driver to be used with the golang database/sql package.

The code here can be used as a driver in this manner; it can also be used as a stand alone client.

The VoltDB golang client supports a VoltDB specific asynchronous api in addition to the database/sql/driver api. The VoltDB api also includes column accessors for VoltDB specific types. The details of the VoltDB api can be found in the godoc.

Examples

The VoltDB golang client includes three examples. There is a simple hello world example and a similar example that uses the asynchronous api. There is also an example that uses the client with the database/sql/driver api only.

Wire Protocol

By default, version 1 of the VoltDB wire protocol is used; this is suitable for VoltDB server version 5.2 or later. Set the wire protocol version to 0 for use with an older server. See the 'driver_hello_world' example.

FAQ

How do I manage connection pools?

When using database/sql driver, connection pools are automatically managed for you. However there is a couple of options offered for custom control such as SetConnMaxLifetime, SetMaxIdleConns and SetMaxOpenConns

Micro benchmarks

When doing development on this client, before adding new changes first you need to run benchmarks of the client . We have included helper make rules for this just run make bench-old which when done will create old.bench file on the root of the project.

You can then go ahead and make the changes, when done you need to run benchmarks with the new changes by running make bench-new which will create new.bench.

Compare the two benchmarks with make benchcmp. This will help you to see if there were any regressions introduced by the changes. This rule depends on benchcmp tool to be installed, if that tool is missing run make deps to install it.

You can’t perform that action at this time.