Class: PG::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/eno/pg.rb

Constant Summary collapse

ESCAPER =
->(expr) {
  case expr
  when Symbol
    quote_ident(expr.to_s)
  when String
    "'#{escape(expr)}'"
  else
    nil # use default quoting
  end
}

Instance Method Summary collapse

Instance Method Details

#q(query = nil, **ctx, &block) ⇒ Object



17
18
19
20
# File 'lib/eno/pg.rb', line 17

def q(query = nil, **ctx, &block)
  query ||= Eno::Query.new(&block)
  exec(query_to_sql(query, **ctx))
end

#query_to_sql(query, **ctx) ⇒ Object



22
23
24
# File 'lib/eno/pg.rb', line 22

def query_to_sql(query, **ctx)
  query.to_sql(escape_proc: ESCAPER, **ctx)
end