Skip to main content

Go Driver for Databend

The official Go driver providing a standard database/sql interface for seamless integration with existing Go applications.

Installation

go get github.com/databendlabs/databend-go

Connection String: See Drivers Overview for DSN format and connection examples.


Key Features

  • Standard Interface: Full database/sql compatibility
  • Connection Pooling: Built-in connection management
  • Bulk Operations: Efficient batch inserts via transactions
  • Type Safety: Comprehensive Go type mappings

Data Type Mappings

DatabendGoNotes
Integers
TINYINTint8
SMALLINTint16
INTint32
BIGINTint64
TINYINT UNSIGNEDuint8
SMALLINT UNSIGNEDuint16
INT UNSIGNEDuint32
BIGINT UNSIGNEDuint64
Floating Point
FLOATfloat32
DOUBLEfloat64
Other Types
DECIMALdecimal.DecimalRequires decimal package
STRINGstring
DATEtime.Time
TIMESTAMPtime.Time
ARRAY(T)stringJSON encoded
TUPLE(...)stringJSON encoded
VARIANTstringJSON encoded
BITMAPstringBase64 encoded

Basic Usage

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

_ "github.com/databendlabs/databend-go"
)

// Connect to Databend
db, err := sql.Open("databend", "<your-dsn>")
if err != nil {
log.Fatal(err)
}
defer db.Close()

// DDL: Create table
_, err = db.Exec("CREATE TABLE users (id INT, name STRING)")
if err != nil {
log.Fatal(err)
}

// Write: Insert data
_, err = db.Exec("INSERT INTO users VALUES (?, ?)", 1, "Alice")
if err != nil {
log.Fatal(err)
}

// Query: Select data
var id int
var name string
err = db.QueryRow("SELECT id, name FROM users WHERE id = ?", 1).Scan(&id, &name)
if err != nil {
log.Fatal(err)
}

fmt.Printf("User: %d, %s\n", id, name)

Resources

Explore Databend Cloud for FREE
Low-cost
Fast Analytics
Easy Data Ingestion
Elastic Scaling
Try it today