Skip to content

docs(readme): update readme and contributing guide #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .github/cover.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@

# Go workspace file
go.work

.DS_Store
17 changes: 17 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -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.
147 changes: 107 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
<p align="center">
<a href="https://tur.so/turso-go">
<picture>
<img src="/.github/cover.png" alt="libSQL Go" />
</picture>
</a>
<h1 align="center">libSQL Go</h1>
</p>

<p align="center">
Databases for Go multi-tenant AI Apps.
</p>

<p align="center">
<a href="https://tur.so/turso-go"><strong>Turso</strong></a> ·
<a href="https://docs.turso.tech"><strong>Docs</strong></a> ·
<a href="https://docs.turso.tech/sdk/go/quickstart"><strong>Quickstart</strong></a> ·
<a href="https://docs.turso.tech/sdk/go/reference"><strong>SDK Reference</strong></a> ·
<a href="https://turso.tech/blog"><strong>Blog &amp; Tutorials</strong></a>
</p>

<p align="center">
<a href="LICENSE">
<picture>
<img src="https://img.shields.io/github/license/tursodatabase/go-libsql?color=0F624B" alt="MIT License" />
</picture>
</a>
<a href="https://tur.so/discord-go">
<picture>
<img src="https://img.shields.io/discord/933071162680958986?color=0F624B" alt="Discord" />
</picture>
</a>
<a href="#contributors">
<picture>
<img src="https://img.shields.io/github/contributors/tursodatabase/go-libsql?color=0F624B" alt="Contributors" />
</picture>
</a>
<a href="/examples">
<picture>
<img src="https://img.shields.io/badge/browse-examples-0F624B" alt="Examples" />
</picture>
</a>
</p>

## 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. <a href="https://tur.so/discord-go">Join us in Discord</a> 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:[email protected]).

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
<a href="https://github.com/tursodatabase/go-libsql/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22">
<picture>
<img src="https://img.shields.io/github/issues-search/tursodatabase/go-libsql?label=good%20first%20issue&query=label%3A%22good%20first%20issue%22%20&color=0F624B" alt="good first issue" />
</picture>
</a>