CipherStash
CipherStash Documentation

Range

Range supports range operations in queries.

Supported Types

A Range index can be defined on the following types

Supported Query Operations

  • lt (less than)
  • lte (less than or equal)
  • eq (equal)
  • gt (greater than)
  • gte (greater than or equal)
  • between (indexed value is in between two supplied values)

String Ordering

Range indexes can be used to sort encrypted strings. This feature is somewhat experimental, and thus is not fully-featured yet.

Currently, only printable ASCII characters are supported. Within that subset, characters are sorted in this order:

  1. letters, case-insensitively sorted in alphabetic order; then
  2. whitespace; then
  3. all digits are considered “equal”; then
  4. then all punctuation is also considered “equal”.

Only the first 80 or characters of the string are subject to sorting.

Further advancements, including full UTF-8 and locale-specific ordering rules, are planned. Let us know on our support site if you are particularly interested in this feature.

Index Definition

Range indexes can be defined with the "range" kind in a JSON schema definition:

{
  // (type definition omitted)
  "indexes": {
    "startDate": { "kind": "range", "field": "startDate" }
  }
}

StashJS (TypeScript)

let queryResult1 = await employees.all(
  employee => employee.startDate.eq(new Date(2021, 3, 21))
)

let queryResult2 = await employees.all(
  employee => employee.startDate.lte(new Date(2021, 3, 21))
)

let queryResult3 = await employees.all(
  employee => employee.startDate.between(
    new Date(2020, 1, 1),
    new Date(2021, 1, 1)
  )
)