Module: Sequel::Plugins::PreparedStatementsWithPk::DatasetMethods

Defined in:
lib/sequel/plugins/prepared_statements_with_pk.rb

Instance Method Summary collapse

Instance Method Details

#with_pk(pk) ⇒ Object

Use a prepared statement to find a row with the matching primary key inside this dataset.



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/sequel/plugins/prepared_statements_with_pk.rb', line 49

def with_pk(pk)
  begin
    ds, bv = unbind
  rescue UnbindDuplicate
    super
  else
    begin
      bv = bv.merge!(model.primary_key_hash(pk)){|k, v1, v2| ((v1 == v2) ? v1 : raise(UnbindDuplicate))}
    rescue UnbindDuplicate
      super
    else
      ps = model.send(:prepared_lookup_dataset, ds)
      if server = @opts[:server]
        ps = ps.server(server)
      end
      ps.call(bv)
    end
  end
end