Skip to content

Latest commit

 

History

History
131 lines (103 loc) · 3.72 KB

README.md

File metadata and controls

131 lines (103 loc) · 3.72 KB

libSQL Go

libSQL Go

Databases for Go multi-tenant AI Apps.

Turso · Docs · Quickstart · SDK Reference · Blog & Tutorials

MIT License Discord Contributors Examples

Features

Warning

This SDK is currently in technical preview. Join us in Discord to report any issues.

Install

go get github.com/tursodatabase/go-libsql

Note

If you require a remote only, no-CGO Go libSQL driver, see libsql-client-go.

Note

Currently only linux amd64, linux arm64, darwin amd64 and darwin arm64 are supported.

Quickstart

The example below uses Embedded Replicas and syncs data every one minute from Turso.

package main

import (
  "database/sql"
  "fmt"
  "os"
  "path/filepath"

  "github.com/tursodatabase/go-libsql"
)

func main() {
    dbName := "local.db"
    primaryUrl := "TURSO_DATABASE_URL"
    authToken := "TURSO_AUTH_TOKEN"
    syncInterval := time.Minute

    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),
        libsql.WithSyncInterval(syncInterval),
    )
    if err != nil {
        fmt.Println("Error creating connector:", err)
        os.Exit(1)
    }
    defer connector.Close()

    db := sql.OpenDB(connector)
    defer db.Close()
}

Documentation

Visit our official documentation.

Support

Join us on Discord to get help using this SDK. Report security issues via email.

Contributors

See the contributing guide to learn how to get involved.

Contributors

good first issue