Options
All
  • Public
  • Public/Protected
  • All
Menu

The batch API object. It unions a set of functions (set, update, remove) that are similar to regular set, update and remove with the only difference that the batch counterparts do not return a promise and perform operations only when commit function is called.

Hierarchy

  • Batch

Index

Methods

commit

  • commit(): Promise<void>
  • Starts the execution of the operations in the batch.

    Returns Promise<void>

    A promise that resolves when the operations are finished

remove

  • remove<Model>(collection: Collection<Model>, id: string): void
  • remove<Model>(ref: Ref<Model>): void
  • Removes a document.

    import { batch, collection } from 'typesaurus'
    
    type Counter = { count: number }
    const counters = collection<Counter>('counters')
    
    const { remove, commit } = batch()
    
    for (let count = 0; count < 500; count++) {
      remove(counters, count.toString())
    }
    
    commit()

    Type parameters

    • Model

    Parameters

    • collection: Collection<Model>

      The collection to remove document in

    • id: string

      The id of the documented to remove

    Returns void

    A promise that resolves when the operation is complete

  • Type parameters

    • Model

    Parameters

    • ref: Ref<Model>

      The reference to the document to remove

    Returns void

set

  • Sets a document to the given data.

    import { batch, collection } from 'typesaurus'
    
    type Counter = { count: number }
    const counters = collection<Counter>('counters')
    
    const { set, commit } = batch()
    
    for (let count = 0; count < 500; count++) {
      set(counters, count.toString(), { count })
    }
    
    commit()

    Type parameters

    • Model

    Parameters

    • ref: Ref<Model>

      The reference to the document to set

    • data: SetModel<Model>

      The document data

    Returns void

  • Type parameters

    • Model

    Parameters

    • collection: Collection<Model>

      The collection to set document in

    • id: string

      The id of the document to set

    • data: SetModel<Model>

      The document data

    Returns void

update

  • update<Model>(collection: Collection<Model>, id: string, data: Field<Model>[]): void
  • update<Model>(ref: Ref<Model>, data: Field<Model>[]): void
  • update<Model>(collection: Collection<Model>, id: string, data: UpdateModel<Model>): void
  • update<Model>(ref: Ref<Model>, data: UpdateModel<Model>): void
  • Updates a document.

    import { batch, field, collection } from 'typesaurus'
    
    type Counter = { count: number, meta: { updatedAt: number } }
    const counters = collection<Counter>('counters')
    
    const { update, commit } = batch()
    
    for (let count = 0; count < 500; count++) {
      update(counters, count.toString(), { count: count + 1 })
      // or using field paths:
      update(counters, count.toString(), [
        field('count', count + 1),
        field(['meta', 'updatedAt'], Date.now())
      ])
    }
    
    commit()

    Type parameters

    • Model

    Parameters

    • collection: Collection<Model>

      The collection to update document in

    • id: string

      The id of the document to update

    • data: Field<Model>[]

      The document data to update

    Returns void

    void

  • Type parameters

    • Model

    Parameters

    • ref: Ref<Model>

      The reference to the document to set

    • data: Field<Model>[]

      The document data to update

    Returns void

  • Type parameters

    • Model

    Parameters

    • collection: Collection<Model>

      The collection to update document in

    • id: string

      The id of the document to update

    • data: UpdateModel<Model>

      The document data to update

    Returns void

  • Type parameters

    • Model

    Parameters

    • ref: Ref<Model>

      The reference to the document to set

    • data: UpdateModel<Model>

      The document data to update

    Returns void

upset

  • Sets or updates a document with the given data.

    import { batch, collection } from 'typesaurus'
    
    type Counter = { count: number }
    const counters = collection<Counter>('counters')
    
    const { upset, commit } = batch()
    
    for (let count = 0; count < 500; count++) {
      upset(counters, count.toString(), { count })
    }
    
    commit()

    Type parameters

    • Model

    Parameters

    • ref: Ref<Model>

      The reference to the document to set or update

    • data: UpsetModel<Model>

      The document data

    Returns void

  • Type parameters

    • Model

    Parameters

    • collection: Collection<Model>

      The collection to set or update document in

    • id: string

      The id of the document to set or update

    • data: UpsetModel<Model>

      The document data

    Returns void

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