CipherStash
CipherStash Documentation

Range query

Range queries support the below 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)

In this example, the field year has been indexed as a Range index.

Between

.between(minValue, maxValue)

Returns all records between the min and max values provided.

import {
    Stash,
    StashRecord,
} from "@cipherstash/stashjs"

interface Movie extends StashRecord {
  title: string;
  runningTime: number;
  year: number;
};

const rangeQuery = async () => {
  try {
    const stash = await Stash.connect()
    const movies = await stash.loadCollection<Movie>("movies")

    let queryResult = await movies.query(movie => movie.year.between(2000, 2007))

    console.log(queryResult)
  } catch (err) {
    console.error(`Could not query collection! Reason: ${JSON.stringify(err)}`)
  }
}

rangeQuery()
Less than

.lt(fieldValue)

Returns all records less than the value provided.

import {
  Stash,
  StashRecord,
} from "@cipherstash/stashjs"

interface Movie extends StashRecord {
  title: string;
  runningTime: number;
  year: number;
};

const rangeQuery = async () => {
  try {
    const stash = await Stash.connect()
    const movies = await stash.loadCollection<Movie>("movies")

    let queryResult = await movies.query(movie => movie.year.lt(2000))

    console.log(queryResult)
  } catch (err) {
    console.error(`Could not query collection! Reason: ${JSON.stringify(err)}`)
  }
}

rangeQuery()
Less than or equal to

.lte(fieldValue)

Returns all records less than and equal to the value provided.

import {
  Stash,
  StashRecord,
} from "@cipherstash/stashjs"

interface Movie extends StashRecord {
  title: string;
  runningTime: number;
  year: number;
};

const rangeQuery = async () => {
  try {
    const stash = await Stash.connect()
    const movies = await stash.loadCollection<Movie>("movies")

    let queryResult = await movies.query(movie => movie.year.lte(2009))

    console.log(queryResult)
  } catch (err) {
    console.error(`Could not query collection! Reason: ${JSON.stringify(err)}`)
  }
}

rangeQuery()
Greater than

.gt(fieldValue)

Returns all records greater than the value provided.

import {
  Stash,
  StashRecord,
} from "@cipherstash/stashjs"

interface Movie extends StashRecord {
  title: string;
  runningTime: number;
  year: number;
};

const rangeQuery = async () => {
  try {
    const stash = await Stash.connect()
    const movies = await stash.loadCollection<Movie>("movies")

    const queryResult = await movies.query(movie => movie.year.gt(2004))

    console.log(queryResult)
  } catch (err) {
    console.error(`Could not query collection! Reason: ${JSON.stringify(err)}`)
  }
}

rangeQuery()
Greater than or equal to

.gte(fieldValue)

Returns all records greater than and equal to the value provided.

import {
  Stash,
  StashRecord,
} from "@cipherstash/stashjs"

interface Movie extends StashRecord {
  title: string;
  runningTime: number;
  year: number;
};

const rangeQuery = async () => {
  try {
    const stash = await Stash.connect()
    const movies = await stash.loadCollection<Movie>("movies")

    const queryResult = await movies.query(movie => movie.year.gte(2004))

    console.log(queryResult)
  } catch (err) {
    console.error(`Could not query collection! Reason: ${JSON.stringify(err)}`)
  }
}

rangeQuery()
Equal to

.eq(fieldValue)

Returns all records equal to the value provided.

import {
  Stash,
  StashRecord,
} from "@cipherstash/stashjs"

interface Movie extends StashRecord {
  title: string;
  runningTime: number;
  year: number;
};

const rangeQuery = async () => {
  try {
    const stash = await Stash.connect()
    const movies = await stash.loadCollection<Movie>("movies")

    const queryResult = await movies.query(movie => movie.year.eq(2004))

    console.log(queryResult)
  } catch (err) {
    console.error(`Could not query collection! Reason: ${JSON.stringify(err)}`)
  }
}

rangeQuery()