Class: ClaudeMemory::Core::BatchLoader
- Inherits:
-
Object
- Object
- ClaudeMemory::Core::BatchLoader
- Defined in:
- lib/claude_memory/core/batch_loader.rb
Overview
Utility for batch loading records from Sequel datasets Eliminates duplication of batch query patterns
Class Method Summary collapse
-
.load_many(dataset, ids, group_by: :id) ⇒ Hash
Load multiple records by IDs and organize them by a key.
Class Method Details
.load_many(dataset, ids, group_by: :id) ⇒ Hash
Load multiple records by IDs and organize them by a key
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/claude_memory/core/batch_loader.rb', line 14 def self.load_many(dataset, ids, group_by: :id) return {} if ids.empty? results = dataset.where(id: ids).all case group_by when :single # Single record per ID (hash by ID) results.each_with_object({}) { |row, hash| hash[row[:id]] = row } when Symbol # Multiple records per key (grouped) results.group_by { |row| row[group_by] } else raise ArgumentError, "Invalid group_by: #{group_by.inspect}" end end |