Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including rbql with all npm packages installed. Try it out:

var rbql = require("rbql")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

rbql v0.3.0

Rainbow Query Language

RBQL (RainBow Query Language) Description

RBQL is a technology which provides SQL-like language that supports SELECT and UPDATE queries with JavaScript expressions.

Official Site


$ npm i rbql

Usage example:

$ rbql-js --query "select a1, a2 order by a1" < input.tsv

Main Features

  • Use JavaScript expressions inside SELECT, UPDATE, WHERE and ORDER BY statements
  • Result set of any query immediately becomes a first-class table on it's own.
  • Output entries appear in the same order as in input unless ORDER BY is provided.
  • Input csv/tsv spreadsheet may contain varying number of entries (but select query must be written in a way that prevents output of missing values)
  • Works out of the box, no external dependencies.

Supported SQL Keywords (Keywords are case insensitive)

  • UPDATE [ SET ]
  • ORDER BY ... [ DESC | ASC ]

All keywords have the same meaning as in SQL queries. You can check them online

RBQL-specific keywords, rules and limitations

  • JOIN statements must have the following form: <JOIN_KEYWORD> (/path/to/table.tsv | table_name ) ON ai == bj
  • UPDATE SET is synonym to UPDATE, because in RBQL there is no need to specify the source table.
  • UPDATE has the same meaning as in SQL, but it also can be considered as a special type of SELECT query.
  • TOP and LIMIT have identical meaning. Use whichever you like more.
  • DISTINCT COUNT is like DISTINCT, but adds a new column to the "distinct" result set: number of occurrences of the entry, similar to uniq -c unix command.
  • STRICT LEFT JOIN is like LEFT JOIN, but generates an error if any key in left table "A" doesn't have exactly one matching key in the right table "B".

Special variables

Variable NameVariable TypeVariable Description
a1, a2,..., a{N}stringValue of i-th column
b1, b2,..., b{N}stringValue of i-th column in join table B
NRintegerLine number (1-based)
NFintegerNumber of fields in line

Aggregate functions and queries

RBQL supports the following aggregate functions, which can also be used with GROUP BY keyword:
_COUNT()_, _MIN()_, _MAX()_, _SUM()_, _AVG()_, _VARIANCE()_, MEDIAN()


  • Aggregate function are CASE SENSITIVE and must be CAPITALIZED.
  • It is illegal to use aggregate functions inside JS expressions. Although you can use expressions inside aggregate functions. E.g. MAX(float(a1) / 1000) - legal; MAX(a1) / 1000 - illegal.

Examples of RBQL queries

  • select top 100 a1, a2 * 10, a4.length where a1 == "Buy" order by parseInt(a2)
  • select * order by Math.random() - random sort, this is an equivalent of bash command sort -R
  • select top 20 a1.length / 10, a2 where ["car", "plane", "boat"].indexOf(a2) > -1
  • select a1.length / 10, a2 where ["car", "plane", "boat"].indexOf(a2) > -1 limit 20
  • update set a3 = 'US' where a3.indexOf('of America') != -1
  • select * where NR <= 10 - this is an equivalent of bash command "head -n 10", NR is 1-based')
  • select a1, a4 - this is an equivalent of bash command "cut -f 1,4"
  • select * order by parseInt(a2) desc - this is an equivalent of bash command "sort -k2,2 -r -n"
  • select NR, * - enumerate lines, NR is 1-based
  • select a1, b1, b2 inner join ./countries.txt on a2 == b1 order by a1, a3 - an example of join query
  • select distinct count a1.length where a2 != 'US'
  • select MAX(a1), MIN(a1) where a2 != 'US' group by a2, a3


  • rbql-js CLI App for Node.js - npm
  • rbql-py CLI App in python
  • Rainbow CSV extension with integrated RBQL in Visual Studio Code
  • Rainbow CSV extension with integrated RBQL in Vim
  • Rainbow CSV extension with integrated RBQL in Sublime Text 3


RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free