📣
TiDB Cloud Premium is now in public preview. Unlimited growth, instant elasticity, advanced security for enterprise workloads. Try it out →

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/sql compatibility
  • Connection Pooling: Built-in connection management
  • Bulk Operations: Efficient batch inserts via transactions
  • Type Safety: Comprehensive Go type mappings

Data Type Mappings

TiDB Cloud LakeGoNotes
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/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

Was this page helpful?