Skip to main content

SqbSingletonService

import { SqbSingletonService } from '@opra/sqb';

Hierarchy: ServiceBase → SqbServiceBase → SqbEntityService → SqbSingletonService


Constructor​

new SqbSingletonService<T>(dataType: Type<T> | string, options?: SqbSingletonService.Options)

Properties​

PropertyTypeDescription
idSQBAdapter.IdOrIdsThe identifier used to locate the singleton record (default: 1)

Methods​

assert​

assert(options?: ExistsOptions): Promise<void>

Throws ResourceNotAvailableError if the singleton record does not exist.

options — ExistsOptions


create​

create(input: PartialDTO<T>, options: RequiredSome<CreateOptions, 'projection'>): Promise<PartialDTO<T>>
create(input: PartialDTO<T>, options?: CreateOptions): Promise<T>

Creates the singleton record and returns it.

options — CreateOptions


delete​

delete(options?: DeleteOptions): Promise<number>

Deletes the singleton record. Returns the number of deleted records.

options — DeleteOptions


exists​

exists(options?: ExistsOptions): Promise<boolean>

Returns true if the singleton record exists.

options — ExistsOptions


find​

find(options: RequiredSome<FindOneOptions, 'projection'>): Promise<PartialDTO<T> | undefined>
find(options?: FindOneOptions): Promise<T | undefined>

Fetches the singleton record. Returns undefined if it does not exist.

options — FindOneOptions


get​

get(options: RequiredSome<FindOneOptions, 'projection'>): Promise<PartialDTO<T>>
get(options?: FindOneOptions): Promise<T>

Fetches the singleton record. Throws ResourceNotAvailableError if it does not exist.

options — FindOneOptions


update​

update(input: PatchDTO<T, SqlElement>, options: RequiredSome<UpdateOneOptions, 'projection'>): Promise<PartialDTO<T> | undefined>
update(input: PatchDTO<T, SqlElement>, options?: UpdateOneOptions): Promise<T | undefined>

Applies a partial update to the singleton record and returns it. Returns undefined if it does not exist.

options — UpdateOneOptions


updateOnly​

updateOnly(input: PatchDTO<T, SqlElement>, options?: UpdateOneOptions): Promise<number>

Same as update but does not fetch and return the updated record. Returns the number of matched records.

options — UpdateOneOptions


Interfaces​

SqbSingletonService.Options​

Extends SqbEntityService.Options.

OptionTypeDefaultDescription
idSQBAdapter.IdOrIds1The identifier used to locate the singleton record

CreateOptions​

OptionTypeDescription
projectionstring | string[]Fields to return in the created record. Omit for all fields.

DeleteOptions​

OptionTypeDescription
filterSQBAdapter.FilterInputAdditional filter expression.

ExistsOptions​

OptionTypeDescription
filterSQBAdapter.FilterInputAdditional filter expression.

FindOneOptions​

OptionTypeDescription
filterSQBAdapter.FilterInputAdditional filter expression.
projectionstring | string[]Fields to include.
sortstring[]Sort directives, e.g. ['name', '-createdAt'].

UpdateOneOptions​

OptionTypeDescription
projectionstring | string[]Fields to return in the updated record.
filterSQBAdapter.FilterInputAdditional filter expression for the update.