class BaseRepository
implements IRepository<Entity, Id>
Since 0.1.0

Shared repository implementation that normalizes options and delegates data operations to a DataSource.

Subclassing is intentional here: adapter-specific repositories extend this class and provide their own DataSource wire-up.

Constructors

BaseRepository(_dataSource: DataSource)

Creates a new repository instance.

Parameters
_dataSource: DataSource

Type Parameters

Entity

Entity shape

Id extends EntityKey = string

Primary key type, constrained to EntityKey

Methods

protected
coerceId(id: Id): EntityKey

Cast the entity id to the type the adapter expects.

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

Count entities with optional filtering.

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

Insert a new entity.

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
findAll(options?: FindOptions): Promise<Entity[]>

Fetch entities with optional filtering, sorting, and pagination.

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

Fetch a single entity by its primary key.

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

Find the first entity that matches the supplied query options.

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

Find a page of entities by cursor pagination.

Refuses by name with UnsupportedQueryFeatureError when the bound data source does not expose a findPage member — which is true for every shipped adapter until the milestone that implements cursor paging on that backend. Absence means "cannot page by cursor", never "there are no more rows".

protected
toEntity(row: Partial<Record<string, unknown>>): Entity

Cast a raw row to the typed Entity.

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

Update an existing entity by primary key.

Usage

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