Skip to content

Feature Request: Support for Auto-Incrementing Document IDs #28

@josh4500

Description

@josh4500

I propose adding a mechanism within Collection to support simple, auto-incrementing integer IDs for documents.

Currently, adding a document to a Collection requires the developer to manually provide a unique String ID. For use cases like local storage of log-like data or traditional list-based models, this is cumbersome. Developers must implement boilerplate code to find the maximum existing ID and increment it, which is both inefficient and prone to race conditions if not handled carefully.

Proposed Solution
Add a new IdGenerationStrategy enum to the add method. When specified, the system will automatically generate and assign a simple, sequential integer ID.

We could have something like this below

Loon.collection<T>(
  ...,
  idGenerationStrategy: IdGenerationStrategy.autoIncrement
);

Motivation came from my working with a SearchQueryModel where the insertion order matters, and I don't need to compute the ID before storing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions