Sha256: 927595d46ea5ae3085e675db245f7d205aa7f543f81101d66832e4b89a15fc37
Contents?: true
Size: 1.47 KB
Versions: 5
Compression:
Stored size: 1.47 KB
Contents
# frozen_string_literal: true module PgEasyReplicate class Query extend Helper class << self def run( query:, connection_url:, user: internal_user_name, schema: nil, transaction: true, using_vacuum_analyze: false ) conn = connect(connection_url: connection_url, schema: schema, user: user) timeout ||= ENV["PG_EASY_REPLICATE_STATEMENT_TIMEOUT"] || "5s" if transaction r = conn.transaction do conn.run("SET search_path to #{quote_ident(schema)}") if schema conn.run("SET statement_timeout to '#{timeout}'") conn.fetch(query).to_a end else conn.run("SET search_path to #{quote_ident(schema)}") if schema if using_vacuum_analyze conn.run("SET statement_timeout=0") else conn.run("SET statement_timeout to '#{timeout}'") end r = conn.fetch(query).to_a end conn.disconnect r ensure conn&.fetch("RESET statement_timeout") conn&.disconnect end def connect(connection_url:, user: internal_user_name, schema: nil) c = Sequel.connect( connection_url, user: user, logger: ENV.fetch("DEBUG", nil) ? logger : nil, search_path: schema, ) logger.debug("Connection established") c end end end end
Version data entries
5 entries across 5 versions & 1 rubygems