impexp

package
v1.29.0 Latest Latest
Warning

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

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

Documentation

Overview

Package impexp provides import/export utilities for data migration, backup, and restore operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Backup

func Backup(ctx context.Context, sources map[string]DataSource, outputDir string) error

Backup creates a full backup of data

func Restore

func Restore(ctx context.Context, backupDir string, sinks map[string]DataSink) error

Restore restores data from a backup

Types

type DataSink

type DataSink interface {
	// WriteBatch writes a batch of data
	WriteBatch(ctx context.Context, batch []interface{}) error
}

DataSink receives data during batch import

type DataSource

type DataSource interface {
	// NextBatch returns the next batch of data
	NextBatch(ctx context.Context, batchSize int) ([]interface{}, error)

	// HasMore indicates if more data is available
	HasMore() bool
}

DataSource provides data for batch export

type DefaultExporter

type DefaultExporter struct{}

DefaultExporter implements the Exporter interface

func (*DefaultExporter) Export

func (e *DefaultExporter) Export(ctx context.Context, data interface{}, w io.Writer, opts *Options) error

Export exports data to a writer

func (*DefaultExporter) ExportBatch

func (e *DefaultExporter) ExportBatch(ctx context.Context, dataSource DataSource, w io.Writer, opts *Options) error

ExportBatch exports data in batches

func (*DefaultExporter) ExportFile

func (e *DefaultExporter) ExportFile(ctx context.Context, data interface{}, filename string, opts *Options) error

ExportFile exports data to a file

type DefaultImporter

type DefaultImporter struct{}

DefaultImporter implements the Importer interface

func (*DefaultImporter) Import

func (i *DefaultImporter) Import(ctx context.Context, r io.Reader, dest interface{}, opts *Options) error

Import imports data from a reader

func (*DefaultImporter) ImportBatch

func (i *DefaultImporter) ImportBatch(ctx context.Context, r io.Reader, dataSink DataSink, opts *Options) error

ImportBatch imports data in batches

func (*DefaultImporter) ImportFile

func (i *DefaultImporter) ImportFile(ctx context.Context, filename string, dest interface{}, opts *Options) error

ImportFile imports data from a file

type Exporter

type Exporter interface {
	// Export exports data to a writer
	Export(ctx context.Context, data interface{}, w io.Writer, opts *Options) error

	// ExportFile exports data to a file
	ExportFile(ctx context.Context, data interface{}, filename string, opts *Options) error

	// ExportBatch exports data in batches
	ExportBatch(ctx context.Context, dataSource DataSource, w io.Writer, opts *Options) error
}

Exporter handles data export operations

func NewExporter

func NewExporter() Exporter

NewExporter creates a new exporter

type FilterFunc

type FilterFunc func(entity interface{}) bool

FilterFunc filters entities during export/import

type Format

type Format string

Format represents the export/import format

const (
	FormatJSON Format = "json"
	FormatCSV  Format = "csv"
	FormatXML  Format = "xml"
	FormatZIP  Format = "zip"
)

type Importer

type Importer interface {
	// Import imports data from a reader
	Import(ctx context.Context, r io.Reader, dest interface{}, opts *Options) error

	// ImportFile imports data from a file
	ImportFile(ctx context.Context, filename string, dest interface{}, opts *Options) error

	// ImportBatch imports data in batches
	ImportBatch(ctx context.Context, r io.Reader, dataSink DataSink, opts *Options) error
}

Importer handles data import operations

func NewImporter

func NewImporter() Importer

NewImporter creates a new importer

type Options

type Options struct {
	Format      Format            // Export format
	Pretty      bool              // Pretty print JSON
	Compress    bool              // Compress output
	Filter      FilterFunc        // Filter function for selective export
	Transform   TransformFunc     // Transform function for data manipulation
	BatchSize   int               // Batch size for large datasets
	Delimiter   rune              // CSV delimiter
	Headers     []string          // CSV headers
	MaxFileSize int64             // Maximum file size in bytes
	Metadata    map[string]string // Additional metadata
	Version     string            // Export version for ZIP format (default "1.0")
}

Options configures import/export operations

type TransformFunc

type TransformFunc func(entity interface{}) (interface{}, error)

TransformFunc transforms entities during export/import

Jump to

Keyboard shortcuts

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