ubs_numcounter_ns

@unitybase/ubs~ ubs_numcounter_ns

Registration key counter

Constructor

new ubs_numcounter_ns()

Mixes In:
mStorage   

Extends

Members

attrs static

Attributes defined in metadata. This property not exist in real life and added just for help

entity: UBEntity

Reference to entity metadata

Methods

addNew(ctx) api

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:
  1. ctx (ubMethodParams)
Mixes In:
mStorage.addNew   

delete(ctx) api

Delete data
Arguments:
  1. ctx (ubMethodParams)
    Properties
    1. mParams.execParams.ID (number)  element ID to be deleted
Mixes In:
mStorage.delete   

insert(ctx) api

Insert new row to the entity.
Arguments:
  1. ctx (ubMethodParams)
    Properties
    1. mParams.execParams (Object|TubList)  Object keys is entity attributes names, key values is a value to be inserted
Mixes In:
mStorage.insert   

select(ctx) api

Read entity data
Arguments:
  1. ctx (ubMethodParams)
    Properties
    1. mParams (UBQL)  ORM query in UBQL format
Mixes In:
mStorage.select   

update(ctx) api

Update data
Arguments:
  1. ctx (ubMethodParams)
    Properties
    1. mParams.execParams (Object|TubList)  Object keys is entity attributes names, key values is a value to be inserted
      Properties
      1. ID (number)  element ID to be updated
Mixes In:
mStorage.update   

generateAutoIncrementalCode(ctx, forAttributeopt)

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:
  1. ctx (ubMethodParams)
    Properties
    1. mParams.entity (string)
    2. mParams.execParams (TubList|Object)
  2. [forAttribute='code'] (string)  Code of attribute for number generation
Example
const me = cdn_profession
me.on('insert:before', generateAutoIncrementalCode)

function generateAutoIncrementalCode (ctx) {
  ubs_numcounter.generateAutoIncrementalCode(ctx, 'code')
}

//or even simple if attribute name is `code`
me.on('insert:before', ubs_numcounter.generateAutoIncrementalCode)

getRegnum(regKeyValue, startNumopt, skipReservedNumberopt)Number

Return counter number by mask
Arguments:
  1. regKeyValue (String)  Registration key mask
  2. [startNum] (Number)  The starting counter value in case mask not exists
  3. [skipReservedNumber=false] (Boolean)  When "true" skip loading number from reserve and calculate new number by mask

getRegnumCounter(ctxt) api

Get counter value by registration key
Arguments:
  1. ctxt (ubMethodParams)
    Properties
    1. mParams.execParams.regkey (string)
    2. mParams.execParams.skipReservedNumber (boolean)  Skip loading number from reserve and calculate new number by mask