Class: Aidp::Database::Repositories::StrategyRepository
- Inherits:
-
Aidp::Database::Repository
- Object
- Aidp::Database::Repository
- Aidp::Database::Repositories::StrategyRepository
- Defined in:
- lib/aidp/database/repositories/strategy_repository.rb
Instance Attribute Summary
Attributes inherited from Aidp::Database::Repository
Instance Method Summary collapse
- #find_by_name(name) ⇒ Object
-
#initialize(project_dir: Dir.pwd) ⇒ StrategyRepository
constructor
A new instance of StrategyRepository.
- #load(id) ⇒ Object
- #register(name:, spec:) ⇒ Object
Constructor Details
#initialize(project_dir: Dir.pwd) ⇒ StrategyRepository
Returns a new instance of StrategyRepository.
10 11 12 |
# File 'lib/aidp/database/repositories/strategy_repository.rb', line 10 def initialize(project_dir: Dir.pwd) super(project_dir: project_dir, table_name: "strategies") end |
Instance Method Details
#find_by_name(name) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/aidp/database/repositories/strategy_repository.rb', line 36 def find_by_name(name) row = query_one( "SELECT * FROM strategies WHERE project_dir = ? AND name = ? ORDER BY created_at DESC, rowid DESC", [project_dir, name] ) deserialize_strategy(row) end |
#load(id) ⇒ Object
31 32 33 34 |
# File 'lib/aidp/database/repositories/strategy_repository.rb', line 31 def load(id) row = query_one("SELECT * FROM strategies WHERE id = ? AND project_dir = ?", [id, project_dir]) deserialize_strategy(row) end |
#register(name:, spec:) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/aidp/database/repositories/strategy_repository.rb', line 14 def register(name:, spec:) strategy_id = Digest::SHA256.hexdigest("#{project_dir}:#{name}:#{spec}") # Concurrent sibling child workflows can register the identical # strategy at the same time (same deterministic strategy_id), so # the insert must be idempotent rather than a check-then-insert to # avoid a primary-key race between them. execute( "INSERT OR IGNORE INTO #{table_name} (id, project_dir, name, spec) VALUES (?, ?, ?, ?)", [strategy_id, project_dir, name, spec] ) Aidp.log_debug("strategy_repository", "registered", id: strategy_id, name: name) {id: strategy_id, name: name} end |