W↓
All docs
🔑
Sign Up/Sign In
docs.turso.tech/sdk/go/
Public Link
Apr 6, 2025, 5:08:19 PM - complete - 4 kB
Created by:
****ad@vlad.studio
Starting URLs:
https://docs.turso.tech/sdk/go/
## Page: https://docs.turso.tech/sdk/go/ package main import ( "database/sql" "fmt" "os" "path/filepath" "github.com/tursodatabase/go-libsql" ) func main() { dbName := "local.db" primaryUrl := "libsql://[DATABASE].turso.io" authToken := "..." dir, err := os.MkdirTemp("", "libsql-*") if err != nil { fmt.Println("Error creating temporary directory:", err) os.Exit(1) } defer os.RemoveAll(dir) dbPath := filepath.Join(dir, dbName) connector, err := libsql.NewEmbeddedReplicaConnector(dbPath, primaryUrl, libsql.WithAuthToken(authToken), ) if err != nil { fmt.Println("Error creating connector:", err) os.Exit(1) } defer connector.Close() db := sql.OpenDB(connector) defer db.Close() } --- ## Page: https://docs.turso.tech/sdk/go/quickstart package main import ( "database/sql" "fmt" "os" "path/filepath" "github.com/tursodatabase/go-libsql" ) func main() { dbName := "local.db" primaryUrl := "libsql://[DATABASE].turso.io" authToken := "..." dir, err := os.MkdirTemp("", "libsql-*") if err != nil { fmt.Println("Error creating temporary directory:", err) os.Exit(1) } defer os.RemoveAll(dir) dbPath := filepath.Join(dir, dbName) connector, err := libsql.NewEmbeddedReplicaConnector(dbPath, primaryUrl, libsql.WithAuthToken(authToken), ) if err != nil { fmt.Println("Error creating connector:", err) os.Exit(1) } defer connector.Close() db := sql.OpenDB(connector) defer db.Close() } --- ## Page: https://docs.turso.tech/sdk/go/reference ## Embedded Replicas You can work with embedded replicas that can sync from the remote database to a local SQLite file, and delegate writes to the remote primary database: ### Manual Sync The `Sync` function allows you to sync manually the local database with the remote counterpart: ### Periodic Sync You can automatically sync at intervals using `WithSyncInterval` and passing a `time.Duration` as an argument. For example, to sync every minute, you can use the following code: ### Read Your Writes By default, the database connection ensures that writes are immediately visible to subsequent read operations initiated by the same connection. You can disable this behaviour using `WithReadYourWrites(false)`: ## Encryption To enable encryption on a SQLite file, pass the encryption key value as an argument to the constructor: --- ## Page: https://docs.turso.tech/sdk/go/examples * * GitHub Copilot Write better code with AI * GitHub Advanced Security Find and fix vulnerabilities * Actions Automate any workflow * Codespaces Instant dev environments * Issues Plan and track work * Code Review Manage code changes * Discussions Collaborate outside of code * Code Search Find more, search less * Explore * Learning Pathways * Events & Webinars * Ebooks & Whitepapers * Customer Stories * Partners * Executive Insights * * GitHub Sponsors Fund open source developers * The ReadME Project GitHub community articles * * Enterprise platform AI-powered developer platform * Pricing ## Provide feedback ## Saved searches ## Use saved searches to filter your results more quickly Sign up