Skip to content

Data Pagination in Pipelines

In this section, we’ll explore how to paginate your data in Pipeline. We’ll use items model for this example.

var schema = {
id: {
type: NIMBUSDB_DATA_TYPE.INTEGER,
const: NIMBUSDB_CONSTRAINT.PRIMARY_KEY
},
name: NIMBUSDB_DATA_TYPE.STRING,
price: {
type: NIMBUSDB_DATA_TYPE.NUMBER,
validator: function(data, value) {
return value >= 0;
},
default_value: 0
},
is_locked: {
type: NIMBUSDB_DATA_TYPE.BOOLEAN,
const: NIMBUSDB_CONSTRAINT.OPTIONAL,
default_value: false
}
};
items = new NimbusDBModel("global", "items", schema, [
{ id: 1, name: "Apple", price: 5 },
{ id: 2, name: "Banana", price: 7.2 },
{ id: 3, name: "Cherry", price: 15 },
{ id: 4, name: "Date", price: 12.5 },
{ id: 5, name: "Elderberry", price: 8 },
{ id: 6, name: "Fig", price: 10 },
{ id: 7, name: "Grape", price: 6 },
{ id: 8, name: "Honeydew", price: 9 },
{ id: 9, name: "Kiwi", price: 4 },
{ id: 10, name: "Lemon", price: 3 }
]);

The limit operation is used to limit the data to the first _count elements. A negative value takes from the end.

// (1) limit to the first 3 elements
var items_pl = items.pipe() // create an `items` pipeline
// let's say you have this data in your pipeline:
// [ 5, 7.2, 15, 12.5, 8, 10, 6, 9, 4, 3 ]
.limit(3); // limit to the first 3 elements
// result:
// [ 5, 7.2, 15 ]
// (2) limit to the last 3 elements
var items_pl = items.pipe() // create an `items` pipeline
// let's say you have this data in your pipeline:
// [ 5, 7.2, 15, 12.5, 8, 10, 6, 9, 4, 3 ]
.limit(-3); // limit to the last 3 elements
// result:
// [ 3, 4, 9 ]

The offset operation is used to skip the first _count elements. A negative value skips from the end.

// (1) skip the first 3 elements
var items_pl = items.pipe() // create an `items` pipeline
// let's say you have this data in your pipeline:
// [ 5, 7.2, 15, 12.5, 8, 10, 6, 9, 4, 3 ]
.offset(3); // skip the first 3 elements
// result:
// [ 12.5, 8, 10, 6, 9, 4, 3 ]
// (2) skip the last 3 elements
var items_pl = items.pipe() // create an `items` pipeline
// let's say you have this data in your pipeline:
// [ 5, 7.2, 15, 12.5, 8, 10, 6, 9, 4, 3 ]
.offset(-3); // skip the last 2 elements (because `-1` is the last element)
// result:
// [ 9, 6, 10, 8, 12.5, 15, 7.2, 5 ]

The slice operation is used to extract a slice of the data starting at _start for _length elements.

// (1) extract a slice of the data starting at index 2
var items_pl = items.pipe() // create an `items` pipeline
// let's say you have this data in your pipeline:
// [ 5, 7.2, 15, 12.5, 8, 10, 6, 9, 4, 3 ]
.slice(2); // start at index 2 (the third element) and extract remaining elements
// result:
// [ 15, 12.5, 8, 10, 6, 9, 4, 3 ]
// (2) extract a slice of the data starting at index 2 with a length of 2
var items_pl = items.pipe() // create an `items` pipeline
// let's say you have this data in your pipeline:
// [ 5, 7.2, 15, 12.5, 8, 10, 6, 9, 4, 3 ]
.slice(2, 3); // start at index 2 (the third element) and extract 3 elements
// result:
// [ 15, 12.5, 8 ]
// (3) extract a slice of the data from the 3 last elements
var items_pl = items.pipe() // create an `items` pipeline
// let's say you have this data in your pipeline:
// [ 5, 7.2, 15, 12.5, 8, 10, 6, 9, 4, 3 ]
.slice(-3); // start at the third-last element and extract remaining elements
// result:
// [ 9, 4, 3 ]
// (4) extract a slice of the data from the 3 last elements with a length of 2
var items_pl = items.pipe() // create an `items` pipeline
// let's say you have this data in your pipeline:
// [ 5, 7.2, 15, 12.5, 8, 10, 6, 9, 4, 3 ]
.slice(-3, 2); // start at the third-last element and extract 2 elements
// result:
// [ 9, 4 ]
// (5) extract a slice of the data from the 3 last elements with a length of 4 (reversed)
var items_pl = items.pipe() // create an `items` pipeline
// let's say you have this data in your pipeline:
// [ 5, 7.2, 15, 12.5, 8, 10, 6, 9, 4, 3 ]
.slice(-3, -4); // start at the third-last element and extract 4 elements (reversed)
// result:
// [ 9, 6, 10, 8 ]

Limits the pipeline data to the first _count elements. A negative value takes from the end.

pipeline.d.ts
class NimbusDBPipeline {
// ... other methods and properties ...
static limit(
_count: int
): NimbusDBPipeline;
}
  • Type: int
  • The number of elements to keep. Negative values take from the end.
  • Type: NimbusDBPipeline
  • A new NimbusDBPipeline instance (mutable = false) or the current pipeline instance (mutable = true).

Skips the first _count elements. A negative value skips from the end.

pipeline.d.ts
class NimbusDBPipeline {
// ... other methods and properties ...
static offset(
_count: int
): NimbusDBPipeline;
}
  • Type: int
  • The number of elements to skip.
  • Type: NimbusDBPipeline
  • A new NimbusDBPipeline instance (mutable = false) or the current pipeline instance (mutable = true).

Extracts a slice of the pipeline data starting at _start for _length elements.

pipeline.d.ts
class NimbusDBPipeline {
// ... other methods and properties ...
static slice(
_start: int,
_length?: int
): NimbusDBPipeline;
}
  • Type: int
  • The starting index (negative = from the end).
  • Type: int
  • Default: undefined (data.length - start)
  • The number of elements to include.
  • Type: NimbusDBPipeline
  • A new NimbusDBPipeline instance (mutable = false) or the current pipeline instance (mutable = true).