Skip to main content

SqbSingletonService

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

Hierarchy: ServiceBaseSqbServiceBaseSqbEntityServiceSqbSingletonService


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.

optionsExistsOptions


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.

optionsCreateOptions


delete

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

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

optionsDeleteOptions


exists

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

Returns true if the singleton record exists.

optionsExistsOptions


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.

optionsFindOneOptions


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.

optionsFindOneOptions


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.

optionsUpdateOneOptions


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.

optionsUpdateOneOptions


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.