From c810b25b9aba35bf6097f2f7f43f24010249f40e Mon Sep 17 00:00:00 2001 From: Adrian Salceanu Date: Mon, 8 Aug 2022 14:36:34 +0200 Subject: [PATCH] Allow setting of connection data via environment arguments --- Project.toml | 2 +- src/SearchLightPostgreSQL.jl | 13 ++++--------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/Project.toml b/Project.toml index 87a5ee4..5c333b6 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "SearchLightPostgreSQL" uuid = "4327cdd6-4902-11ea-0272-430cea0431bd" authors = ["Adrian Salceanu "] -version = "2.2" +version = "2.3" [deps] DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" diff --git a/src/SearchLightPostgreSQL.jl b/src/SearchLightPostgreSQL.jl index adaf670..a6f7004 100644 --- a/src/SearchLightPostgreSQL.jl +++ b/src/SearchLightPostgreSQL.jl @@ -59,15 +59,10 @@ Connects to the database and returns a handle. function SearchLight.connect(conn_data::Dict = SearchLight.config.db_config_settings) :: 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"])) + for key in ["host", "hostaddr", "port", "database", "username", "password", "passfile", "connect_timeout", "client_encoding"] + get!(conn_data, key, get(ENV, "SEARCHLIGHT_$(uppercase(key))", nothing)) + conn_data[key] !== nothing && push!(dns, string("$key=", conn_data[key])) + end push!(CONNECTIONS, LibPQ.Connection(join(dns, " ")))[end] end