format

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const DisplayNameLayout = "2006-01-02T150405.000Z"

DisplayNameLayout is the time format for the timestamp portion of UUIDv7 display names. Uses millisecond precision, UTC, filesystem-safe (no colons).

Variables

This section is empty.

Functions

func ArrayToText

func ArrayToText(value []interface{}) (string, error)

ArrayToText converts a PostgreSQL array to JSON array text

func BoolToPostgresText

func BoolToPostgresText(value bool) string

BoolToPostgresText converts a boolean to PostgreSQL text format (t/f)

func BoolToStandardText

func BoolToStandardText(value bool) string

BoolToStandardText converts a boolean to standard text format (true/false)

func ConvertValueToText

func ConvertValueToText(value interface{}) (string, error)

ConvertValueToText converts a PostgreSQL value to its text representation Handles special PostgreSQL types like JSONB, arrays, and complex types

func DisplayNameToUUIDv7 added in v0.7.0

func DisplayNameToUUIDv7(name string) (uuid.UUID, error)

DisplayNameToUUIDv7 parses a display name back to a UUIDv7. This is the inverse of UUIDv7ToDisplayName -- fully reversible with no lookup needed.

func ExtractUUIDv7Time added in v0.7.0

func ExtractUUIDv7Time(id [16]byte) time.Time

ExtractUUIDv7Time extracts the millisecond timestamp from a UUIDv7. UUIDv7 stores a Unix timestamp in milliseconds in the first 48 bits.

func IsDisplayName added in v0.7.0

func IsDisplayName(s string) bool

IsDisplayName checks whether a string looks like a UUIDv7 display name (timestamp-base36 format). Used for path resolution to distinguish display names from hex UUIDs.

func IsUUIDv7 added in v0.7.0

func IsUUIDv7(id [16]byte) bool

IsUUIDv7 checks whether a UUID is version 7 by inspecting the version bits at positions 48-51 (the high nibble of byte 6).

func JSONBToText

func JSONBToText(value interface{}) (string, error)

JSONBToText converts a JSONB value to compact JSON text

func NormalizeForJSON

func NormalizeForJSON(value interface{}) interface{}

NormalizeForJSON converts PostgreSQL-specific types to JSON-compatible types. Unlike ConvertValueToText, this preserves JSON-native types (strings, numbers, bools, nil) while converting problematic types like [16]byte UUIDs to strings.

func ParseCSV

func ParseCSV(line string) ([]string, []interface{}, error)

ParseCSV parses a CSV line into columns and values Format: value1,value2,"quoted value, with comma" Empty values are treated as NULL Note: This requires column names to be known externally (schema order) Used for bare row writes without explicit format extension.

func ParseCSVBulk

func ParseCSVBulk(data []byte) ([]string, [][]interface{}, error)

ParseCSVBulk parses CSV data with a header row into columns and rows. First line must be column names, subsequent lines are data rows. Empty fields are treated as NULL.

func ParseCSVBulkNoHeaders

func ParseCSVBulkNoHeaders(data []byte, columns []string) ([]string, [][]interface{}, error)

ParseCSVBulkNoHeaders parses CSV data without a header row. All rows are data rows, columns are provided by caller. Empty fields are treated as NULL.

func ParseCSVWithHeader

func ParseCSVWithHeader(data string) ([]string, []interface{}, error)

ParseCSVWithHeader parses CSV data with a header row (two lines). First line is column names, second line is values. Returns columns from header and corresponding values. Empty values are treated as NULL. Used for .csv format writes which support PATCH semantics.

func ParseJSON

func ParseJSON(jsonStr string) ([]string, []interface{}, error)

ParseJSON parses a JSON object into columns and values Format: {"col1": "value1", "col2": 42, "col3": null}

func ParseJSONBulk

func ParseJSONBulk(data []byte) ([]string, [][]interface{}, error)

ParseJSONBulk parses a JSON array of objects into columns and rows. All objects must have the same keys (column names). Null values are preserved.

func ParseTSV

func ParseTSV(line string) ([]string, []interface{}, error)

ParseTSV parses a TSV line into columns and values Format: value1\tvalue2\tvalue3 Empty values are treated as NULL Note: This requires column names to be known externally (schema order) Used for bare row writes without explicit format extension.

func ParseTSVBulk

func ParseTSVBulk(data []byte) ([]string, [][]interface{}, error)

ParseTSVBulk parses TSV data with a header row into columns and rows. First line must be column names, subsequent lines are data rows. Empty fields are treated as NULL.

func ParseTSVBulkNoHeaders

func ParseTSVBulkNoHeaders(data []byte, columns []string) ([]string, [][]interface{}, error)

ParseTSVBulkNoHeaders parses TSV data without a header row. All rows are data rows, columns are provided by caller. Empty fields are treated as NULL.

func ParseTSVWithHeader

func ParseTSVWithHeader(data string) ([]string, []interface{}, error)

ParseTSVWithHeader parses TSV data with a header row (two lines). First line is column names, second line is values. Returns columns from header and corresponding values. Empty values are treated as NULL. Used for .tsv format writes which support PATCH semantics.

func ParseYAML

func ParseYAML(yamlStr string) ([]string, []interface{}, error)

ParseYAML parses a YAML document into columns and values Format:

col1: value1
col2: 42
col3: null

func ParseYAMLBulk

func ParseYAMLBulk(data []byte) ([]string, [][]interface{}, error)

ParseYAMLBulk parses multi-document YAML into columns and rows. Each document (separated by ---) represents one row. All documents must have the same keys (column names).

func RowToCSV

func RowToCSV(columns []string, values []interface{}) ([]byte, error)

RowToCSV converts a database row to CSV format (RFC 4180) Columns are in schema order, comma-separated, no header row NULL values are represented as empty fields Fields containing commas, quotes, or newlines are quoted

func RowToJSON

func RowToJSON(columns []string, values []interface{}) ([]byte, error)

RowToJSON converts a database row to compact JSON format. Returns a single-line JSON object with column names as keys. NULL values are represented as JSON null. Characters like &, <, > are NOT escaped (no HTML safety escaping).

func RowToTSV

func RowToTSV(columns []string, values []interface{}) ([]byte, error)

RowToTSV converts a database row to TSV format Columns are in schema order, tab-separated, no header row NULL values are represented as empty fields

func RowToYAML

func RowToYAML(columns []string, values []interface{}) ([]byte, error)

RowToYAML converts a database row to YAML format. Column names are used as keys, producing self-documenting output. NULL values are represented as YAML null. Output includes leading document separator (---) for proper multi-document concatenation. Unicode characters (including emoji) are preserved as-is, not escaped.

Example output:

---
id: 1
name: Alice
email: alice@example.com
created_at: null

func RowsToCSV

func RowsToCSV(columns []string, rows [][]interface{}) ([]byte, error)

RowsToCSV converts multiple database rows to CSV format (RFC 4180). Data rows only, no header row (consistent with row-as-file reads). Column names available via .info/columns if needed. NULL values are represented as empty fields. Fields containing commas, quotes, or newlines are quoted. Empty input returns empty output.

Parameters:

  • columns: Column names in database order (used for validation only)
  • rows: Row values as [][]interface{}

Returns CSV data with trailing newline per row.

func RowsToCSVWithHeaders

func RowsToCSVWithHeaders(columns []string, rows [][]interface{}) ([]byte, error)

RowsToCSVWithHeaders converts multiple database rows to CSV format with a header row. First row is column names, subsequent rows are data. Used for round-trip compatibility with import.

func RowsToJSON

func RowsToJSON(columns []string, rows [][]interface{}) ([]byte, error)

RowsToJSON converts multiple database rows to JSON array format. Returns a JSON array of objects, with column names as keys. NULL values are represented as JSON null. Empty input returns "[]" (empty array). Characters like &, <, > are NOT escaped (no HTML safety escaping).

Parameters:

  • columns: Column names in database order
  • rows: Row values as [][]interface{}

Returns JSON array with pretty printing for readability.

func RowsToTSV

func RowsToTSV(columns []string, rows [][]interface{}) ([]byte, error)

RowsToTSV converts multiple database rows to TSV format. Data rows only, no header row (consistent with row-as-file reads). Column names available via .info/columns if needed. NULL values are represented as empty fields. Tab-separated, no quoting. Empty input returns empty output.

Parameters:

  • columns: Column names in database order (used for validation only)
  • rows: Row values as [][]interface{}

Returns TSV data with trailing newline per row.

func RowsToTSVWithHeaders

func RowsToTSVWithHeaders(columns []string, rows [][]interface{}) ([]byte, error)

RowsToTSVWithHeaders converts multiple database rows to TSV format with a header row. First row is column names, subsequent rows are data. Used for round-trip compatibility with import.

func RowsToYAML

func RowsToYAML(columns []string, rows [][]interface{}) ([]byte, error)

RowsToYAML converts multiple database rows to multi-document YAML format. Each row becomes a separate YAML document with "---" separator. Column names are used as keys, producing self-documenting output. NULL values are represented as YAML null. Empty input returns empty string.

Parameters:

  • columns: Column names in database order
  • rows: Row values as [][]interface{}

Returns multi-document YAML with "---" separators.

func TimeToText

func TimeToText(t time.Time) string

TimeToText converts a time.Time to RFC3339Nano format (full precision)

func UUIDv7ToDisplayName added in v0.7.0

func UUIDv7ToDisplayName(id [16]byte) string

UUIDv7ToDisplayName converts a UUIDv7 to a human-readable display name: "<timestamp>-<base36 entropy>", e.g. "2026-04-07T143000.123Z-zzz0063hd8e5r42".

The format is fully reversible via DisplayNameToUUIDv7. It encodes all 122 meaningful bits of the UUID (48 timestamp + 12 rand_a + 62 rand_b). The 4 version bits and 2 variant bits are fixed constants reconstructed on decode.

Base36 (0-9a-z) is used for the entropy portion to be case-insensitive safe on macOS APFS.

func ValueToString

func ValueToString(value interface{}) string

ValueToString converts a database value to its string representation NULL values become empty strings This is a public function used by TSV, CSV, and column file formatting

Delegates to ConvertValueToText for consistent type handling across all formats, including proper serialization of PostgreSQL types like numeric, UUID, etc.

Types

This section is empty.

Jump to

Keyboard shortcuts

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