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 contracts/FabricContractSequence.ts, line 4

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();
```