litekit

package
v0.2.20 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccessMode

type AccessMode byte

AccessMode represents SQLite access mode. https://www.sqlite.org/c3ref/open.html

const (
	// ReadWriteCreate is a mode in which the database is opened for reading and writing,
	// and is created if it does not already exist.
	ReadWriteCreate AccessMode = iota

	// ReadOnly is a mode in which the database is opened in read-only mode.
	// If the database does not already exist, an error is returned.
	ReadOnly

	// ReadWrite is a mode in which database is opened for reading and writing if possible,
	// or reading only if the file is write-protected by the operating system.
	// In either case the database must already exist, otherwise an error is returned.
	// For historical reasons, if opening in read-write mode fails due to OS-level permissions,
	// an attempt is made to open it in read-only mode.
	ReadWrite

	// InMemory is a mode in which database will be opened as an in-memory database.
	// The database is named by the "filename" argument for the purposes of cache-sharing,
	// if shared cache mode is enabled, but the "filename" is otherwise ignored.
	InMemory
)

func AccessModeFromString

func AccessModeFromString(mode string) (AccessMode, error)

AccessModeFromString converts a string representation of an access mode to an AccessMode type. It returns the corresponding AccessMode and a nil error if the conversion is successful. If the input string does not match any known access mode, it returns the default ReadWriteCreate mode and an error indicating that the access mode is unsupported. The supported access modes are "rwc" (ReadWriteCreate), "ro" (ReadOnly), "rw" (ReadWrite), and "memory" (InMemory). The conversion is case-insensitive.

func (AccessMode) String

func (m AccessMode) String() string

type Conn

type Conn struct {
	*sql.DB
	// contains filtered or unexported fields
}

func New

func New(path string, options ...Option) (*Conn, error)

func (*Conn) Close added in v0.2.2

func (c *Conn) Close() (closeErr error)

func (*Conn) Health

func (c *Conn) Health(ctx context.Context) error

Health implements hc.HealthChecker interface.

type Error

type Error string

Error represents package level errors related to the storage engine.

const (
	// ErrUnsupportedAccessMode indicates that AccessMode which has been
	// passed to the New function by WithAccessMode option is not
	// supported by the Storage.
	ErrUnsupportedAccessMode Error = "unsupported access mode"

	// ErrUnsupportedJournalMode indicates that JournalMode which has been
	// passed to the New function by WithJournalMode option is not
	// supported by the Storage.
	ErrUnsupportedJournalMode Error = "unsupported journal mode"
)

func (Error) Error

func (e Error) Error() string

type Evolver

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

Evolver is responsible for database schema evolution.

func NewEvolver

func NewEvolver(db *Conn, mutations fs.FS, options ...EvolverOption) (*Evolver, error)

NewEvolver creates a new instance of Evolver.

func (*Evolver) MutateSchema

func (e *Evolver) MutateSchema() (eErr error)

type EvolverOption added in v0.2.1

type EvolverOption func(*Evolver)

func WithBackupBeforeMutations added in v0.2.1

func WithBackupBeforeMutations() EvolverOption

WithBackupBeforeMutations returns an EvolverOption that sets the backupBeforeMutations field of the Evolver to true.

func WithMutationTimeout added in v0.2.1

func WithMutationTimeout(timeout time.Duration) EvolverOption

WithMutationTimeout returns an EvolverOption that sets the mutationTimeout field of the Evolver to the specified timeout value.

type FileBackupConfig added in v0.2.2

type FileBackupConfig struct {
	RestoreTimeout time.Duration
	Path           string
}

FileBackupConfig holds file backup configuration.

type JournalMode

type JournalMode byte

JournalMode represents SQLite journaling mode. https://www.sqlite.org/pragma.html#pragma_journal_mode

Note that the JournalMode for an InMemory database is either Memory or Off and can not be changed to a different value.

An attempt to change the JournalMode of an InMemory database to any setting other than Memory or Off is ignored.

Note also that the JournalMode cannot be changed while a transaction is active.

const (
	// Delete journaling mode is the normal behavior. In the Delete mode, the rollback
	// journal is deleted at the conclusion of each transaction. Indeed, the delete
	// operation is the action that causes the transaction to commit.
	// See the document titled Atomic Commit In SQLite for additional detail:
	// https://www.sqlite.org/atomiccommit.html
	Delete JournalMode = iota

	// Truncate journaling mode commits transactions by truncating the rollback journal to
	// zero-length instead of deleting it. On many systems, truncating a file is much faster
	// than deleting the file since the containing directory does not need to be changed.
	Truncate

	// Persist journaling mode prevents the rollback journal from being deleted at the end of
	// each transaction. Instead, the header of the journal is overwritten with zeros.
	// This will prevent other database connections from rolling the journal back.
	// The Persist journaling mode is useful as an optimization on platforms where deleting or
	// truncating a file is much more expensive than overwriting the first block of a file with zeros.
	Persist

	// Memory journaling mode stores the rollback journal in volatile RAM.
	// This saves disk I/O but at the expense of database safety and integrity.
	// If the application using SQLite crashes in the middle of a transaction when
	// the Memory journaling mode is set, then the database file will very likely go corrupt.
	Memory

	// WAL journaling mode uses a write-ahead log instead of a rollback journal to implement transactions.
	// The WAL journaling mode is persistent; after being set it stays in effect across multiple database
	// connections and after closing and reopening the database.
	// A database in WAL journaling mode can only be accessed by SQLite version 3.7.0 (2010-07-21) or later.
	WAL

	// Off journaling mode disables the rollback journal completely.
	// No rollback journal is ever created and hence there is never a rollback journal to delete.
	// The Off journaling mode disables the atomic commit and rollback capabilities of SQLite.
	// The ROLLBACK command no longer works; it behaves in an undefined way.
	// Applications must avoid using the ROLLBACK command when the journal mode is Off.
	// If the application crashes in the middle of a transaction when the Off journaling mode is set,
	// then the database file will very likely go corrupt.
	Off
)

func JournalModeFromString

func JournalModeFromString(mode string) (JournalMode, error)

JournalModeFromString converts a string representation of a journal mode to a JournalMode type. It returns the corresponding JournalMode and a nil error if the conversion is successful. If the input string does not match any known journal mode, it returns the default Delete mode and an error indicating that the access mode is unsupported. The supported journal modes are "WAL", "Delete", "Memory", "Off", "Persist", and "Truncate". The conversion is case-insensitive.

func (JournalMode) String

func (m JournalMode) String() string

type Mutation

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

Mutation represents a single schema mutation. It contains the version number of the mutation and the changes to be applied.

type Option

type Option func(c *Conn)

Option represents an optional functions which configures the Storage.

func WithAccessMode

func WithAccessMode(mode AccessMode) Option

WithAccessMode enables SQLite to use picked access mode.

func WithBackupToFile added in v0.2.2

func WithBackupToFile(cfg FileBackupConfig) Option

WithBackupToFile sets backup to a file.

func WithBackupToS3 added in v0.2.2

func WithBackupToS3(cfg S3BackupConfig) Option

WithBackupToS3 sets backup to S3-like storages.

func WithJournalMode

func WithJournalMode(mode JournalMode) Option

WithJournalMode sets SQLite to use picked journal mode.

type S3BackupConfig added in v0.2.2

type S3BackupConfig struct {
	RestoreTimeout  time.Duration
	AccessKeyID     string
	SecretAccessKey string
	Bucket          string
	Region          string
	Endpoint        string
}

S3BackupConfig holds S3 backup configuration.

type SchemaVersionInfo

type SchemaVersionInfo struct {
	ID        int
	Version   int
	CreatedAt time.Time
	UpdatedAt time.Time
}

SchemaVersionInfo represents information about a schema version. It contains the id, version number, and timestamps of creation and update.

type To added in v0.2.2

type To byte

To represents backup destination type.

const (
	// S3 represents backup destination to S3-like storages.
	S3 To = iota + 1

	// File represents backup destination to a file.
	File
)

Jump to

Keyboard shortcuts

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