Skip to content

Commit

Permalink
Allow setting of connection data via environment arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
essenciary committed Aug 8, 2022
1 parent 69e4420 commit c810b25
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "SearchLightPostgreSQL"
uuid = "4327cdd6-4902-11ea-0272-430cea0431bd"
authors = ["Adrian Salceanu <e@essenciary.com>"]
version = "2.2"
version = "2.3"

[deps]
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Expand Down
13 changes: 4 additions & 9 deletions src/SearchLightPostgreSQL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

2 comments on commit c810b25

@essenciary
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/65863

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v2.3.0 -m "<description of version>" c810b25b9aba35bf6097f2f7f43f24010249f40e
git push origin v2.3.0

Please sign in to comment.