Skip to content

Latest commit

 

History

History
93 lines (67 loc) · 2.06 KB

README.md

File metadata and controls

93 lines (67 loc) · 2.06 KB

BDataMatrix - Structured Tabular Data Management in Go

License Go Report Card

BDataMatrix is a lightweight Go library for managing structured tabular data efficiently. It provides functions to add, update, delete, sort, and query data, along with various export options such as CSV, TSV, JSON, and YAML.

Installation

To install BDataMatrix, run:

go get github.com/bearaujus/bdatamatrix

Import

import "github.com/bearaujus/bdatamatrix"

Features

  • Create structured tabular data with defined headers.
  • Add, update, delete, and search rows efficiently.
  • Export data to CSV, TSV, JSON, YAML, or custom formats.
  • Track header indices for optimized querying.
  • Support for case-insensitive searching.

Usage

1. Creating a Matrix

Create a new matrix with headers:

matrix, err := bdatamatrix.New("ID", "Name", "Age")
if err != nil {
    log.Fatal(err)
}

Create a matrix with predefined data:

rows := [][]string{
    {"1", "Alice", "30"},
    {"2", "Bob", "25"},
}
matrix, err := bdatamatrix.NewWithData(rows, "ID", "Name", "Age")
if err != nil {
    log.Fatal(err)
}

2. Adding and Querying Rows

_ = matrix.AddRow("3", "Charlie", "35")

query := bdatamatrix.FindRowsQuery{
    Column:          "Name",
    Operator:        bdatamatrix.OperatorEquals,
    CaseInsensitive: true,
    Values:          []string{"Alice"},
}

result, err := matrix.FindRows(query)
if err != nil {
    log.Fatal(err)
}
fmt.Println("Matched rows:", result)

3. Exporting Data

Export as CSV:

csvOutput := matrix.ToCSV(true)
_ = csvOutput.Write("output.csv", 0644)

Export as JSON:

jsonOutput := matrix.ToJSON(true, false)
_ = jsonOutput.Write("output.json", 0644)

License

This project is licensed under the MIT License - see the LICENSE file for details.