Class

Sequence

Sequence(options)

Constructor

# new Sequence(options)

Provides a framework for generating sequential values (like primary keys) in the persistence layer. Implementations of this class handle the specifics of how sequences are stored and incremented in different database systems.

Abstract base class for sequence generation

Parameters:
Name Type Description
options SequenceOptions

Configuration options for the sequence generator

View Source persistence/Sequence.ts, line 5

Example
```typescript
// Example implementation for a specific database
class PostgresSequence extends Sequence {
  constructor(options: SequenceOptions) {
    super(options);
  }

  async next(): Promise<number> {
    // Implementation to get next value from PostgreSQL sequence
    const result = await this.options.executor.raw(`SELECT nextval('${this.options.name}')`);
    return parseInt(result.rows[0].nextval);
  }

  async current(): Promise<number> {
    // Implementation to get current value from PostgreSQL sequence
    const result = await this.options.executor.raw(`SELECT currval('${this.options.name}')`);
    return parseInt(result.rows[0].currval);
  }

  async range(count: number): Promise<number[]> {
    // Implementation to get a range of values
    const values: number[] = [];
    for (let i = 0; i < count; i++) {
      values.push(await this.next());
    }
    return values;
  }
}

// Usage
const sequence = new PostgresSequence({
  name: 'user_id_seq',
  executor: dbExecutor
});

const nextId = await sequence.next();
```

Classes

Sequence

Protected constructor that initializes the sequence with the provided options

Sequence

Protected constructor that initializes the sequence with the provided options

Members

# log

Gets or initializes the logger for this sequence

Accessor for the logger instance

View Source persistence/Sequence.ts, line 63

# logger

Lazily initialized logger for the sequence instance

Logger instance for this sequence

View Source persistence/Sequence.ts, line 57

Methods

# abstract current()

Retrieves the current value of the sequence without incrementing it

Gets the current value of the sequence

View Source persistence/Sequence.ts, line 156

A promise that resolves to the current value in the sequence

# protected log() → {Logger}

Gets or initializes the logger for this sequence

Accessor for the logger instance

View Source persistence/Sequence.ts, line 131

The logger instance

Logger

# abstract next()

Retrieves the next value from the sequence, incrementing it in the process

Gets the next value in the sequence

View Source persistence/Sequence.ts, line 148

A promise that resolves to the next value in the sequence

# abstract range(count)

Retrieves multiple sequential values at once, which can be more efficient than calling next() multiple times

Gets a range of sequential values

Parameters:
Name Type Description
count number

The number of sequential values to retrieve

View Source persistence/Sequence.ts, line 165

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

View Source persistence/Sequence.ts, line 183

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

View Source persistence/Sequence.ts, line 174

The sequence name for the model's primary key

string

Sequence(seq)

Constructor

# 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

View Source ram/model/RamSequenceModel.ts, line 11

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

Members

# log

Gets or initializes the logger for this sequence

Accessor for the logger instance

View Source persistence/Sequence.ts, line 63

# logger

Lazily initialized logger for the sequence instance

Logger instance for this sequence

View Source persistence/Sequence.ts, line 57

Methods

# abstract current()

Retrieves the current value of the sequence without incrementing it

Gets the current value of the sequence

View Source persistence/Sequence.ts, line 156

A promise that resolves to the current value in the sequence

# protected log() → {Logger}

Gets or initializes the logger for this sequence

Accessor for the logger instance

View Source persistence/Sequence.ts, line 131

The logger instance

Logger

# abstract next()

Retrieves the next value from the sequence, incrementing it in the process

Gets the next value in the sequence

View Source persistence/Sequence.ts, line 148

A promise that resolves to the next value in the sequence

# abstract range(count)

Retrieves multiple sequential values at once, which can be more efficient than calling next() multiple times

Gets a range of sequential values

Parameters:
Name Type Description
count number

The number of sequential values to retrieve

View Source persistence/Sequence.ts, line 165

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

View Source persistence/Sequence.ts, line 183

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

View Source persistence/Sequence.ts, line 174

The sequence name for the model's primary key

string