Module: OpalORM::Searchable

Included in:
SQLObject
Defined in:
lib/opal_orm/searchable.rb

Instance Method Summary collapse

Instance Method Details

#where(params) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/opal_orm/searchable.rb', line 5

def where(params)
  where_clause = params.keys.map do |key|
    "#{key.to_s} = ?"
  end.join(" AND ")
  results = DBConnection.execute(<<-SQL,params.values)
  SELECT
    *
  FROM
    #{table_name}
  WHERE
    #{where_clause}
  SQL
  results.map { |res| new(res)}
end