SqbEntityService
SqbEntityService<T> is an abstract class that sits between SqbServiceBase and the concrete service classes. It adds the CRUD database primitives, the interceptor-aware command execution loop, and the lifecycle hooks used by SqbCollectionService and SqbSingletonService.
You do not extend it directly. Extend SqbCollectionService or SqbSingletonService instead.
import { SqbEntityService } from '@opra/sqb';
Hierarchy: ServiceBase → SqbServiceBase → SqbEntityService
Lifecycle hooks
Override these in SqbCollectionService or SqbSingletonService subclasses. The base implementations are no-ops.
| Hook | Signature |
|---|---|
_beforeCreate(command) | (CreateCommand<T>) => Promise<void> |
_afterCreate(command, result) | (CreateCommand<T>, PartialDTO<T>) => Promise<void> |
_beforeUpdate(command) | (UpdateOneCommand<T>) => Promise<void> |
_afterUpdate(command, result) | (UpdateOneCommand<T>, PartialDTO<T> | undefined) => Promise<void> |
_beforeUpdateMany(command) | (UpdateManyCommand<T>) => Promise<void> |
_afterUpdateMany(command, affected) | (UpdateManyCommand<T>, number) => Promise<void> |
_beforeDelete(command) | (DeleteOneCommand) => Promise<void> |
_afterDelete(command, affected) | (DeleteOneCommand, number) => Promise<void> |
_beforeDeleteMany(command) | (DeleteManyCommand) => Promise<void> |
_afterDeleteMany(command, affected) | (DeleteManyCommand, number) => Promise<void> |
Interfaces
SqbEntityService.Options
Extends SqbServiceBase.Options.
| Option | Type | Description |
|---|---|---|
resourceName | string | ((_this) => string) | Resource name used in error messages and API metadata |
scope | string | Comma-delimited scopes used to filter the API document |
commonFilter | CommonFilter | CommonFilter[] | Filter(s) automatically applied to every read and write operation |
interceptor | (next, command, _this) => Promise<any> | Wraps every operation — useful for logging, tracing, or access control |
onError | (error, command, _this) => void | Promise<void> | Called whenever a command throws |
SqbEntityService.CrudOp
type CrudOp = 'create' | 'read' | 'update' | 'delete';
SqbEntityService.CommandInfo
Passed to every lifecycle hook and interceptor.
| Property | Type | Description |
|---|---|---|
crud | CrudOp | The CRUD category of the operation |
method | string | The method name (e.g. 'findMany', 'update') |
byId | boolean | Whether the operation targets a specific record by ID |
documentId | IdOrIds | The record identifier, if applicable |
input | any | The input payload, if applicable |
options | any | The operation options |
SqbEntityService.CommonFilter
type CommonFilter =
| SQBAdapter.FilterInput
| ((args: CommandInfo, _this: SqbEntityService<any>) =>
SQBAdapter.FilterInput | Promise<SQBAdapter.FilterInput> | undefined);
A static filter or a function computed per request. Applied automatically to every operation alongside any method-level filter option.
Command interfaces
Command objects are passed to lifecycle hooks. Each interface extends CommandInfo and narrows the crud discriminant.
CreateCommand<T>
| Property | Type |
|---|---|
crud | 'create' |
input | PatchDTO<T> |
options | CreateOptions |
CountCommand
| Property | Type |
|---|---|
crud | 'read' |
options | CountOptions |
DeleteOneCommand
| Property | Type |
|---|---|
crud | 'delete' |
documentId | IdOrIds |
options | DeleteOptions |
DeleteManyCommand
| Property | Type |
|---|---|
crud | 'delete' |
options | DeleteManyOptions |
ExistsCommand
| Property | Type |
|---|---|
crud | 'read' |
documentId | IdOrIds (optional) |
options | ExistsOptions |
FindOneCommand
| Property | Type |
|---|---|
crud | 'read' |
documentId | IdOrIds (optional) |
options | FindOneOptions |
FindManyCommand
| Property | Type |
|---|---|
crud | 'read' |
options | FindManyOptions |
UpdateOneCommand<T>
| Property | Type |
|---|---|
crud | 'update' |
documentId | IdOrIds (optional) |
input | PatchDTO<T, SqlElement> |
options | UpdateOneOptions |
UpdateManyCommand<T>
Same shape as UpdateOneCommand<T> but without documentId.