libsql

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2025 License: MIT Imports: 4 Imported by: 0

README

Fiber LibSQL Storage

Tests LibSQL Go Reference Go Report Card

LibSQL storage implementation for Fiber framework using go-libsql.

Requirements
  • Go 1.23+
Install
go get github.com/syzio/fiber-libsql
Examples
Local Database
storage := libsql.New(libsql.Config{
    Connection: libsql.Local{
        Database: "file:./fiber.db",
    },
})
Remote Database (Turso)
storage := libsql.New(libsql.Config{
    Connection: libsql.Remote{
        Database:  "libsql://your-database.turso.io",
        AuthToken: "your-token",
    },
})
Embedded Replica
storage := libsql.New(libsql.Config{
    Connection: libsql.EmbeddedReplica{
        Database:      "file:./local.db",
        PrimaryURL:    "libsql://your-database.turso.io",
        AuthToken:     "your-token",
        EncryptionKey: "optional-key",
        SyncInterval:  time.Second,
    },
})
Configuration
type Config struct {
    Connection Connection  // Required: database connection configuration
    Table      string     // Optional: table name (default: fiber_storage)
    Reset      bool       // Optional: drop table if exists (default: false)
    GCInterval time.Duration // Optional: GC interval (default: 10s)
}
License

MIT License - see LICENSE for more details.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConfigDefault = Config{
	Connection: Local{
		Database: "file:./fiber.db",
	},

	Table:      "fiber_storage",
	Reset:      false,
	GCInterval: 10 * time.Second,
}

Functions

This section is empty.

Types

type Config

type Config struct {
	Connection Connection

	Table      string
	Reset      bool
	GCInterval time.Duration
}

Config defines the config for storage

type Connection

type Connection interface {
	Db() (*sql.DB, error)
}

Connection defines the interface for different database connection types

type EmbeddedReplica

type EmbeddedReplica struct {
	Database   string
	PrimaryURL string
	AuthToken  string

	EncryptionKey string

	SyncInterval time.Duration
}

EmbeddedReplica represents a Turso embedded replica connection

func (EmbeddedReplica) Db

func (c EmbeddedReplica) Db() (*sql.DB, error)

type Local

type Local struct {
	Database string
}

Local represents a local LibSQL database connection

func (Local) Db

func (c Local) Db() (*sql.DB, error)

type Remote

type Remote struct {
	Database  string
	AuthToken string
}

Remote represents a remote LibSQL database connection

func (Remote) Db

func (c Remote) Db() (*sql.DB, error)

type Storage

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

Storage interface implementation

func New

func New(config ...Config) *Storage

New creates a storage instance

func (*Storage) Close

func (s *Storage) Close() error

Close closes the storage, stopping the GC and closing the database connection

func (*Storage) Conn

func (s *Storage) Conn() *sql.DB

Conn returns the underlying database connection

func (*Storage) Delete

func (s *Storage) Delete(key string) error

Delete deletes the value for the given key

func (*Storage) Get

func (s *Storage) Get(key string) ([]byte, error)

Get gets the value for the given key

func (*Storage) Reset

func (s *Storage) Reset() error

Reset resets the storage

func (*Storage) Set

func (s *Storage) Set(key string, val []byte, exp time.Duration) error

Set stores the value for the given key

Jump to

Keyboard shortcuts

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