Setu-TS
    Preparing search index...

    Interface IDatabaseService

    High-level database service combining repository access, unit of work, raw queries, and lifecycle management.

    0.1.0

    interface IDatabaseService {
        close(): Promise<void>;
        getRepository<Entity, Id extends EntityKey = string>(
            entity: string,
        ): IRepository<Entity, Id>;
        isHealthy(): Promise<boolean>;
        migrate(): Promise<void>;
        query<T>(sql: string, params?: unknown[]): Promise<T[]>;
        transaction<T>(
            work: (uow: IUnitOfWork) => Promise<T>,
            options?: TransactionOptions,
        ): Promise<T>;
    }

    Implemented by

    Index
    • Execute a raw SQL query and return results.

      Type Parameters

      • T

        Expected row shape

      Parameters

      • sql: string

        SQL query string

      • Optionalparams: unknown[]

        Query parameters (replaced positionally)

      Returns Promise<T[]>

      Query result rows

      0.1.0

    • Execute the work callback within a database transaction.

      On success the transaction commits and the callback result is returned. On error the transaction rolls back and the error propagates.

      Type Parameters

      • T

        Return type of the work callback

      Parameters

      • work: (uow: IUnitOfWork) => Promise<T>

        Function receiving a transaction-scoped Unit of Work

      • Optionaloptions: TransactionOptions

        Optional transaction settings, including requested isolation

      Returns Promise<T>

      The result of the work callback

      If the work callback throws — transaction is rolled back

      0.1.0