Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tursodatabase/go-libsql
libSQL API for Go
https://github.com/tursodatabase/go-libsql
go libsql sqlite
Last synced: 4 days ago
JSON representation
libSQL API for Go
- Host: GitHub
- URL: https://github.com/tursodatabase/go-libsql
- Owner: tursodatabase
- License: mit
- Created: 2023-08-29T14:24:15.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-11-13T15:47:18.000Z (about 1 month ago)
- Last Synced: 2024-12-16T00:07:04.032Z (11 days ago)
- Topics: go, libsql, sqlite
- Language: Go
- Homepage:
- Size: 325 MB
- Stars: 130
- Watchers: 14
- Forks: 20
- Open Issues: 21
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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.## 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## Installing
```
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`.
## Getting Started
### Connecting to the database
To connect to the database one needs to create a `libsql.Connector` using one of the factory functions: `libsql.NewEmbeddedReplicaConnector` or `libsql.NewEmbeddedReplicaConnectorWithAutoSync`.
Here's an example of obtaining a `sql.DB` object from `database/sql` package:
```
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()
```Once `sql.DB` object is created one can use it as any other database that supports `database/sql` package.
### Fetching updates from primary database instance
If the connector is created with `libsql.NewEmbeddedReplicaConnectorWithAutoSync` then it will automatically fetch updates from a primary periodically.
For connectors created with `libsql.NewEmbeddedReplicaConnector` we need to fetch updates manually by calling `connector.Sync`
## Examples
Module with usage examples can be found in [example directory].
## License
This project is licensed under the [MIT license].
### Contribution
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.[MIT license]: https://github.com/tursodatabase/go-libsql/blob/main/LICENSE
[example directory]: https://github.com/tursodatabase/go-libsql/tree/main/example