Sha256: 4ce9ac96f3b805ff75eae6755c9fc956ffe84113b17a2d925bf5be021e1a271e

Contents?: true

Size: 449 Bytes

Versions: 1

Compression:

Stored size: 449 Bytes

Contents

# frozen_string_literal: true

require 'pg'

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

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

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
eno-0.5 lib/eno/pg.rb