exporter

package
v0.69.0 Latest Latest
Warning

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

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

Documentation

Overview

ExportTopoJSON: TopoJSON v3 export.

Scope decision (v1): whole-ring shared-arc dedup, WITHOUT partial-arc splitting. Two rings (Polygon/MultiPolygon rings, or LineString/ MultiLineString lines) that trace the identical closed boundary -- allowing for a different start vertex and/or winding direction -- become one shared arc, referenced forward by one and reversed (~i) by the other. This is cheap once every ring is being hashed anyway (which building "arcs" requires regardless), and it is exactly the case this project's own GEO_DISSOLVE will produce (two adjacent regions sharing a full boundary). Detecting a PARTIAL match -- two boundaries that coincide for only part of their length and diverge elsewhere, which would require splitting an arc at the junction point -- is the genuinely hard part of real topology-building tools like mapshaper, and is out of scope here; every ring that isn't a whole-ring match gets its own arc. The result is still 100% spec-valid TopoJSON either way, just less maximally compact than a full topology-builder's output would be.

Unlike every other exporter in this package, this cannot stream row by row: arc assignment and quantization both need a global pass over every coordinate before any arc can be finalized (a ring's arc may turn out to be shared with a row not yet seen, and the quantization scale/translate need the global bounding box). Memory use is O(total coordinate count), not O(one row) -- an unavoidable consequence of the format, not a shortcut.

Excel (.xlsx) export. Writes a minimal but valid Office Open XML SpreadsheetML workbook: one sheet, no shared-string table (every text value is written as an inline string, which the format supports natively and avoids the bookkeeping of a separate dictionary part), and the boilerplate parts (content types, relationships, a single default style) every reader — including Excel itself — expects to find. Built with only archive/zip and encoding/xml (both stdlib), matching this package's existing hand-rolled GeoJSON/TopoJSON/SQL writers: no third-party XLSX dependency.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExportCSV

func ExportCSV(w io.Writer, rs *engine.ResultSet, opts Options) error

ExportCSV writes ResultSet rows as CSV to w. Column order is preserved.

func ExportGOB

func ExportGOB(w io.Writer, rs *engine.ResultSet) error

ExportGOB encodes the ResultSet.Rows using gob to w.

func ExportGeoJSON added in v0.27.0

func ExportGeoJSON(w io.Writer, rs *engine.ResultSet, geomCol string, opts Options) error

ExportGeoJSON writes ResultSet rows as an RFC 7946 GeoJSON FeatureCollection. geomCol names the column whose value becomes each Feature's "geometry"; every other selected column (except a redundant "geometry_type" column, if present -- ImportGeoJSON's own naming convention, so an imported-then-reselected table round-trips cleanly) becomes a "properties" entry. Pass "" for geomCol to auto-detect via resolveGeometryColumn.

A row whose geometry cell is nil, or doesn't parse as JSON, becomes a Feature with "geometry": null (legal per RFC 7946 §3.2) rather than aborting the export -- one bad cell should not lose every other row.

func ExportJSON

func ExportJSON(w io.Writer, rs *engine.ResultSet, opts Options) error

ExportJSON writes ResultSet rows as a JSON array of objects. Like ExportNDJSON, it encodes one row at a time instead of materializing a result-sized []map[string]any, so memory use stays proportional to a single row rather than the whole result set. Output uses the established encoding/json semantics, including the PrettyJSON setting.

func ExportNDJSON added in v0.19.0

func ExportNDJSON(w io.Writer, rs *engine.ResultSet, opts Options) error

ExportNDJSON writes one JSON object per ResultSet row. Unlike ExportJSON it does not materialize a result-sized array, so it is suitable for pipes and large exports. Each line is independently valid JSON.

func ExportSQL added in v0.14.0

func ExportSQL(w io.Writer, rs *engine.ResultSet, tableName string) error

ExportSQL writes ResultSet rows as INSERT statements for tableName.

func ExportTableManifest added in v0.19.0

func ExportTableManifest(w io.Writer, db *storage.DB, tenant, tableName string) error

ExportTableManifest writes a deterministic JSON schema and data fingerprint for one table. The corresponding data can be exported as CSV, JSON or SQL.

func ExportTopoJSON added in v0.27.0

func ExportTopoJSON(w io.Writer, rs *engine.ResultSet, geomCol, objectName string, opts Options) error

ExportTopoJSON writes ResultSet rows as a TopoJSON v3 Topology. geomCol and auto-detect behave identically to ExportGeoJSON. objectName becomes the single key of the "objects" map (default "collection" if empty, or if a caller-supplied name is empty). Every row becomes one child geometry inside that object's GeometryCollection, carrying a "properties" member -- the standard, Power-BI/D3-compatible convention for attaching per-feature attributes in TopoJSON (there is no first-class per-feature "properties" the way GeoJSON has; a GeometryCollection whose children each carry one is how every real TopoJSON consumer expects it).

func ExportXLSX added in v0.27.0

func ExportXLSX(w io.Writer, rs *engine.ResultSet, opts Options) error

ExportXLSX writes rs as a single-sheet Excel workbook to w. Numeric Go values (int*/uint*/float*) become native numeric cells and bool becomes a native boolean cell, so a SUM/AVERAGE formula over an exported numeric column works without a manual "convert to number" step in Excel; every other value (including time.Time, formatted like the other exporters' valueToString) is written as an inline string cell.

func ExportXML

func ExportXML(w io.Writer, rs *engine.ResultSet) error

ExportXML writes ResultSet as simple XML: <rows><row><col>value</col>...</row>...</rows>

Types

type ManifestColumn added in v0.19.0

type ManifestColumn struct {
	Name         string `json:"name"`
	DeclaredType string `json:"declared_type"`
	Affinity     string `json:"affinity,omitempty"`
	NotNull      bool   `json:"not_null"`
	HasDefault   bool   `json:"has_default"`
	DefaultSQL   string `json:"default_sql,omitempty"`
	Constraint   string `json:"constraint,omitempty"`
}

ManifestColumn preserves portable schema information without exposing tinySQL internal implementation fields.

type Options

type Options struct {
	PrettyJSON   bool
	CSVNoHeader  bool
	CSVDelimiter rune
	// BinaryEncoding controls CSV rendering of BLOB values. "base64" is the
	// default and writes a self-identifying base64: payload; "hex" writes a
	// self-identifying hex: payload. SQL always uses SQLite-compatible X'..'.
	BinaryEncoding string
	// JSONBinaryEnvelope preserves the BLOB/text distinction in JSON by
	// encoding BLOBs as {"$tinysql":"blob","base64":"..."}. It is enabled
	// by default; set JSONBinaryMode to "legacy-string" for a plain base64
	// string compatible with encoding/json's historical []byte behaviour.
	JSONBinaryMode string
}

Options controls exporter behavior.

type TableManifest added in v0.19.0

type TableManifest struct {
	FormatVersion int              `json:"format_version"`
	Tenant        string           `json:"tenant"`
	Table         string           `json:"table"`
	TextEncoding  string           `json:"text_encoding"`
	RowCount      int              `json:"row_count"`
	DataSHA256    string           `json:"data_sha256"`
	Columns       []ManifestColumn `json:"columns"`
}

TableManifest is a portable, versioned description of an exported table. DataSHA256 fingerprints the ordered rows and typed cells without exposing their contents. It allows an import/export workflow to verify parity before publishing an artifact.

Jump to

Keyboard shortcuts

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