export

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package export streams search results as JSON, CSV, or NDJSON (v0.1.0, owner directive §4).

Contracts:

  • Same semantics: export pages through the SAME SearchService the interactive surfaces use — the keyset cursor guarantees a stable page sequence even while the index changes underneath (already- emitted rows never repeat).
  • Streaming: rows are written per page; memory stays O(page), not O(result set). Large exports are bounded only by MaxRows=0 (unlimited, the operator's explicit choice).
  • Correct escaping: CSV is RFC 4180 via encoding/csv (quotes, commas, newlines, UTF-8); JSON/NDJSON via encoding/json.
  • Honest metadata: the footer carries the compiled query info (mode, branch, took), the total count, and the index freshness notice — never credentials, never connection strings.
  • Array fields (technologies, sources) serialize as ";"-joined strings inside CSV cells; JSON/NDJSON keep real arrays.

Index

Constants

View Source
const (
	FormatJSON   = "json"
	FormatCSV    = "csv"
	FormatNDJSON = "ndjson"
)

Format names.

View Source
const DefaultMaxRows = 10000

DefaultMaxRows is the CLI-side guard: an export without --max stops after this many rows with an explicit "raise --max" message. A Request MaxRows of 0 means unlimited.

Variables

Formats lists the supported export formats.

Functions

func FormatExtension

func FormatExtension(format string) string

FormatExtension returns the canonical file extension for a format.

func ResolveOutPath

func ResolveOutPath(explicit, format string, force bool) (string, error)

ResolveOutPath returns the output path: the explicit value (validated) or a timestamped default with the format's extension. existingOK suppresses the overwrite refusal (used by --force).

func ValidateOutPath

func ValidateOutPath(name string) error

ValidateOutPath checks an explicit --out value.

Types

type Request

type Request struct {
	Query  search.Query // GQL/mode/sort/fields/timeout; Limit is managed by the pager
	Format string
	// MaxRows caps the stream; 0 = unlimited.
	MaxRows int
}

Request is one export job.

type Stats

type Stats struct {
	Rows      int64  `json:"rows"`
	Pages     int    `json:"pages"`
	Format    string `json:"format"`
	TookMs    int64  `json:"took_ms"`
	Query     string `json:"query"`
	Mode      string `json:"mode"`
	Truncated bool   `json:"truncated"` // stopped at MaxRows
	Notice    string `json:"notice,omitempty"`
}

Stats reports what one export wrote.

func Stream

func Stream(ctx context.Context, svc *search.Service, req Request, w io.Writer) (Stats, error)

Stream writes the export to w and returns the stats. Rows are flushed per page — the caller's writer decides the buffering.

Jump to

Keyboard shortcuts

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