database

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BadgerLogger

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

BadgerLogger is a wrapper type to give our logger the expected interface

func NewBadgerLogger

func NewBadgerLogger(logger *slog.Logger) *BadgerLogger

func (*BadgerLogger) Debugf

func (b *BadgerLogger) Debugf(msg string, args ...any)

func (*BadgerLogger) Errorf

func (b *BadgerLogger) Errorf(msg string, args ...any)

func (*BadgerLogger) Infof

func (b *BadgerLogger) Infof(msg string, args ...any)

func (*BadgerLogger) Warningf

func (b *BadgerLogger) Warningf(msg string, args ...any)

type BaseDatabase

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

func (*BaseDatabase) Blob

func (b *BaseDatabase) Blob() *badger.DB

Blob returns the underling blob DB instance

func (*BaseDatabase) Close

func (b *BaseDatabase) Close() error

Close cleans up the database connections

func (*BaseDatabase) Metadata

func (b *BaseDatabase) Metadata() *gorm.DB

Metadata returns the underlying metadata DB instance

func (*BaseDatabase) Transaction

func (b *BaseDatabase) Transaction(readWrite bool) *Txn

Transaction starts a new database transaction and returns a handle to it

type CommitTimestamp

type CommitTimestamp struct {
	ID        uint `gorm:"primarykey"`
	Timestamp int64
}

CommitTimestamp represents the sqlite table used to track the current commit timestamp

func (CommitTimestamp) TableName

func (CommitTimestamp) TableName() string

type CommitTimestampError

type CommitTimestampError struct {
	MetadataTimestamp int64
	BlobTimestamp     int64
}

func (CommitTimestampError) Error

func (e CommitTimestampError) Error() string

type Database

type Database interface {
	Close() error
	Metadata() *gorm.DB
	Blob() *badger.DB
	Transaction(bool) *Txn
	// contains filtered or unexported methods
}

type InMemoryDatabase

type InMemoryDatabase struct {
	*BaseDatabase
}

InMemoryDatabase stores all data in memory. Data will not be persisted

func NewInMemory

func NewInMemory(logger *slog.Logger) (*InMemoryDatabase, error)

NewInMemory creates a new in-memory database

type PersistentDatabase

type PersistentDatabase struct {
	*BaseDatabase
	// contains filtered or unexported fields
}

PersistentDatabase stores its data on disk, providing persistence across restarts

func NewPersistent

func NewPersistent(
	dataDir string,
	logger *slog.Logger,
) (*PersistentDatabase, error)

NewPersistent creates a new persistent database instance using the provided data directory

type Rat

type Rat struct {
	*big.Rat
}

func (*Rat) Scan

func (r *Rat) Scan(val any) error

func (Rat) Value

func (r Rat) Value() (driver.Value, error)

type Txn

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

Txn is a wrapper around the transaction objects for the underlying DB engines

func NewTxn

func NewTxn(db Database, readWrite bool) *Txn

func (*Txn) Blob

func (t *Txn) Blob() *badger.Txn

func (*Txn) Commit

func (t *Txn) Commit() error

func (*Txn) Do

func (t *Txn) Do(fn func(*Txn) error) error

Do executes the specified function in the context of the transaction. Any errors returned will result in the transaction being rolled back

func (*Txn) Metadata

func (t *Txn) Metadata() *gorm.DB

func (*Txn) Rollback

func (t *Txn) Rollback() error

type Uint64

type Uint64 uint64

func (*Uint64) Scan

func (u *Uint64) Scan(val any) error

func (Uint64) Value

func (u Uint64) Value() (driver.Value, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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