Modules@robinpath/table
table

@robinpath/table

0.1.1Node.jsPublic

Tabular data operations: filter, sort, join, group, aggregate, pivot � like a lightweight DataFrame

Table

Tabular data operations: filter, sort, join, group, aggregate, pivot — like a lightweight DataFrame

Package: @robinpath/table | Category: Analytics | Type: Integration

Authentication

No authentication required. All functions are available immediately.

Use Cases

Use the table module when you need to:

  • Create a table from array of objects or columns+rows -- Use table.create to perform this operation
  • Select specific columns -- Use table.select to perform this operation
  • Filter rows by condition -- Use table.where to perform this operation
  • Sort rows by a field -- Use table.orderBy to perform this operation
  • Group rows by a field -- Use table.groupBy to perform this operation

Quick Reference

FunctionDescriptionReturns
createCreate a table from array of objects or columns+rowsArray of row objects
selectSelect specific columnsTable with selected columns
whereFilter rows by conditionFiltered rows
orderBySort rows by a fieldSorted table
groupByGroup rows by a fieldGrouped rows keyed by field value
aggregateAggregate grouped dataAggregated results
joinJoin two tablesJoined table
distinctRemove duplicate rowsDeduplicated table
limitTake first N rowsFirst N rows
offsetSkip first N rowsRemaining rows
addColumnAdd a column with a default valueTable with new column
removeColumnRemove column(s)Table without specified columns
renameColumnRename a columnTable with renamed column
pivotPivot tablePivoted table
unpivotUnpivot/melt tableUnpivoted table with key/value columns
countCount rowsRow count
sumSum a numeric columnSum
avgAverage a numeric columnAverage
minMinimum of a columnMinimum value
maxMaximum of a columnMaximum value
headFirst N rowsFirst N rows
tailLast N rowsLast N rows
columnsGet column namesColumn name strings
shapeGet row and column counts{rows, columns}

Functions

create

Create a table from array of objects or columns+rows

Module: table | Returns: array -- Array of row objects

table.create [{"name": "Alice", "age": 30}]
ParameterTypeRequiredDescription
dataobjectYesArray of objects or {columns, rows}

select

Select specific columns

Module: table | Returns: array -- Table with selected columns

table.select $data ["name", "age"]
ParameterTypeRequiredDescription
tablearrayYesTable data
columnsarrayYesColumn names to keep

where

Filter rows by condition

Module: table | Returns: array -- Filtered rows

table.where $data "age" "gt" 25
ParameterTypeRequiredDescription
tablearrayYesTable data
fieldstringYesColumn name
operatorstringYeseq
valueanyNoComparison value

orderBy

Sort rows by a field

Module: table | Returns: array -- Sorted table

table.orderBy $data "age" "desc"
ParameterTypeRequiredDescription
tablearrayYesTable data
fieldstringYesColumn to sort by
directionstringNoasc or desc

groupBy

Group rows by a field

Module: table | Returns: object -- Grouped rows keyed by field value

table.groupBy $data "department"
ParameterTypeRequiredDescription
tablearrayYesTable data
fieldstringYesColumn to group by

aggregate

Aggregate grouped data

Module: table | Returns: array -- Aggregated results

table.aggregate $data "dept" [{"field": "salary", "op": "avg"}]
ParameterTypeRequiredDescription
tablearrayYesTable data
groupFieldstringYesColumn to group by
aggregationsarrayYesArray of {field, op: sum

join

Join two tables

Module: table | Returns: array -- Joined table

table.join $users $orders "id" "userId" "left"
ParameterTypeRequiredDescription
leftarrayYesLeft table
rightarrayYesRight table
leftKeystringYesLeft join key
rightKeystringYesRight join key
typestringNoinner

distinct

Remove duplicate rows

Module: table | Returns: array -- Deduplicated table

table.distinct $data ["name"]
ParameterTypeRequiredDescription
tablearrayYesTable data
columnsarrayNoColumns for uniqueness check

limit

Take first N rows

Module: table | Returns: array -- First N rows

table.limit $data 10
ParameterTypeRequiredDescription
tablearrayYesTable data
nnumberYesNumber of rows

offset

Skip first N rows

Module: table | Returns: array -- Remaining rows

table.offset $data 5
ParameterTypeRequiredDescription
tablearrayYesTable data
nnumberYesRows to skip

addColumn

Add a column with a default value

Module: table | Returns: array -- Table with new column

table.addColumn $data "status" "active"
ParameterTypeRequiredDescription
tablearrayYesTable data
columnNamestringYesNew column name
valueanyYesDefault value

removeColumn

Remove column(s)

Module: table | Returns: array -- Table without specified columns

table.removeColumn $data "temp"
ParameterTypeRequiredDescription
tablearrayYesTable data
columnsanyYesColumn name or array of names

renameColumn

Rename a column

Module: table | Returns: array -- Table with renamed column

table.renameColumn $data "fname" "firstName"
ParameterTypeRequiredDescription
tablearrayYesTable data
oldNamestringYesCurrent name
newNamestringYesNew name

pivot

Pivot table

Module: table | Returns: array -- Pivoted table

table.pivot $data "product" "month" "sales" "sum"
ParameterTypeRequiredDescription
tablearrayYesTable data
rowFieldstringYesRow grouping field
columnFieldstringYesColumn pivot field
valueFieldstringYesValue field
aggOpstringNosum

unpivot

Unpivot/melt table

Module: table | Returns: array -- Unpivoted table with key/value columns

table.unpivot $data ["name"] ["jan", "feb", "mar"]
ParameterTypeRequiredDescription
tablearrayYesTable data
idColumnsarrayYesColumns to keep
valueColumnsarrayYesColumns to melt

count

Count rows

Module: table | Returns: number -- Row count

table.count $data
ParameterTypeRequiredDescription
tablearrayYesTable data

sum

Sum a numeric column

Module: table | Returns: number -- Sum

table.sum $data "amount"
ParameterTypeRequiredDescription
tablearrayYesTable data
fieldstringYesColumn name

avg

Average a numeric column

Module: table | Returns: number -- Average

table.avg $data "score"
ParameterTypeRequiredDescription
tablearrayYesTable data
fieldstringYesColumn name

min

Minimum of a column

Module: table | Returns: number -- Minimum value

table.min $data "price"
ParameterTypeRequiredDescription
tablearrayYesTable data
fieldstringYesColumn name

max

Maximum of a column

Module: table | Returns: number -- Maximum value

table.max $data "price"
ParameterTypeRequiredDescription
tablearrayYesTable data
fieldstringYesColumn name

head

First N rows

Module: table | Returns: array -- First N rows

table.head $data 5
ParameterTypeRequiredDescription
tablearrayYesTable data
nnumberNoNumber of rows (default 5)

tail

Last N rows

Module: table | Returns: array -- Last N rows

table.tail $data 5
ParameterTypeRequiredDescription
tablearrayYesTable data
nnumberNoNumber of rows (default 5)

columns

Get column names

Module: table | Returns: array -- Column name strings

table.columns $data
ParameterTypeRequiredDescription
tablearrayYesTable data

shape

Get row and column counts

Module: table | Returns: object -- {rows, columns}

table.shape $data
ParameterTypeRequiredDescription
tablearrayYesTable data

Error Handling

All functions throw on failure. Common errors:

ErrorCause
(standard errors)Check function parameters and authentication
@desc "Create and validate result"
do
  set $result as table.create [{"name": "Alice", "age": 30}]
  if $result != null
    print "Success"
  else
    print "No result"
  end
enddo

Recipes

1. Create a new item with create

Create a new resource and capture the result.

set $result as table.create [{"name": "Alice", "age": 30}]
print "Created: " + $result

2. Multi-step Table workflow

Chain multiple table operations together.

@desc "Create, select, and more"
do
  set $r_create as table.create [{"name": "Alice", "age": 30}]
  set $r_select as table.select $data ["name", "age"]
  set $r_where as table.where $data "age" "gt" 25
  print "All operations complete"
enddo

3. Safe create with validation

Check results before proceeding.

@desc "Create and validate result"
do
  set $result as table.create [{"name": "Alice", "age": 30}]
  if $result != null
    print "Success: " + $result
  else
    print "Operation returned no data"
  end
enddo

Related Modules

  • json -- JSON module for complementary functionality

Versions (1)

VersionTagPublished
0.1.1latest1 months ago
Install
$ robinpath add @robinpath/table

Collaborators

Dumitru Balaban
Dumitru Balaban
@dumitru
View all @robinpath modules
Version0.1.1
LicenseMIT
Unpacked Size7.4 KB
Versions1
Weekly Downloads21
Total Downloads21
Stars0
Last Publish1 months ago
Created1 months ago

Category

data