importer

package
v0.0.0-...-b98a032 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2026 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package importer provides functionality to import entities and relations from JSON, YAML, and CSV files into rela projects.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EntityData

type EntityData struct {
	ID         string                 `json:"id" yaml:"id"`
	Type       string                 `json:"type" yaml:"type"`
	Properties map[string]interface{} `json:"properties,omitempty" yaml:"properties,omitempty"`
}

EntityData represents an entity to import

type Format

type Format string

Format represents an import file format

const (
	FormatJSON Format = "json"
	FormatYAML Format = "yaml"
	FormatCSV  Format = "csv"
)

type ImportData

type ImportData struct {
	Entities  []EntityData
	Relations []RelationData
}

ImportData represents the parsed import data

type ImportError

type ImportError struct {
	Type    string // "entity" or "relation"
	ID      string // entity ID or relation key
	Message string
}

ImportError represents an error during import with context

func (ImportError) Error

func (e ImportError) Error() string

type ImportSource

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

ImportSource provides filesystem access for reading import input files. It wraps a storage.FS to make the intent explicit: the FS is for reading source data (CSV, JSON, YAML), which may be on a different filesystem than the project's repository.

func NewImportSource

func NewImportSource(fs storage.FS) *ImportSource

NewImportSource creates an ImportSource from a filesystem.

func (*ImportSource) Open

func (s *ImportSource) Open(path string) (io.ReadCloser, error)

Open opens a file for reading from the import source.

type Importer

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

Importer handles importing data into a rela project

func New

func New(
	repo repository.Store, meta *metamodel.Metamodel, g *graph.Graph, opts Options, source *ImportSource,
) *Importer

New creates a new Importer that reads input files from the given source.

func (*Importer) Import

func (imp *Importer) Import(data *ImportData) (*Result, error)

Import imports the parsed data

func (*Importer) ImportFile

func (imp *Importer) ImportFile(path string) (*Result, error)

ImportFile imports data from a file

type Options

type Options struct {
	// Format specifies the input format. If empty, auto-detected from file extension.
	Format Format

	// DryRun validates without creating files
	DryRun bool

	// Update allows updating existing entities instead of failing on duplicates
	Update bool

	// SkipErrors continues importing on validation errors
	SkipErrors bool

	// RelationsFile is the path to a separate relations CSV file (for CSV imports)
	RelationsFile string
}

Options configures the import behavior

type RelationData

type RelationData struct {
	From       string                 `json:"from" yaml:"from"`
	Relation   string                 `json:"relation" yaml:"relation"`
	To         string                 `json:"to" yaml:"to"`
	Properties map[string]interface{} `json:"properties,omitempty" yaml:"properties,omitempty"`
}

RelationData represents a relation to import

type Result

type Result struct {
	EntitiesCreated  int
	EntitiesUpdated  int
	EntitiesSkipped  int
	RelationsCreated int
	RelationsSkipped int
	Errors           []ImportError
}

Result contains the outcome of an import operation

Jump to

Keyboard shortcuts

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