# new Sequence(seq)
A model class that represents a sequence in the RAM adapter. It stores the current value of a sequence that can be used for generating sequential identifiers for entities. The sequence is identified by its ID and maintains the current value.
RAM sequence model for auto-incrementing values
Parameters:
| Name | Type | Description |
|---|---|---|
seq |
ModelArg.<Sequence>
|
Initial sequence data |
Example
```typescript
// Create a new sequence
const orderSequence = new Sequence({ id: 'order_seq', current: 1 });
// Use the sequence to get the next value
const nextOrderId = parseInt(orderSequence.current.toString()) + 1;
orderSequence.current = nextOrderId;
```
Classes
- Sequence
Protected constructor that initializes the sequence with the provided options
- Sequence
Protected constructor that initializes the sequence with the provided options
Methods
# async current(args)
Gets the current value of the sequence from storage. If the sequence doesn't exist yet, it returns the configured starting value.
Retrieves the current value of the sequence
Parameters:
| Name | Type | Description |
|---|---|---|
args |
MaybeContextualArg.<any>
|
A promise that resolves to the current sequence value
# async protected increment(current, countopt)
Increases the current sequence value by the specified amount and persists the new value to storage. This method handles both numeric and BigInt sequence types.
Increments the sequence value
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
current |
string
|
number
|
bigint
|
The current value of the sequence |
|
count |
number
|
<optional> |
Optional amount to increment by, defaults to the sequence's incrementBy value |
A promise that resolves to the new sequence value after incrementing
# async next(argz)
Retrieves the current value of the sequence and increments it by the configured increment amount. This is the main method used to get a new sequential value.
Gets the next value in the sequence
Parameters:
| Name | Type | Description |
|---|---|---|
argz |
MaybeContextualArg.<any>
|
A promise that resolves to the next value in the sequence
# async range(count)
Retrieves a specified number of sequential values from the sequence. This is useful when you need to allocate multiple IDs at once. The method increments the sequence by the total amount needed and returns all values in the range.
Generates a range of sequential values
Parameters:
| Name | Type | Description |
|---|---|---|
count |
number
|
The number of sequential values to generate |
A promise that resolves to an array of sequential values
# static parseValue(type, value) → {string|number|bigint}
Converts a sequence value to the specified type (Number or BigInt)
Parses a sequence value to the appropriate type
Parameters:
| Name | Type | Description |
|---|---|---|
type |
"Number"
|
"BigInt"
|
undefined
|
The target type to convert to |
value |
string
|
number
|
bigint
|
The value to convert |
The converted value
string
|
number
|
bigint
# static pk(model) → {string}
Utility method that returns the standardized sequence name for a model's primary key
Gets the primary key sequence name for a model
Parameters:
| Name | Type | Description |
|---|---|---|
model |
M
|
Constructor.<M>
|
The model instance or constructor |
The sequence name for the model's primary key
string