Connect to TiDB Cloud Lake Using Golang
The official Go driver provides a standard database/sql interface for seamless integration with existing Go applications.
Installation
go get github.com/tidbcloud/lake-go
Connection String: See drivers overview for DSN format and examples.
Key Features
- ✅ Standard Interface: Full
database/sqlcompatibility - ✅ Connection Pooling: Built-in connection management
- ✅ Bulk Operations: Efficient batch inserts via transactions
- ✅ Type Safety: Comprehensive Go type mappings
Data Type Mappings
Basic Usage
import (
"database/sql"
"fmt"
"log"
_ "github.com/tidbcloud/lake-go"
)
// Connect to TiDB Cloud Lake
db, err := sql.Open("lake", "<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
- GitHub Repository: lake-go
- Examples: GitHub Examples