Documentation IndexFetch the complete documentation index at: /llms.txtUse this file to discover all available pages before exploring further.
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Install
go get turso.tech/database/tursogo
Connect
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() }
Create table
_, err = db.Exec(` CREATE TABLE IF NOT EXISTS users ( id INTEGER PRIMARY KEY AUTOINCREMENT, username TEXT NOT NULL ) `) if err != nil { panic(err) }
Insert data
_, 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) }
Query data
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) }
Was this page helpful?