Class: ClaudeMemory::Core::BatchLoader

Inherits:
Object
  • Object
show all
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

Class Method Details

.load_many(dataset, ids, group_by: :id) ⇒ Hash

Load multiple records by IDs and organize them by a key

Parameters:

  • dataset (Sequel::Dataset)

    The dataset to query

  • ids (Array)

    The IDs to load

  • group_by (Symbol) (defaults to: :id)

    How to organize results (:single for hash by ID, or column name for grouping)

Returns:

  • (Hash)

    Results organized by the specified 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