Class: LlmCostTracker::Storage::ActiveRecordRollupUpsertSql

Inherits:
Object
  • Object
show all
Defined in:
lib/llm_cost_tracker/storage/active_record_rollup_upsert_sql.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model) ⇒ ActiveRecordRollupUpsertSql

Returns a new instance of ActiveRecordRollupUpsertSql.



12
13
14
# File 'lib/llm_cost_tracker/storage/active_record_rollup_upsert_sql.rb', line 12

def initialize(model)
  @model = model
end

Class Method Details

.call(model) ⇒ Object



8
9
10
# File 'lib/llm_cost_tracker/storage/active_record_rollup_upsert_sql.rb', line 8

def self.call(model)
  new(model).call
end

Instance Method Details

#callObject



16
17
18
19
20
21
# File 'lib/llm_cost_tracker/storage/active_record_rollup_upsert_sql.rb', line 16

def call
  return Arel.sql(mysql_sql) if ActiveRecordAdapter.mysql?(connection)
  return Arel.sql(postgres_sql) if ActiveRecordAdapter.postgresql?(connection)

  Arel.sql("total_cost = total_cost + excluded.total_cost, updated_at = excluded.updated_at")
end