Registration key counter

Mixes In:

# new ubs_numcounter_ns ()

Members

# attrs : ubsNumcounterAttrs static

Attributes defined in metadata. Property does not exist in real life and added for IDE

# entity : UBEntity instance

Reference to entity metadata

Methods

# addNew (ctxubMethodParams) instance

Create record with filled default values and return it to caller. Newly created record is not inserted to database. For inserting record to the database insert method should be called

Arguments:

# delete (ctxubMethodParams) instance

Delete record by ID

Arguments:

# insert (ctxubMethodParams) instance

New record insertion

Arguments:

# select (ctxubMethodParams) instance

ORM query for read records

Arguments:

# update (ctxubMethodParams) instance

Update existed record

Arguments:
  • ctx: ubMethodParams
    • mParamsobject

      Update method parameters

    • fieldListarray.<string>

      Optional attributes names. Values of this attributes will be returned in result. Additional DB query is required to return values, so if caller do not need it better to not pass a fieldList to update

# generateAutoIncrementalCode (ctxubMethodParams, forAttributeoptstring) instance

Generate auto incremental code for specified entity attribute in case attribute value in execParams is empty or equal to attribute default value, specified in meta file.

Will create a numcounter with code === entity.name and 1 as initial value.

Result value will be left padded by '0' to the length specified in ubs_settings To be used in insert:before handler as

Arguments:
  
      cdn_profession.on('insert:before', generateAutoIncrementalCode)

function generateAutoIncrementalCode (ctx) {
  ubs_numcounter.generateAutoIncrementalCode(ctx, 'code')
}
//or even simple if attribute name is `code`
cdn_profession.on('insert:before', ubs_numcounter.generateAutoIncrementalCode)
  

# getRegnum (regKeyValuestring, startNumoptnumber, skipReservedNumberoptboolean) → number instance

Returns the counter number by mask. Locks the row in the ubs_numcouner table until the transaction is committed, so other transactions will wait, but guarantees that the returned number is incremented continuously, without gaps.

In case gaps are allowed by business logic, better to use ubs_numcounter.getRegnumLoosely - it's lock the ubs_numcouner very rarely and much faster because of in-memory cache

Return:

Next number for this mask

Arguments:
  • regKeyValue: string

    Registration key mask

  • startNum: number

    The starting counter value in case mask not exists

  • skipReservedNumber = false: boolean

    When "true" skip loading number from reserve and calculate new number by mask

# getRegnumCounter (ctxubMethodParams) → boolean instance

Get counter value by registration key. If both skipReservedNumber and loosely is true - use loosely non-blocking algo

Arguments:

# getRegnumLoosely (regKeyValuestring, startNumoptnumber) → number instance

Returns the counter number by mask with possible gaps in the sequence byt faster when getRegnum. In -dev mode fallback to getRegnum

Return:

Next number for this mask

Arguments:
  • regKeyValue: string

    Registration key mask

  • startNum = 0: number

    The starting counter value in case mask not exists