engines

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewAuto

func NewAuto() *database.Database

NewAuto creates a database based on environment variables:

  • DB_URL + DB_TOKEN: Remote libSQL replica (syncs with Turso/libSQL server)
  • DB_PATH: Local file-based SQLite database
  • Neither: In-memory database (for development/testing)

When using remote mode, DB_PATH can optionally specify the local replica path. If not set, it defaults to "/data/replica.db".

Fatal if the configured mode fails. Memory mode cannot fail.

func NewLocal

func NewLocal(path string) (*database.Database, error)

NewLocal creates a new local file database engine.

func NewMemory

func NewMemory() (*database.Database, error)

NewMemory creates a new in-memory database. Useful for testing and development. Data is lost when the connection is closed.

func NewRemote

func NewRemote(localPath, primaryURL, authToken string, opts ...RemoteOption) (*database.Database, error)

NewRemote creates a new embedded replica database that syncs with a remote libSQL server. It maintains a local copy for fast reads while syncing writes to the primary.

The localPath is where the local replica is stored. The primaryURL is the remote libSQL server URL (e.g., "libsql://db-name.turso.io"). The authToken is the authentication token for the remote server.

Returns an error if the connection cannot be established after retries.

Example:

db, err := engines.NewRemote(
    "./data/replica.db",
    os.Getenv("DB_URL"),
    os.Getenv("DB_TOKEN"),
    engines.WithSyncInterval(time.Minute),
)

Types

type RemoteOption

type RemoteOption func(*remoteConfig)

RemoteOption configures a remote database

func WithSyncInterval

func WithSyncInterval(d time.Duration) RemoteOption

WithSyncInterval sets the automatic sync interval. If not set, sync must be called manually.

Jump to

Keyboard shortcuts

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