Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Collection<R, M, MM>

Type parameters

Hierarchy

  • Collection

Index

Constructors

Accessors

  • get id(): string
  • The UUID of the collection used internally

    As this field is for internal use only, use the Collection.name field if you need to reference a collection.

    see

    Collection.name

    Returns string

  • get name(): string
  • The name of the collection

    const stash = await Stash.connect();
    const movies = await stash.loadCollection('movies');
    movies.name // 'movies'

    Returns string

  • get ref(): string
  • A cryptographically secure identifier for the collection

    This field is generated using your profile's naming key, and the name of the collection and is used when communicating with CipherStash.

    Returns string

  • The underlying CollectionSchema for the collection

    Returns CollectionSchema<R, M, MM>

Methods

  • delete(id: string | Buffer): Promise<null>
  • Delete a record by id

    const stash = await Stash.connect();
    const movies = await stash.loadCollection<Movie>('movies');

    const movie = await movies.delete(...);

    Parameters

    • id: string | Buffer

      the id of the document to be deleted

    Returns Promise<null>

  • get(id: string | Buffer): Promise<null | (R & HasID)>
  • Retrieve a record by id

    const stash = await Stash.connect();
    const movies = await stash.loadCollection<Movie>('movies');

    const movie = await movies.get(...);

    Parameters

    • id: string | Buffer

      the id of the document to be retrieved

    Returns Promise<null | (R & HasID)>

    A promise containing the retrieved document if it exists

  • getAll(ids: (string | Buffer)[]): Promise<R[]>
  • Retrieve an array of records from an array of ids

    const stash = await Stash.connect();
    const movies = await stash.loadCollection<Movie>('movies');

    const [ first, second ] = await movies.getAll([ ..., ... ]);

    Parameters

    • ids: (string | Buffer)[]

      An array or buffer of ids to be retrieved

    Returns Promise<R[]>

    • An array containing the retrieved documents
  • put(doc: R): Promise<string>
  • Upsert a record into the collection

    const stash = await Stash.connect();
    const movies = await stash.loadCollection<Movie>('movies');

    const id = await movies.put({
    title: 'CipherStash Reloaded',
    year: 2022
    });

    Parameters

    • doc: R

      the document to be inserted into

    Returns Promise<string>

    A promise resolving with the id of the inserted document

  • putStream(records: AsyncIterator<R, any, undefined>): Promise<StreamingPutReply__Output>
  • Put multiple records into a collection using an async generator

    async function* fetchMovies() {
    const first = await fetchFirstMovie();
    yield first;

    const second = await fetchSecondMovie();
    yield second;
    }

    const stash = await Stash.connect();
    const movies = await stash.loadCollection<Movie>('movies');

    await movies.putStream(fetchMovies);

    Parameters

    • records: AsyncIterator<R, any, undefined>

      AsyncIterator that yields the docs to be inserted

    Returns Promise<StreamingPutReply__Output>

    A promise that resolves with the number of documents inserted

  • Query a collection based on its schema

    const stash = await Stash.connect();
    const movies = await stash.loadCollection(movieSchema);

    const { documents } = await movies.query(
    movie => movie.year.lte(1960)
    );

    Parameters

    • callbackOrQueryOptions: ((where: NeverObjectToAny<{ [ F in string]: OperatorsForIndex<R, M, F> }>) => Query<R, M>) | QueryOptions<R, M>

      a callback function for building a query, or a query options object

    • Optional queryOptions: QueryOptions<R, M>

      an optional object containing query options

    Returns Promise<QueryResult<R & HasID>>

    A QueryResult object containing the documents, aggregates and the time query took

Generated using TypeDoc