ApplicationBatchUpdater allows you to do basic configuration of batch update:

  • set search criteria;
  • save.

Type parameters

Hierarchy

Methods

all

  • all(): Promise<number>
  • The method runs a batch update.

    Returns the number of items that were actually updated according to ApplicationBatchUpdater.size, starting from [[ApplicationBatchUpdater. from]]. By default, the size of the updated items is limited to 10 entries. If you need to update more items, use the ApplicationBatchUpdater.size method.

    const searchResults = await Application.update()
        .set('str', _ => 'test') 
        .where((f, g) => g.and ( 
            f. __deletedAt.eq(null), 
            f.str.eq(null) 
        )) 
        .all(); 
    

    Returns Promise<number>

from

  • from(n: number): this
  • The method allows skipping the set number of updated items.

    Parameters

    • n: number

      Number of items to skip. For example, when working with a large number of app items, you can divide the update into separate batches and dynamically determine the start of each batch.

      Context.data.from += 100;
      const rows = await Application.batch() 
          .update() 
          .set('str', _ =>  'test') 
          .from(Context.data.from) 
          .where((f, g) => g.and ( 
               f.__deletedAt.eq(null), 
              f.str.eq(null) 
          )) 
          .all(); 
      

    Returns this

notify

  • notify(enabled: boolean): this
  • The method sets notifications for when app items are updated.

    Parameters

    • enabled: boolean

      If enabled is set to true, notifications are enabled. By default they are disabled. Important: enabling notifications when updating a large number of items can cause excessive load on the system. For each item, an update event will be created that is then processed in the system in general order.

      const rows = await Application.batch(). update().set('str', _ => 'test')
         .notify(true) 
         .all(); 
      

    Returns this

set

  • set<K>(f: K, v: UpdateClosure<UpdatableItem<TFull>, RemoveIndex<T>[K]>): ApplicationBatchUpdater<TFull, Omit<RemoveIndex<T>, K>, P>
  • The method allows setting rules for updating fields of app items in a collection.

    Type parameters

    • K: keyof UpdatableItem<T>

    Parameters

    • f: K

      Name of the app item field that is being updated.

    • v: UpdateClosure<UpdatableItem<TFull>, RemoveIndex<T>[K]>

      Value of the updated field.

      const rows = await Application. batch()
          .update() 
          .set('str0', _ => 'test') 
          .set('str1', f =>  f.str) 
          .set('str2', (f, op) => op.concat(f.str0, '+', f.str1)) 
          . all(); 
      

    Returns ApplicationBatchUpdater<TFull, Omit<RemoveIndex<T>, K>, P>

size

  • size(n: number): this
  • The method allows to limit the number of updated items.

    Parameters

    • n: number

      Batch size (default size is 10, the max size is 10000).

      const rows = await Application.batch()
          .update() 
          .set('str', _ =>  'test') 
          .size(500) 
          .where((f, g) => g.and ( 
              f.__deletedAt. eq(null), 
              f.str.eq(null) 
          )) 
          .all(); 
      

    Returns this

where

  • where(fc: FilterClosure<TFull>): this
  • The method allows setting filtering for updated app items in a collection.

    Parameters

    • fc: FilterClosure<TFull>

      Search filters.

      const rows = await Application.batch()
          . update() 
          .set('str', _ => 'test') 
          .where((f, g) => g.and (  
              f.__deletedAt.eq(null), 
              f.str.eq(null) 
          )) 
          .all();  
      

    Returns this