dalgo2ingitdb

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: May 13, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyLocaleToRead added in v0.12.0

func ApplyLocaleToRead(data map[string]any, cols map[string]*ingitdb.ColumnDef) map[string]any

ApplyLocaleToRead transforms record data from file representation to application representation. For each column that has a Locale value set (e.g. column "title" with locale "en"), the paired map column (e.g. "titles") is inspected: the locale entry is extracted and exposed as the shortcut column ("title"), and that locale key is removed from the pair map to avoid duplication. The caller receives e.g. {"title": "Work", "titles": {"ru": "Работа"}}.

func ApplyLocaleToWrite added in v0.12.0

func ApplyLocaleToWrite(data map[string]any, cols map[string]*ingitdb.ColumnDef) map[string]any

ApplyLocaleToWrite normalises record data before writing to file. For each column that has a Locale value set (e.g. column "title" with locale "en"):

  • The shortcut column ("title") is stored as-is in the file.
  • If the paired map column ("titles") contains an entry for the primary locale key ("en"), that entry is promoted to the shortcut column and removed from the map, so the value is never duplicated across both fields.
  • If the paired map becomes empty after removing the primary locale entry, it is dropped from the result to avoid writing a redundant empty map.

func CollectionForKey added in v0.9.0

func CollectionForKey(def *ingitdb.Definition, id string) (*ingitdb.CollectionDef, string, error)

CollectionForKey finds the collection and record key for a given ID string.

The id format is "{collectionID}/{recordKey}" where collection IDs use "." for namespaces. "/" is reserved for separating collection ID from record key path segments. The longest matching collection prefix wins.

func EncodeMapOfRecordsContent added in v0.57.0

func EncodeMapOfRecordsContent(data map[string]map[string]any, format ingitdb.RecordFormat, recordsetName string, columnsOrder []string) ([]byte, error)

EncodeMapOfRecordsContent serializes a map of ID-keyed records into the declared format. For yaml/json/toml, the data is written as a top-level mapping (record ID -> field map). For INGR, the data is flattened into a list of records (each gets `$ID` injected as the first column) and written via the ingr-io writer.

recordsetName is used as the INGR header title (typically the collection ID). It is ignored for non-INGR formats. columnsOrder controls the column order in the INGR header; when empty, columns are emitted in alphabetical order with `$ID` first.

func EncodeRecordContentForCollection added in v1.2.0

func EncodeRecordContentForCollection(value any, colDef *ingitdb.CollectionDef) ([]byte, error)

EncodeRecordContentForCollection serializes record content using the collection's declared format. It is the write-side counterpart of ParseRecordContentForCollection and the only path callers should use when writing records that may be in a format that requires schema access (csv today; possibly others later).

For csv, value MUST be []map[string]any — see encodeCSVForCollection. For the other six formats, value is passed through to marshalForFormat unchanged; callers that want a single-record map[string]any can keep using the schema-agnostic marshalForFormat directly.

func ParseMapOfRecordsContent added in v0.40.0

func ParseMapOfRecordsContent(content []byte, format ingitdb.RecordFormat) (map[string]map[string]any, error)

ParseMapOfRecordsContent parses content containing a map of ID-keyed records.

For yaml/json/toml, the file's top-level structure is a mapping from record ID to a per-record field map; we re-shape it into map[string]map[string]any.

For INGR, the file is a list of records where the reserved `$ID` column holds each record's key; we read the list and re-index by `$ID`. Records missing `$ID`, or with duplicate `$ID` values, are rejected as malformed.

func ParseRecordContent added in v0.12.0

func ParseRecordContent(content []byte, format ingitdb.RecordFormat) (map[string]any, error)

ParseRecordContent parses record content in YAML or JSON format. For markdown-format collections use ParseRecordContentForCollection, which also has access to the column schema and content-field name.

func ParseRecordContentForCollection added in v0.55.0

func ParseRecordContentForCollection(content []byte, colDef *ingitdb.CollectionDef) (map[string]any, error)

ParseRecordContentForCollection parses record content using the collection's declared format. For YAML and JSON this is equivalent to ParseRecordContent. For markdown records it parses YAML frontmatter, filters to columns declared in the schema, and exposes the body under the configured content_field column name.

Types

type ParsedRecord added in v1.5.0

type ParsedRecord struct {
	// Position is 1-based: line number for jsonl/csv, document index
	// for yaml/ingr. For csv with a header row, Position 2 is the
	// first data record.
	Position int
	// Key is the resolved record key (from $id, id, or --key-column).
	Key string
	// Data is the record's structured fields with the key field stripped.
	Data map[string]any
}

ParsedRecord is one record extracted from a batch stream.

func ParseBatchINGR added in v1.6.0

func ParseBatchINGR(r io.Reader) ([]ParsedRecord, error)

ParseBatchINGR reads an INGR multi-record stream from r and returns one ParsedRecord per record. The key is read from the reserved $ID column (INGR's key field; note the uppercase). $ID is stripped from the returned Data map. Position is the 1-based record index.

func ParseBatchJSONL added in v1.5.0

func ParseBatchJSONL(r io.Reader) ([]ParsedRecord, error)

ParseBatchJSONL reads NDJSON from r and returns one ParsedRecord per non-blank line. Each record MUST have a top-level $id; the $id is stripped from the returned Data map. Blank lines are skipped but counted for the Position field.

func ParseBatchYAMLStream added in v1.6.0

func ParseBatchYAMLStream(r io.Reader) ([]ParsedRecord, error)

ParseBatchYAMLStream reads a YAML multi-document stream from r and returns one ParsedRecord per non-nil document. Each record MUST have a top-level $id; $id is stripped from the returned Data map. Position is the 1-based document index.

Jump to

Keyboard shortcuts

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