Registration key counter
# 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 (ctx: ubMethodParams) 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:
ctx
: ubMethodParamsmParams
: objectOptional values for attributes of new record
# delete (ctx: ubMethodParams) instance
Delete record by ID
Arguments:
ctx
: ubMethodParamsmParams
: objectDelete method parameters
# insert (ctx: ubMethodParams) instance
New record insertion
Arguments:
ctx
: ubMethodParamsmParams
: objectInsert method parameters
# select (ctx: ubMethodParams) instance
ORM query for read records
Arguments:
ctx
: ubMethodParamsmParams
: UBQLORM query in UBQL format
# update (ctx: ubMethodParams) instance
Update existed record
Arguments:
ctx
: ubMethodParams
# generateAutoIncrementalCode (ctx: ubMethodParams, forAttributeopt: string) 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:
ctx
: ubMethodParamsforAttribute
= 'code': stringCode of attribute for number generation
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 (regKeyValue: string, startNumopt: number, skipReservedNumberopt: boolean) → 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
# getRegnumCounter (ctx: ubMethodParams) → boolean instance
Get counter value by registration key. If both skipReservedNumber
and loosely
is true - use loosely non-blocking algo
Arguments:
ctx
: ubMethodParams
# getRegnumLoosely (regKeyValue: string, startNumopt: number) → 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