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.
To install BDataMatrix, run:
go get github.com/bearaujus/bdatamatrix
import "github.com/bearaujus/bdatamatrix"
- 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.
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)
}
_ = 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)
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)
This project is licensed under the MIT License - see the LICENSE file for details.