generated from quinnj/Example.jl
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Almost the secrets issue is because the PR has no access to the environment secrets of the base repo
- Loading branch information
Farreeda
committed
Aug 24, 2023
1 parent
666bc10
commit 503bbe9
Showing
5 changed files
with
190 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
using DBConnector | ||
using Documenter | ||
|
||
makedocs(; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,87 @@ | ||
function _dbconnect(conn_obj::Type{MySQL.Connection}, host::String, user::String, password::String; db::String="", port::Integer=3306, unix_socket::Union{Nothing,String}=nothing, client_flag=API.CLIENT_MULTI_STATEMENTS, opts = Dict()) | ||
function _dbconnect(conn_obj::Type{MySQL.Connection}; kwargs...) | ||
|
||
if unix_socket == nothing | ||
unix_socket = API.MYSQL_DEFAULT_SOCKET | ||
|
||
if haskey(kwargs, :host) && haskey(kwargs, :user) | ||
host = kwargs[:host] | ||
kwargs = filter(kvp -> first(kvp) != :host, kwargs) | ||
user = kwargs[:user] | ||
kwargs = filter(kvp -> first(kvp) != :user, kwargs) | ||
if isempty(kwargs) | ||
return DBInterface.connect(conn_obj,host, user) | ||
elseif haskey(kwargs, :password) | ||
password=kwargs[:password] | ||
kwargs = filter(kvp -> first(kvp) != :password, kwargs) | ||
if isempty(kwargs) | ||
return DBInterface.connect(conn_obj,host, user, password) | ||
elseif haskey(kwargs, :db) | ||
db = kwargs[:db] | ||
kwargs = filter(kvp -> first(kvp) != :db, kwargs) | ||
if isempty(kwargs) | ||
return DBInterface.connect(conn_obj,host, user, password; kwargs) | ||
elseif haskey(kwargs, :port) | ||
db = kwargs[:port] | ||
kwargs = filter(kvp -> first(kvp) != :port, kwargs) | ||
if isempty(kwargs) | ||
return DBInterface.connect(conn_obj,host, user; kwargs) | ||
end | ||
end | ||
end | ||
elseif haskey(kwargs, :db) | ||
db = kwargs[:db] | ||
kwargs = filter(kvp -> first(kvp) != :db, kwargs) | ||
if isempty(kwargs) | ||
return DBInterface.connect(conn_obj,host, user; kwargs) | ||
elseif haskey(kwargs, :port) | ||
db = kwargs[:port] | ||
kwargs = filter(kvp -> first(kvp) != :port, kwargs) | ||
if isempty(kwargs) | ||
return DBInterface.connect(conn_obj,host, user; kwargs) | ||
end | ||
end | ||
end | ||
|
||
else | ||
error("Invalid arguments, make sure that keyword user and host exists") | ||
end | ||
end | ||
|
||
# if !haskey(kwargs, "unix_socket") | ||
# unix_socket = API.MYSQL_DEFAULT_SOCKET | ||
# kwargs.push(unix_socket) | ||
#end | ||
""" | ||
if haskey(kwargs, :host) | ||
host = kwargs[:host] | ||
kwargs = filter(kvp -> first(kvp) != :host, kwargs) | ||
if haskey(kwargs, :user) | ||
user = kwargs[:user] | ||
kwargs = filter(kvp -> first(kvp) != :user, kwargs) | ||
elseif haskey(kwargs, :username) | ||
user = kwargs[:username] | ||
kwargs = filter(kvp -> first(kvp) != :username, kwargs) | ||
else | ||
error("Invalid arguments, make sure that keyword user exists") | ||
end | ||
else | ||
error("Invalid arguments, make sure that keyword host exists") | ||
end | ||
if haskey(kwargs, :password) | ||
password=kwargs[:password] | ||
kwargs = filter(kvp -> first(kvp) != :password, kwargs) | ||
elseif isempty(kwargs) | ||
return DBInterface.connect(conn_obj,host, user) | ||
else | ||
return DBInterface.connect(conn_obj,host, user; kwargs) | ||
end | ||
if isempty(kwargs) | ||
return DBInterface.connect(conn_obj,host, user, password) | ||
else | ||
return DBInterface.connect(conn_obj,host, user, password; kwargs) | ||
return DBInterface.connect(conn_obj,host, user, password, db=db, port=port, unix_socket=unix_socket, client_flag=client_flag, opts=opts ) | ||
end | ||
return DBInterface.connect(conn_obj; kwargs...) | ||
#return DBInterface.connect(conn_obj,host, user, password, db=db, port=port, unix_socket=unix_socket, client_flag=client_flag, opts=opts ) | ||
end | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,112 @@ | ||
""" | ||
Workaround for LibPQ interface to DBInterface's `prepare` function; not supported in LibPQ.jl package currently | ||
""" | ||
DBInterface.prepare(conn::LibPQ.Connection, args...; kws...) = | ||
LibPQ.prepare(conn, args...; kws...) | ||
|
||
|
||
""" | ||
Dispatch for LibPQ interface to DBInterface `connect` function; not supported in LibPQ.jl package currently | ||
""" | ||
DBInterface.connect(::Type{LibPQ.Connection}, args...; kws...) = | ||
LibPQ.Connection(args...; kws...) | ||
|
||
""" | ||
This LibPQ connection function creates a connection string using | ||
1- username (user) | ||
2- hostname (host) | ||
3- password | ||
4- database (db) | ||
5- port | ||
Cases handles: | ||
1- user and host | ||
2- user, host, db | ||
3- user, host, password | ||
4- user, host, password, db | ||
5- user, host, password, db, port | ||
6- user, host, db, port | ||
adding other keywords can't be handled yet | ||
""" | ||
|
||
function _dbconnect(conn_obj::Type{LibPQ.Connection}; kwargs...) | ||
conn_string = "" | ||
for k in kwargs | ||
conn_string = conn_string * "$(string(k.first))=$(k.second) " | ||
end | ||
|
||
conn_string = strip(conn_string) | ||
|
||
return DBInterface.connect(conn_obj, conn_string) | ||
if haskey(kwargs, :host) && haskey(kwargs, :user) | ||
host = kwargs[:host] | ||
kwargs = filter(kvp -> first(kvp) != :host, kwargs) | ||
user = kwargs[:user] | ||
kwargs = filter(kvp -> first(kvp) != :user, kwargs) | ||
if isempty(kwargs) | ||
conn_string = "postgresql://$user@$host" | ||
return DBInterface.connect(conn_obj, conn_string) | ||
elseif haskey(kwargs, :password) | ||
password=kwargs[:password] | ||
kwargs = filter(kvp -> first(kvp) != :password, kwargs) | ||
if isempty(kwargs) | ||
conn_string = "postgresql://$user:$password@$host" | ||
return DBInterface.connect(conn_obj, conn_string) | ||
elseif haskey(kwargs, :db) | ||
db = kwargs[:db] | ||
kwargs = filter(kvp -> first(kvp) != :db, kwargs) | ||
if isempty(kwargs) | ||
conn_string = "postgresql://$(user):$(password)@$(host)/$(db)?user=$(user)" | ||
return DBInterface.connect(conn_obj, conn_string) | ||
elseif haskey(kwargs, :port) | ||
db = kwargs[:port] | ||
kwargs = filter(kvp -> first(kvp) != :port, kwargs) | ||
if isempty(kwargs) | ||
conn_string = "postgresql://$user:$password@$host:$port/$db" | ||
return DBInterface.connect(conn_obj, conn_string) | ||
end | ||
end | ||
end | ||
elseif haskey(kwargs, :db) | ||
db = kwargs[:db] | ||
kwargs = filter(kvp -> first(kvp) != :db, kwargs) | ||
if isempty(kwargs) | ||
conn_string = "postgresql://$user@$host/$db" | ||
return DBInterface.connect(conn_obj, conn_string) | ||
elseif haskey(kwargs, :port) | ||
db = kwargs[:port] | ||
kwargs = filter(kvp -> first(kvp) != :port, kwargs) | ||
if isempty(kwargs) | ||
conn_string = "postgresql://$user@$host:$port/$db" | ||
return DBInterface.connect(conn_obj, conn_string) | ||
end | ||
end | ||
|
||
else | ||
error("Invalid arguments, make sure that keyword user and host exist") | ||
end | ||
end | ||
|
||
end | ||
|
||
function _dbconnect(conn_obj::Type{LibPQ.Connection}, conn_string :: String) | ||
|
||
return DBInterface.connect(conn_obj, conn_string) | ||
|
||
end | ||
""" | ||
Workaround for LibPQ interface to DBInterface's `execute` function; not supported in LibPQ.jl package currently | ||
""" | ||
DBInterface.execute(conn::Union{LibPQ.Connection, LibPQ.Statement}, args...; kws...) = | ||
LibPQ.execute(conn, args...; kws...) | ||
|
||
function _dbconnect(conn_obj::Type{LibPQ.Connection}, host::String, user::String, password::String, db::String; port::Integer=5432) | ||
|
||
conn_string = "postgresql://$(user):$(password)@$(host)/$(db)?user=$(user)" | ||
|
||
function _dbconnect(conn_obj::Type{LibPQ.Connection}, conn_string :: String) | ||
|
||
return DBInterface.connect(conn_obj, conn_string) | ||
|
||
end | ||
#= | ||
function _dbconnect(conn_obj::Type{LibPQ.Connection}; host::String, user::String, password::String; db::String="", port::Integer=5432, unix_socket::Union{Nothing,String}=nothing, client_flag=API.CLIENT_MULTI_STATEMENTS, opts = Dict()) | ||
""" | ||
BUG DESCRIPTION: | ||
As of now, this function does not work. the conn_string is not built correctly and you'd probably need to build it manually with string interpolations. | ||
What this function would do is construct a connection string that looks like: | ||
"host = /var/run/postgresql user = user password = password dbname = mimiciii" | ||
However, the problem with the postgresql connection string is that the keywords in the string are actually positionally dependent. You can't just put them in any order. | ||
""" | ||
""" | ||
function _dbconnect(conn_obj::Type{LibPQ.Connection}; kwargs...) | ||
conn_string = "" | ||
for k in kws | ||
conn_string = conn_string * "$(string(k.first))=$(k.second) " | ||
for k in kwargs | ||
conn_string = conn_string * "(string(k.first))=(k.second) " | ||
end | ||
conn_string = strip(conn_string) | ||
return DBInterface.connect(conn_obj, conn_string) | ||
end | ||
=# | ||
|
||
""" | ||
Workaround for LibPQ interface to DBInterface's `prepare` function; not supported in LibPQ.jl package currently | ||
""" | ||
DBInterface.prepare(conn::LibPQ.Connection, args...; kws...) = | ||
LibPQ.prepare(conn, args...; kws...) | ||
|
||
""" | ||
Workaround for LibPQ interface to DBInterface's `execute` function; not supported in LibPQ.jl package currently | ||
""" | ||
DBInterface.execute(conn::Union{LibPQ.Connection, LibPQ.Statement}, args...; kws...) = | ||
LibPQ.execute(conn, args...; kws...) | ||
|
||
|
||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters