diff --git a/.github/cover.png b/.github/cover.png new file mode 100644 index 0000000..9b16b75 Binary files /dev/null and b/.github/cover.png differ diff --git a/.gitignore b/.gitignore index 3b735ec..c03571e 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,5 @@ # Go workspace file go.work + +.DS_Store diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..d31ff35 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,17 @@ +# Contributor Manual + +Turso welcomes contributions from the community. This manual provides guidelines for contributing to `go-libsql` SDK. + +https://github.com/firstcontributions/first-contributions + +## Prerequisites + +## Development + +## Running Tests + +## License + +Unless you explicitly state otherwise, any contribution intentionally submitted +for inclusion in libSQL by you, shall be licensed as MIT, without any additional +terms or conditions. diff --git a/README.md b/README.md index 854f4eb..6cc895a 100644 --- a/README.md +++ b/README.md @@ -1,64 +1,131 @@ -# LibSQL package for Go - -[libSQL](https://github.com/tursodatabase/libsql) is an open source, open contribution fork of SQLite. -This source repository contains libSQL API bindings for Go. - -## Notice -This package comes with a precompiled native libraries. -Currently only `linux amd64`, `linux arm64`, `darwin amd64` and `darwin arm64` are supported. -We're working on adding support for more platforms. +

+ + + libSQL Go + + +

libSQL Go

+

+ +

+ Databases for Go multi-tenant AI Apps. +

+ +

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

+ +

+ + + MIT License + + + + + Discord + + + + + Contributors + + + + + Examples + + +

## Features -* In-memory databases and local database files, like SQLite -* Remote database access to libSQL server -* In-app replica that syncs with a libSQL server +- 🔌 Works offline with [Embedded Replicas](https://docs.turso.tech/features/embedded-replicas/introduction) +- 🌎 Works with remote Turso databases +- ✨ Works with Turso [AI & Vector Search](https://docs.turso.tech/features/ai-and-embeddings) +- 🐘 Works Go PDO -## Installing +> [!WARNING] +> This SDK is currently in technical preview. Join us in Discord to report any issues. -``` +## Install + +```bash go get github.com/tursodatabase/go-libsql ``` -`go-libsql` uses `CGO` to make calls to LibSQL. You must build your binaries with `CGO_ENABLED=1`. +> [!NOTE] +> If you require a remote only, no-CGO Go libSQL driver, see [`libsql-client-go`](https://github.com/tursodatabase/libsql-client-go). -## Getting Started +> [!NOTE] +> Currently only `linux amd64`, `linux arm64`, `darwin amd64` and `darwin arm64` are supported. -### Connecting to the database +## Quickstart -To connect to the database one needs to create a `libsql.Connector` using one of the factory functions: `libsql.NewEmbeddedReplicaConnector` or `libsql.NewEmbeddedReplicaConnectorWithAutoSync`. +The example below uses Embedded Replicas and syncs data every one minute from Turso. -Here's an example of obtaining a `sql.DB` object from `database/sql` package: +```go +package main -``` -dbPath := // Path do db file on local disk -primaryUrl := // URL to primary database instance -connector := NewEmbeddedReplicaConnector(dbPath, primaryUrl, authToken) -db := sql.OpenDB(connector) -defer db.Close() -``` +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 -Once `sql.DB` object is created one can use it as any other database that supports `database/sql` package. + dir, err := os.MkdirTemp("", "libsql-*") + if err != nil { + fmt.Println("Error creating temporary directory:", err) + os.Exit(1) + } + defer os.RemoveAll(dir) -### Fetching updates from primary database instance + dbPath := filepath.Join(dir, dbName) -If the connector is created with `libsql.NewEmbeddedReplicaConnectorWithAutoSync` then it will automatically fetch updates from a primary periodically. + 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() +} +``` -For connectors created with `libsql.NewEmbeddedReplicaConnector` we need to fetch updates manually by calling `connector.Sync` +## Documentation -## Examples +Visit our [official documentation](https://docs.turso.tech/sdk/go). -Module with usage examples can be found in [example directory]. +## Support -## License +Join us [on Discord](https://tur.so/discord-go) to get help using this SDK. Report security issues [via email](mailto:security@turso.tech). -This project is licensed under the [MIT license]. +## Contributors -### Contribution +See the [contributing guide](CONTRIBUTING.md) to learn how to get involved. -Unless you explicitly state otherwise, any contribution intentionally submitted -for inclusion in libSQL by you, shall be licensed as MIT, without any additional -terms or conditions. +![Contributors](https://contrib.nn.ci/api?repo=tursodatabase/go-libsql) -[MIT license]: https://github.com/tursodatabase/go-libsql/blob/main/LICENSE -[example directory]: https://github.com/tursodatabase/go-libsql/tree/main/example + + + good first issue + +