> ## Documentation Index
> Fetch the complete documentation index at: https://docs.turso.tech/llms.txt
> Use this file to discover all available pages before exploring further.

# Connect to Turso using Go

<Steps>
  <Step title="Install">
    Add the Turso package to your Go project:

    ```bash theme={null}
    go get turso.tech/database/tursogo
    ```
  </Step>

  <Step title="Connect">
    Here's how you can connect to a local SQLite database:

    ```go theme={null}
    package main

    import (
        "database/sql"
        "fmt"
        _ "turso.tech/database/tursogo"
    )

    func main() {
        db, err := sql.Open("turso", "sqlite.db")
        if err != nil {
            panic(err)
        }
        defer db.Close()
    }
    ```
  </Step>

  <Step title="Create table">
    Create a table for users:

    ```go theme={null}
    _, err = db.Exec(`
      CREATE TABLE IF NOT EXISTS users (
        id INTEGER PRIMARY KEY AUTOINCREMENT,
        username TEXT NOT NULL
      )
    `)
    if err != nil {
        panic(err)
    }
    ```
  </Step>

  <Step title="Insert data">
    Insert some data into the users table:

    ```go theme={null}
    _, err = db.Exec("INSERT INTO users (username) VALUES (?)", "alice")
    if err != nil {
        panic(err)
    }

    _, err = db.Exec("INSERT INTO users (username) VALUES (?)", "bob")
    if err != nil {
        panic(err)
    }
    ```
  </Step>

  <Step title="Query data">
    Query all users from the table:

    ```go theme={null}
    rows, err := db.Query("SELECT * FROM users")
    if err != nil {
        panic(err)
    }
    defer rows.Close()

    for rows.Next() {
        var id int
        var username string
        if err := rows.Scan(&id, &username); err != nil {
            panic(err)
        }
        fmt.Printf("User: ID: %d, Username: %s\n", id, username)
    }
    ```
  </Step>
</Steps>
