Module: ViewData::PG::Controls::Row::Get

Defined in:
lib/view_data/pg/controls/row/get.rb

Defined Under Namespace

Modules: CompositePrimaryKey

Class Method Summary collapse

Class Method Details

.call(primary_key, table: nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/view_data/pg/controls/row/get.rb', line 6

def self.call(primary_key, table: nil)
  table ||= Table.name

  session = Session.build

  result = session.execute(<<~SQL, [primary_key])
    SELECT * FROM #{table} WHERE id = $1 LIMIT 1
  SQL

  session.close

  result.to_a[0]
end