data

package
v0.0.0-...-81fcdeb Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package data provides parsers for common data formats

Package data provides data pipeline operations

Package data provides structured data processing capabilities for cbwsh. Inspired by modern shells like Nushell and PowerShell, this package enables type-safe data pipelines and native support for common data formats.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CSVParser

type CSVParser struct {
	Delimiter rune
	HasHeader bool
}

CSVParser parses CSV data into structured tables

func NewCSVParser

func NewCSVParser() *CSVParser

NewCSVParser creates a new CSV parser

func (*CSVParser) Parse

func (p *CSVParser) Parse(data []byte) (*Table, error)

Parse parses CSV bytes into a table

func (*CSVParser) ParseReader

func (p *CSVParser) ParseReader(r io.Reader) (*Table, error)

ParseReader parses CSV from a reader into a table

type DataType

type DataType string

DataType represents the type of structured data

const (
	// DataTypeString represents string data
	DataTypeString DataType = "string"
	// DataTypeInt represents integer data
	DataTypeInt DataType = "int"
	// DataTypeFloat represents floating point data
	DataTypeFloat DataType = "float"
	// DataTypeBool represents boolean data
	DataTypeBool DataType = "bool"
	// DataTypeArray represents array/list data
	DataTypeArray DataType = "array"
	// DataTypeObject represents object/map data
	DataTypeObject DataType = "object"
	// DataTypeNull represents null/nil data
	DataTypeNull DataType = "null"
	// DataTypeTime represents time/date data
	DataTypeTime DataType = "time"
)

type Formatter

type Formatter interface {
	Format(*Table) string
}

Formatter formats a table for display

type JSONFormatter

type JSONFormatter struct {
	Pretty bool
}

JSONFormatter formats a table as JSON

func NewJSONFormatter

func NewJSONFormatter(pretty bool) *JSONFormatter

NewJSONFormatter creates a new JSON formatter

func (*JSONFormatter) Format

func (f *JSONFormatter) Format(table *Table) string

Format formats a table as JSON

type JSONParser

type JSONParser struct{}

JSONParser parses JSON data into structured tables

func NewJSONParser

func NewJSONParser() *JSONParser

NewJSONParser creates a new JSON parser

func (*JSONParser) Parse

func (p *JSONParser) Parse(data []byte) (*Table, error)

Parse parses JSON bytes into a table

func (*JSONParser) ParseReader

func (p *JSONParser) ParseReader(r io.Reader) (*Table, error)

ParseReader parses JSON from a reader into a table

type Operation

type Operation func(*Table) *Table

Operation is a function that transforms a table

type Parser

type Parser interface {
	Parse(data []byte) (*Table, error)
	ParseReader(r io.Reader) (*Table, error)
}

Parser is an interface for parsing data formats

func GetParser

func GetParser(format string) Parser

GetParser returns the appropriate parser for a given format

type Pipeline

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

Pipeline represents a data transformation pipeline

func NewPipeline

func NewPipeline(table *Table) *Pipeline

NewPipeline creates a new data pipeline with the given table

func (*Pipeline) Execute

func (p *Pipeline) Execute() *Table

Execute runs all operations in the pipeline

func (*Pipeline) GroupBy

func (p *Pipeline) GroupBy(field string) *Pipeline

GroupBy groups records by a field

func (*Pipeline) Limit

func (p *Pipeline) Limit(n int) *Pipeline

Limit limits the number of records

func (*Pipeline) Select

func (p *Pipeline) Select(columns ...string) *Pipeline

Select selects specific columns

func (*Pipeline) Sort

func (p *Pipeline) Sort(field string, ascending bool) *Pipeline

Sort sorts records by a field

func (*Pipeline) Where

func (p *Pipeline) Where(field string, condition func(*Value) bool) *Pipeline

Where filters records based on a field condition

type Record

type Record struct {
	Fields map[string]*Value `json:"fields"`
}

Record represents a single record in a structured data stream Similar to a row in a table or a JSON object

func NewRecord

func NewRecord() *Record

NewRecord creates a new record

func (*Record) Get

func (r *Record) Get(key string) (*Value, bool)

Get gets a field value from the record

func (*Record) Has

func (r *Record) Has(key string) bool

Has checks if a field exists in the record

func (*Record) Set

func (r *Record) Set(key string, value interface{})

Set sets a field value in the record

func (*Record) ToMap

func (r *Record) ToMap() map[string]interface{}

ToMap converts the record to a map

type Table

type Table struct {
	Columns []string  `json:"columns"`
	Records []*Record `json:"records"`
}

Table represents a collection of records (like a database table)

func NewTable

func NewTable() *Table

NewTable creates a new table

func (*Table) AddColumn

func (t *Table) AddColumn(name string)

AddColumn adds a column to the table

func (*Table) AddRecord

func (t *Table) AddRecord(record *Record)

AddRecord adds a record to the table

func (*Table) Filter

func (t *Table) Filter(predicate func(*Record) bool) *Table

Filter filters records based on a predicate function

func (*Table) Len

func (t *Table) Len() int

Len returns the number of records

func (*Table) Select

func (t *Table) Select(columns ...string) *Table

Select selects specific columns from the table

type TableFormatter

type TableFormatter struct {
	MaxCellWidth int
}

TableFormatter formats a table as a text table

func NewTableFormatter

func NewTableFormatter() *TableFormatter

NewTableFormatter creates a new table formatter

func (*TableFormatter) Format

func (f *TableFormatter) Format(table *Table) string

Format formats a table as a text table

type Value

type Value struct {
	Type DataType    `json:"type"`
	Data interface{} `json:"data"`
}

Value represents a typed value in the data pipeline

func NewValue

func NewValue(data interface{}) *Value

NewValue creates a new typed value

func (*Value) String

func (v *Value) String() string

String returns the string representation of the value

type YAMLParser

type YAMLParser struct{}

YAMLParser parses YAML data into structured tables

func NewYAMLParser

func NewYAMLParser() *YAMLParser

NewYAMLParser creates a new YAML parser

func (*YAMLParser) Parse

func (p *YAMLParser) Parse(data []byte) (*Table, error)

Parse parses YAML bytes into a table

func (*YAMLParser) ParseReader

func (p *YAMLParser) ParseReader(r io.Reader) (*Table, error)

ParseReader parses YAML from a reader into a table

Jump to

Keyboard shortcuts

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