Skip to content

Latest commit

 

History

History
35 lines (24 loc) · 854 Bytes

File metadata and controls

35 lines (24 loc) · 854 Bytes

Enforce Repository Pattern for Data Access

Status

Accepted

Context

Services make direct database queries (this.db('follows').select(...)) instead of using repositories, violating separation of concerns.

Decision

Services must use repositories for ALL data access. No direct database queries in services.

Implementation

// Repository handles all data access
class AccountRepository {
  async getFollowers(accountId: number) {
    return await this.db('follows')
      .join('accounts', 'accounts.id', 'follows.follower_id')
      .where('follows.following_id', accountId);
  }
}

// Service uses repository
class AccountService {
  constructor(private readonly accountRepository: AccountRepository) {}

  async getFollowers(accountId: number) {
    return await this.accountRepository.getFollowers(accountId);
  }
}