Skip to content

Library Alignment

This page documents operators that are currently available in only one of the Bmg implementations, along with suggestions for potential cross-implementation alignment.

The following operators are available in Bmg (Ruby) but not yet in Bmg.js (TypeScript):

page

Pagination with ordering

rel.page([[:name, :asc]], 1, page_size: 10)

Retrieves a specific page of results with consistent ordering. Useful for building paginated APIs.

rxmatch

Regex match restriction

rel.rxmatch(:name, /^S/)

Filter tuples where an attribute matches a regular expression pattern.

autosummarize

Automatic summarization

rel.autosummarize([:group_key], :sum)

Automatically summarizes all non-key numeric attributes using the specified aggregator.

undress

Convert to scalars

rel.undress

Converts single-attribute tuples to scalar values.

images

Multiple image shortcut

rel.images(other1, other2, ...)

Shortcut for applying multiple image operations in sequence.

generator

Sequence generation

Bmg.generate(1, 100)

Creates a relation from a sequence of values, similar to PostgreSQL’s generate_series.

The following operators are available in Bmg.js (TypeScript) but not yet in Bmg (Ruby):

intersect

Set intersection

left.intersect(right)

Returns tuples that exist in both relations.

wrap

Wrap attributes

rel.wrap(['a', 'b'], 'nested')

Combines multiple attributes into a single tuple-valued attribute.

one

Extract single tuple

rel.one()

Extracts a single tuple, throwing if not exactly one exists.

isEqual

Set equality check

rel1.isEqual(rel2)

Checks if two relations contain the same tuples.

These would provide the most value if implemented in both libraries:

OperatorMissing fromRationale
intersectRubyCommon set operation, completes the set algebra
wrapRubyInverse of unwrap, needed for structural completeness
pageTypeScriptEssential for building paginated APIs
OperatorMissing fromRationale
oneRubyUseful for extracting single results safely
isEqualRubyValuable for testing and assertions
rxmatchTypeScriptUseful for pattern-based filtering
  • to_a (Ruby) and toArray() (TypeScript) serve the same purpose
  • y_by_x (Ruby) and yByX (TypeScript) serve the same purpose
  • Some operators like autosummarize and undress are Ruby-specific conveniences that may not fit TypeScript’s design philosophy

Contributions to align the libraries are welcome! See the respective repositories: