1

Install

Add the Turso package to your Go project:
go get github.com/tursodatabase/turso-go
go install github.com/tursodatabase/turso-go
2

Connect

Here’s how you can connect to a local SQLite database:
package main

import (
    "database/sql"
    "fmt"
    _ "github.com/tursodatabase/turso-go"
)

func main() {
    conn, _ := sql.Open("turso", "sqlite.db")
    defer conn.Close()
}
3

Create table

Create a table for users:
_, err := conn.Exec(`
  CREATE TABLE IF NOT EXISTS users (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    username TEXT NOT NULL
  )
`)
if err != nil {
    panic(err)
}
4

Insert data

Insert some data into the users table:
_, err = conn.Exec("INSERT INTO users (username) VALUES (?)", "alice")
if err != nil {
    panic(err)
}

_, err = conn.Exec("INSERT INTO users (username) VALUES (?)", "bob")
if err != nil {
    panic(err)
}
5

Query data

Query all users from the table:
stmt, _ := conn.Prepare("SELECT * FROM users")
defer stmt.Close()

rows, _ := stmt.Query()
for rows.Next() {
    var id int
    var username string
    _ = rows.Scan(&id, &username)
    fmt.Printf("User: ID: %d, Username: %s\n", id, username)
}