This is a draft of the solution I have come up with:
using LibPQ
using DataFrames
const DatabaseHandle = LibPQ.Connection
const CONNECTIONS = DatabaseHandle[]
HOST = ENV["HC_DWH_HOST"]
USER = ENV["HC_DWH_USER"]
PASS = ENV["HC_DWH_PASS"]
PORT = "5439"
DB = "hc"
config = Dict(
"host" => HOST,
"username" => USER,
"password" => PASS,
"port" => PORT,
"database" => DB
)
"""
Add options parameter to my_connect (SearchLight.connect in reality)
This is passed to LibPQ.Connection() and allows connecting to RedShift
Refer to the source code: https://github.com/GenieFramework/SearchLightPostgreSQL.jl/blob/f2d7dd248f053109f4c20320eee8bc22fb802dd2/src/SearchLightPostgreSQL.jl
And the corresponding option in LibPQ: https://github.com/invenia/LibPQ.jl/blob/master/docs/src/pages/faq.md
"""
function my_connect(conn_data::Dict, options::Dict{String, String}=()) :: DatabaseHandle
dns = String[]
haskey(conn_data, "host") && push!(dns, string("host=", conn_data["host"]))
haskey(conn_data, "hostaddr") && push!(dns, string("hostaddr=", conn_data["hostaddr"]))
haskey(conn_data, "port") && push!(dns, string("port=", conn_data["port"]))
haskey(conn_data, "database") && push!(dns, string("dbname=", conn_data["database"]))
haskey(conn_data, "username") && push!(dns, string("user=", conn_data["username"]))
haskey(conn_data, "password") && push!(dns, string("password=", conn_data["password"]))
haskey(conn_data, "passfile") && push!(dns, string("passfile=", conn_data["passfile"]))
haskey(conn_data, "connect_timeout") && push!(dns, string("connect_timeout=", conn_data["connect_timeout"]))
haskey(conn_data, "client_encoding") && push!(dns, string("client_encoding=", conn_data["client_encoding"]))
push!(CONNECTIONS, LibPQ.Connection(join(dns, " "); options))[end]
end
conn = my_connect(config, Dict{String, String}())
sql = """
SELECT
state,
product,
placement
FROM page_ranking.position_metrics
WHERE unique_imp = \$1
"""
result = execute(conn, sql, ["1526313609394_20180514155553.a57c7cbf4348"])
df = DataFrame(result)
Last part is a test I did to a Redshift cluster I work with. Let me know what you think