Data Access

Overview

subZero REST library is a Rust library (with JavaScript/TS bindings) that will generate a PostgREST compatible REST API.

Besides supporting PostgreSQL (like PostgREST), it can also be used with SQLite, MySQL, Clickhouse and all their variants.

In addition to the standard PostgREST api format, it adds a few extra features like:

  • Calling functions in select parameter (like select=id,sku:$concat('#',id))
  • Analytical queries using aggregate and window functions in combination with groupby parameter

For a complete list of features and capabilities supported by a PostgREST compatible API see here

Usage

In a typical setting you would not interact directly with the functions exposed by the underlying library but rather use the generated code that wraps these functions and exposes a higher level API in the form of a express route handler.

Importing

import { init as subzeroInit, rest } from './rest';

Initializing

await subzeroInit(
    app, // app is an express app
    dbPool, // dbPool is a pg.Pool
    ['public'] // list of schemas to expose
);

Handling requests

// The rest module provides a PostgREST-compatible API
// for accessing the database
router.use('/rest/v1', isAuthenticated, rest(['public']));
Previous
Reference