interface IRepository
Since 0.1.0

Generic repository providing CRUD operations over an entity type.

Type Parameters

Entity

The entity shape the repository manages

Id extends EntityKey = string

Primary key type, constrained to EntityKey (scalar string/number or composite record). Defaults to string.

Methods

Since 0.1.0
findById(id: Id): Promise<Entity | null>

Fetch a single entity by its primary key.

Since 0.1.0
findAll(options?: FindOptions): Promise<Entity[]>

Fetch entities with optional filtering, sorting, and pagination.

Since 0.2.0
findOne(options?: FindOptions): Promise<Entity | null>

Fetch the first entity matching the optional filter.

Since 0.1.0
create(data: Partial<Entity>): Promise<Entity>

Insert a new entity.

Since 0.1.0
update(
id: Id,
data: Partial<Entity>
): Promise<Entity>

Update an existing entity by primary key.

Since 0.1.0
delete(id: Id): Promise<boolean>

Delete an entity by primary key.

Since 0.1.0
exists(id: Id): Promise<boolean>

Check whether an entity with the given primary key exists.

Since 0.1.0
count(options?: CountOptions): Promise<number>

Count entities with optional filtering.

Since 0.2.0
findPage(options: PageOptions): Promise<Page<Entity>>

Find a page of entities by cursor pagination.

Usage

import { type IRepository } from "database-plugin/src/index.ts";