Class: Omen::Query

Inherits:
Object
  • Object
show all
Defined in:
app/models/omen/query.rb

Overview

The one SELECT Claude wrote, held by Postgres and by what it grants the role running it.

Constant Summary collapse

UTC =

Rails writes every timestamp in UTC, which libpq would otherwise read as a local time.

{ oid: 1114, name: 'timestamp', format: 0 }

Instance Method Summary collapse

Constructor Details

#initialize(sql) ⇒ Query

Returns a new instance of Query.

Parameters:

  • sql (String)

    the statement Claude answered with.



7
8
9
# File 'app/models/omen/query.rb', line 7

def initialize(sql)
  @sql = sql
end

Instance Method Details

#answerHash

A savepoint, so a statement Postgres rejects leaves the surrounding transaction usable.

Returns:

  • (Hash)

    the rows, and the encrypted column each header of theirs came from.



13
14
15
16
17
18
19
# File 'app/models/omen/query.rb', line 13

def answer
  record.connected_to role: Omen.config.reading_role do
    record.transaction requires_new: true do
      record.with_connection { |connection| run connection }
    end
  end
end