csvdb

package
v0.4.6 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: MPL-2.0-no-copyleft-exception Imports: 15 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package csvdb provides a generic CSV/TSV database adapter. Store implements both rowsync.Fetcher and rowsync.Updater over a file in an os.Root directory, with atomic writes and optional normalization.

Index

Constants

This section is empty.

Variables

View Source
var DefaultGate = NewWriteGate()

DefaultGate is the shared write gate for the process.

Functions

func AtomicWrite

func AtomicWrite(root *os.Root, name string, write func(*os.File) error) error

AtomicWrite writes data to a temp file in root, then atomically renames it to name. If the write or rename fails, the temp file is removed.

Types

type Combined

type Combined[T any] struct {
	Stores []rowsync.Fetcher[T]
}

Init validates the root and file name. Combined fetches from several stores and concatenates their rows, e.g. clients.tsv + redirects.tsv, which share one row type and one target.

func (*Combined[T]) Fetch

func (c *Combined[T]) Fetch(ctx context.Context) ([]T, error)

func (*Combined[T]) Init

func (c *Combined[T]) Init(_ context.Context) ([]rowsync.Message, error)

type Store

type Store[T any] struct {
	Root      *os.Root
	Name      string
	Format    string
	Gate      *WriteGate
	Normalize func([]T)
}

Store is a generic TSV/CSV file storage adapter backed by an os.Root. Root must be non-nil; Name is the file within the root directory.

func (*Store[T]) Fetch

func (s *Store[T]) Fetch(_ context.Context) ([]T, error)

Fetch reads the existing file. Missing files return empty state.

func (*Store[T]) Init

func (s *Store[T]) Init(_ context.Context) ([]rowsync.Message, error)

func (*Store[T]) Update

func (s *Store[T]) Update(ctx context.Context, plan rowsync.Plan[T]) error

Update applies a plan to the file. It serializes Plan.Final, never raw source rows: UpdateMode plans keep destination-only rows, SyncMode plans drop them. A plan with no actions leaves the file untouched. Insert-only plans append without rewriting the existing snapshot; any update or delete takes the atomic replacement path. The previous file survives encoding or rename failures (temp file + rename, no fsync).

func (*Store[T]) WriteAll

func (s *Store[T]) WriteAll(ctx context.Context, rows []T) error

WriteAll replaces the file with rows, unconditionally. Use it for full-state writes that are not driven by a plan (split files, fetched config snapshots).

type WriteGate

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

WriteGate permits one local file write at a time.

func NewWriteGate

func NewWriteGate() *WriteGate

NewWriteGate creates a gate that permits one write at a time.

Jump to

Keyboard shortcuts

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