SqbSingletonService
import { SqbSingletonService } from '@opra/sqb';
Hierarchy: ServiceBase → SqbServiceBase → SqbEntityService → SqbSingletonService
Constructor
new SqbSingletonService<T>(dataType: Type<T> | string, options?: SqbSingletonService.Options)
Properties
| Property | Type | Description |
|---|---|---|
id | SQBAdapter.IdOrIds | The 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.
| Option | Type | Default | Description |
|---|---|---|---|
id | SQBAdapter.IdOrIds | 1 | The identifier used to locate the singleton record |
CreateOptions
| Option | Type | Description |
|---|---|---|
projection | string | string[] | Fields to return in the created record. Omit for all fields. |
DeleteOptions
| Option | Type | Description |
|---|---|---|
filter | SQBAdapter.FilterInput | Additional filter expression. |
ExistsOptions
| Option | Type | Description |
|---|---|---|
filter | SQBAdapter.FilterInput | Additional filter expression. |
FindOneOptions
| Option | Type | Description |
|---|---|---|
filter | SQBAdapter.FilterInput | Additional filter expression. |
projection | string | string[] | Fields to include. |
sort | string[] | Sort directives, e.g. ['name', '-createdAt']. |
UpdateOneOptions
| Option | Type | Description |
|---|---|---|
projection | string | string[] | Fields to return in the updated record. |
filter | SQBAdapter.FilterInput | Additional filter expression for the update. |