# new RamSequence(options, adapter)
Extends the base Sequence class to provide auto-incrementing sequence functionality for the RAM adapter. This class manages sequences stored in memory, allowing for the generation of sequential identifiers for entities.
RAM-specific sequence implementation
Parameters:
Name | Type | Description |
---|---|---|
options |
SequenceOptions
|
Configuration options for the sequence |
adapter |
RamAdapter
|
The RAM adapter instance to use for storage |
Example
```typescript
// Create a new numeric sequence starting at 1
const sequence = new RamSequence({
name: 'order_sequence',
type: 'Number',
startWith: 1,
incrementBy: 1
}, ramAdapter);
// Get the next value in the sequence
const nextId = await sequence.next();
// Get a range of values
const idRange = await sequence.range(5); // Returns 5 sequential values
```
Methods
# async current()
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
A promise that resolves to the current sequence value
# async 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()
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
A promise that resolves to the next value in the sequence
# parse(value) → {string|number|bigint}
Converts a value to the appropriate type for the sequence (string, number, or bigint) using the base Sequence class's parseValue method.
Parses a value according to the sequence type
Parameters:
Name | Type | Description |
---|---|---|
value |
string
|
number
|
bigint
|
The value to parse |
The parsed value in the correct type
string
|
number
|
bigint
# 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