UNPKG

arvox-backend

Version:

Un framework backend moderne et modulaire basé sur Hono, TypeScript et l'architecture hexagonale avec authentification Better Auth + Drizzle intégrée

81 lines 2.85 kB
/** * Base repository class providing common database operations * Uses generic types to ensure type safety across all repositories */ export class BaseRepository { /** * Check if entity exists by ID * @param id - Entity identifier * @returns Promise with boolean indicating existence */ async exists(id) { const entity = await this.findById(id); return entity !== null; } /** * Find entities by IDs * @param ids - Array of entity identifiers * @returns Promise with array of found entities */ async findByIds(ids) { const entities = await Promise.all(ids.map(id => this.findById(id))); return entities.filter(entity => entity !== null); } /** * Soft delete entity (if supported by implementation) * @param id - Entity identifier * @returns Promise with boolean indicating success */ async softDelete(id) { // Default implementation - override in child classes if soft delete is supported return this.delete(id); } /** * Restore soft deleted entity (if supported by implementation) * @param id - Entity identifier * @returns Promise with restored entity or null */ async restore(_id) { // Default implementation - override in child classes if restoration is supported throw new Error('Restore operation not implemented'); } /** * Find entities with search functionality * @param searchTerm - Search term * @param searchFields - Fields to search in * @param pagination - Optional pagination * @returns Promise with search results */ async findWithSearch(_searchTerm, _searchFields, _pagination) { // Default implementation - override in child classes for custom search logic throw new Error('Search operation not implemented'); } /** * Create multiple entities in batch * @param dataArray - Array of creation data * @returns Promise with array of created entities */ async batchCreate(dataArray) { const entities = await Promise.all(dataArray.map(data => this.create(data))); return entities; } /** * Update multiple entities in batch * @param updates - Array of update objects with id and data * @returns Promise with array of updated entities */ async batchUpdate(updates) { const entities = await Promise.all(updates.map(update => this.update(update.id, update.data))); return entities; } /** * Delete multiple entities in batch * @param ids - Array of entity identifiers * @returns Promise with success status */ async batchDelete(ids) { await Promise.all(ids.map(id => this.delete(id))); return true; } } //# sourceMappingURL=base-repository.js.map