Skip to content

Commit c810b25

Browse files
committed
Allow setting of connection data via environment arguments
1 parent 69e4420 commit c810b25

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "SearchLightPostgreSQL"
22
uuid = "4327cdd6-4902-11ea-0272-430cea0431bd"
33
authors = ["Adrian Salceanu <[email protected]>"]
4-
version = "2.2"
4+
version = "2.3"
55

66
[deps]
77
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"

src/SearchLightPostgreSQL.jl

+4-9
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,10 @@ Connects to the database and returns a handle.
5959
function SearchLight.connect(conn_data::Dict = SearchLight.config.db_config_settings) :: DatabaseHandle
6060
dns = String[]
6161

62-
haskey(conn_data, "host") && push!(dns, string("host=", conn_data["host"]))
63-
haskey(conn_data, "hostaddr") && push!(dns, string("hostaddr=", conn_data["hostaddr"]))
64-
haskey(conn_data, "port") && push!(dns, string("port=", conn_data["port"]))
65-
haskey(conn_data, "database") && push!(dns, string("dbname=", conn_data["database"]))
66-
haskey(conn_data, "username") && push!(dns, string("user=", conn_data["username"]))
67-
haskey(conn_data, "password") && push!(dns, string("password=", conn_data["password"]))
68-
haskey(conn_data, "passfile") && push!(dns, string("passfile=", conn_data["passfile"]))
69-
haskey(conn_data, "connect_timeout") && push!(dns, string("connect_timeout=", conn_data["connect_timeout"]))
70-
haskey(conn_data, "client_encoding") && push!(dns, string("client_encoding=", conn_data["client_encoding"]))
62+
for key in ["host", "hostaddr", "port", "database", "username", "password", "passfile", "connect_timeout", "client_encoding"]
63+
get!(conn_data, key, get(ENV, "SEARCHLIGHT_$(uppercase(key))", nothing))
64+
conn_data[key] !== nothing && push!(dns, string("$key=", conn_data[key]))
65+
end
7166

7267
push!(CONNECTIONS, LibPQ.Connection(join(dns, " ")))[end]
7368
end

0 commit comments

Comments
 (0)