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, reading) ⇒ Query

Returns a new instance of Query.

Parameters:

  • sql (String) —

    the statement Claude answered with.

  • reading (Omen::Reading) —

    the one it answers, which says what it may read.



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

def initialize(sql, reading)
  @sql = sql
  @reading = reading
end

Instance Method Details

#answer ⇒ Hash

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.



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

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