libsql

package module
v0.0.0-...-860fbeb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 8, 2025 License: MIT Imports: 16 Imported by: 0

README

LibSQL package for Go

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.

Documentation

Index

Constants

View Source
const (
	TYPE_INT int = iota + 1
	TYPE_FLOAT
	TYPE_TEXT
	TYPE_BLOB
	TYPE_NULL
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Connector

type Connector struct {
	// contains filtered or unexported fields
}

func NewEmbeddedReplicaConnector

func NewEmbeddedReplicaConnector(dbPath string, primaryUrl string, opts ...Option) (*Connector, error)

func NewLocalConnector

func NewLocalConnector(dbPath string, opts ...Option) (*Connector, error)

func (*Connector) Close

func (c *Connector) Close() error

func (*Connector) Connect

func (c *Connector) Connect(ctx context.Context) (sqldriver.Conn, error)

func (*Connector) Driver

func (c *Connector) Driver() sqldriver.Driver

func (*Connector) Sync

func (c *Connector) Sync() (Replicated, error)

type Option

type Option interface {
	// contains filtered or unexported methods
}

func WithAuthToken

func WithAuthToken(authToken string) Option

func WithEncryption

func WithEncryption(key string) Option

func WithExtension

func WithExtension(path, entryPoint string) Option

func WithReadYourWrites

func WithReadYourWrites(readYourWrites bool) Option

func WithSyncInterval

func WithSyncInterval(interval time.Duration) Option

type ParamsInfo

type ParamsInfo struct {
	NamedParameters           []string
	PositionalParametersCount int
}

type Replicated

type Replicated struct {
	FrameNo      int
	FramesSynced int
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL