Options
All
  • Public
  • Public/Protected
  • All
Menu

Index

Functions

Functions

getMany

  • getMany<Model>(collection: Collection<Model>, ids: keyof string[], onMissing?: function | "ignore"): Promise<Doc<Model>[]>
  • Retrieves multiple documents from a collection.

    You can specify a strategy to handle missing documents by passing the onMissing argument. By default, missing documents will throw an error. Other strategies:

    • By providing (id) => new MyModel(id, ...), you can provide a default value when a doc is missing
    • By providing 'ignore', missing documents are ignore and will be removed from the result
    • By providing (id) => throw new CustomError(id), you can throw a a custom error
    import { getMany, collection } from 'typesaurus'
    
    type User = { name: string }
    const users = collection<User>('users')
    
    getMany(users, ['00sHm46UWKObv2W7XK9e', '00sHm46UWKObv2W7XK0d']).then(user => {
      console.log(user)
      //=> [ { __type__: 'doc', data: { name: 'Sasha' }, ... }, { __type__: 'doc', data: { name: 'Thomas' }, ... }]
    })

    Type parameters

    • Model

    Parameters

    • collection: Collection<Model>
    • ids: keyof string[]
    • Default value onMissing: function | "ignore" = id => {throw new Error(`Missing document with id ${id}`)}

    Returns Promise<Doc<Model>[]>

    Promise to a list of found documents

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Type alias with type parameter
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc