Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Collection<T>

Collection is a group of instances sharing a schema. Collections are like db tables. They can only exist in a db.

Type parameters

  • T = unknown

Hierarchy

  • Collection

Index

Constructors

constructor

  • new Collection(table: Table<T, string>): Collection

Accessors

name

  • get name(): string

Methods

clear

  • clear(): Promise<boolean>

count

  • count(query?: Query<Document<T>>): Promise<number>
  • Count all instances matching the query.

    note

    This is not available on the Go API.

    Parameters

    • Optional query: Query<Document<T>>

      Mongodb-style filter query.

    Returns Promise<number>

create

  • Create a new instance document that can be added or operated on. This does not automatically commit the instance to the collection.

    Parameters

    • Optional data: T

      The input data to use when initializing the document.

    Returns Document<T> & Instance

delete

  • delete(...ids: string[]): Promise<void>
  • Remove (multiple) instance(s) by id.

    note

    It doesn't fail if the ID doesn't exist.

    Parameters

    • Rest ...ids: string[]

      A variadic array of instance ids.

    Returns Promise<void>

find

findById

findOne

has

  • has(...ids: string[]): Promise<boolean>
  • Check that (all) instance(s) exists.

    Parameters

    • Rest ...ids: string[]

    Returns Promise<boolean>

insert

  • insert(...instances: T[]): Promise<string[]>
  • Insert (multiple) new instance(s).

    note

    Insert is similar to save, except it will not allow saving/overwriting existing instances.

    note

    This is the same as create on the Go API.

    Parameters

    • Rest ...instances: T[]

      A variadic array of instances.

    Returns Promise<string[]>

readTransaction

  • readTransaction<T>(cb: T): ReturnType<T>
  • Lock the collection for readonly operations.

    note

    Provides no serialize-able isolation guarantees.

    note

    In practice, this will return a readonly Collection, which disables write operations.

    Type parameters

    • T: (...args: any) => any

    Parameters

    • cb: T

      A callback that takes a readonly collection.

    Returns ReturnType<T>

save

  • save(...instances: T[]): Promise<string[]>
  • Save updates to (multiple) instance(s).

    note

    Save is similar to insert, except it allows saving/overwriting existing instances.

    Parameters

    • Rest ...instances: T[]

      A variadic array of instances.

    Returns Promise<string[]>

writeTransaction

  • writeTransaction<T>(cb: T): ReturnType<T>
  • Lock the collection for exclusive write operations.

    note

    Provides no serialize-able isolation guarantees.

    Type parameters

    • T: (...args: any) => any

    Parameters

    • cb: T

      A callback that takes a collection.

    Returns ReturnType<T>