Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,37 @@ jobs:
${{ runner.os }}-
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1

- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v1
with:
file: lcov.info
job1:
## The type of runner that the job will run on,
## here it runs on ubuntu latest
runs-on: ubuntu-latest
steps:
- name: step 1
## Reference your environment variables
run: echo "The mysqlport is:${{secrets.MYSQL_PORT}}mysqluser:${{secrets.MYSQL_USER}}
mysqlhost:${{secrets.MYSQL_HOST}}
mysqlpassword:${{secrets.MYSQL_PASSWORD}}
postgresuser:${{secrets.POSTGRES_USER}}
postgreshost:${{secrets.POSTGRES_HOST}}
postgresport:${{secrets.POSTGRES_PORT}}
postgrespassword:${{secrets.POSTGRES_PASSWORD}}"
job2:
runs-on: ubuntu-latest
steps:
- name: step 1
## Another way reference your environment variables
run: echo "The mysqlport is:${{secrets.MYSQL_PORT}}mysqluser:${{secrets.MYSQL_USER}}
mysqlhost:${{secrets.MYSQL_HOST}}
mysqlpassword:${{secrets.MYSQL_PASSWORD}}
postgresuser:${{secrets.POSTGRES_USER}}
postgreshost:${{secrets.POSTGRES_HOST}}
postgresport:${{secrets.POSTGRES_PORT}}
postgrespassword:${{secrets.POSTGRES_PASSWORD}}"
docs:
name: Documentation
runs-on: ubuntu-latest
Expand All @@ -60,3 +87,4 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }}

7 changes: 0 additions & 7 deletions .gitignore

This file was deleted.

22 changes: 20 additions & 2 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
using Documenter, Example

makedocs(modules = [Example], sitename = "Example.jl")
makedocs(;
modules = [DBConnector],
authors = "Jacob Zelko (aka TheCedarPrince) <[email protected]> and Fareeda",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Feel free to also add your last name and email too! :D

repo = "https://github.com/JuliaDatabases/DBConnector.jl",
sitename = "DBConnector.jl",
format = Documenter.HTML(;
prettyurls = get(ENV, "CI", "false") == "true",
canonical = "https://github.com/JuliaDatabases/DBConnector.jl"
edit_link = "dev",
footer = "Created by [Jacob Zelko](https://jacobzelko.com) & [Georgia Tech Research Institute](https://www.gtri.gatech.edu). [License](https://github.com/JuliaHealth/OMOPCDMCohortCreator.jl/blob/main/LICENSE)"
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can remove the footer variable here.

),
pages = [
"Home" => "index.md",
"Functions" => "Functions.md"
],

deploydocs(repo = "github.com/quinnj/Example.jl.git", push_preview = true)
)
deploydocs(repo = "github.com/quinnj/Example.jl.git",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh could you update this to the repo URL as shown above? Don't forget the .git extension that needs to be there. Thanks!

push_preview = true,

)
54 changes: 54 additions & 0 deletions docs/src/Functions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Functions

```@contents
Pages = ["Functions.md"]
```

## _dbconnect()

This Function is dedicated to expand the range of connection between The [OMOPCDMCohortCreator](https://github.com/JuliaHealth/OMOPCDMCohortCreator.jl) with databases.
Databases exist are SQLite, MySQL, PostgreSQL.
In the upcoming sections, we will learn about these tools.

### SQLite

Assuming your data exists on a SQLite database and you want to connect it to the OMOPCDMCohortCreator.

calling the function

``` _dbconnect(SQLite.Connection,"path/to/database.db") ```



### MySQL

Assuming your data exists on a MySQL database and you want to connect it to the OMOPCDMCohortCreator.

Make sure that the server is running and using `MySQL.API`:

``` systemctl status mysql ```

calling the function

``` _dbconnect(MySQL.Connection, "host_name", "username", "password"; db = "database_name" , port = port_num, unix_socket = "unix_socket_data_path" ) ```

those parameters must exist:

- host_name : if you are working on same machine server it will be "local host"

- username
- password

Can be known by openning all the `.cnf` files until you find them. I wasn't lucky and opened around 5 till I found the right one. Don't give up!

If unix_socket is not inserted, the default one is given



For any struggles MySQL related, [Read this](https://dev.mysql.com/doc/refman/8.0/en/starting-server.html)






3 changes: 3 additions & 0 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ Example Julia package repo.
```@autodocs
Copy link
Collaborator

Choose a reason for hiding this comment

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

Fareeda, could you open an issue about needing to update the home page of DBConnector.jl's documentation? Thanks!

Modules = [Example]
```



30 changes: 20 additions & 10 deletions src/jdbc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,33 @@ function DBInterface.connect(::Type{JDBC.Connection}, args...; connection_string
catch
println("JVM already initialized")
end
JDBC.Connection(connection_string)
JDBC.DriverManager.getConnection(connection_string)
end

"""
Dispatch for LibPQ interface to DBInterface `prepare` function
TODO: Not fully implemented yet
Dispatch for JDBC interface to DBInterface `prepare` function
BUG: Doesn't seem to work for all JDBC versions yet
"""
# DBInterface.prepare(conn::JDBC.Connection, args...; kws...) =
# JDBC.prepareStatement(conn, args...; kws...)
function DBInterface.prepare(conn::JDBC.JavaObject{Symbol("java.sql.Connection")}, args...; kws...)
stmt = JDBC.createStatement(conn)
result = executeQuery(stmt, args...)
return result
end

"""
Workaround for JDBC interface to DBInterface's `execute` function
"""
function DBInterface.execute(conn::JDBC.JavaObject{Symbol("java.sql.ResultSet")}, args...; kws...)
JDBC.Source(conn)
end

"""
Workaround for LibPQ interface to DBInterface's `execute` function
Workaround for JDBC interface to DBInterface's `execute` function
"""
function DBInterface.execute(conn::Union{JDBC.Connection, JDBC.JPreparedStatement}, args...; kws...)
csr = JDBC.cursor(conn)
JDBC.execute!(csr, args..., kws...)
JDBC.Source(csr)
function DBInterface.execute(conn::JDBC.JavaObject{Symbol("java.sql.Connection")}, args...; kws...)
stmt = JDBC.createStatement(conn)
result = executeQuery(stmt, args...)
JDBC.Source(result)
end


Expand Down
9 changes: 7 additions & 2 deletions src/mysql.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
function _dbconnect(conn_obj::Type{MySQL.Connection}, kwargs)

return DBInterface.connect(conn_obj; kwargs...)
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())
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hm, I am not too sure on this layout here; I think it would be better to have the second argument actually only be a string that is passed to the connection. Let's discuss during our check-in.


if unix_socket == nothing
unix_socket = API.MYSQL_DEFAULT_SOCKET
end

return DBInterface.connect(conn_obj,host, user, password, db=db, port=port, unix_socket=unix_socket, client_flag=client_flag, opts=opts )
end

14 changes: 11 additions & 3 deletions src/postgresql.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
"""
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...)

function _dbconnect(conn_obj::Type{LibPQ.Connection}; kwargs...)
function _dbconnect(conn_obj::Type{LibPQ.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())

conn_string = ""
for k in kwargs
conn_string = conn_string * "$(string(k.first))=$(k.second) "
Expand All @@ -16,6 +18,14 @@ function _dbconnect(conn_obj::Type{LibPQ.Connection}; kwargs...)

end

function _dbconnect(conn_obj::Type{LibPQ.Connection}, host::String, user::String, password::String; db::String="", port::Integer=3306, unix_socket::Union{Nothing,String}=nothing, opts = Dict())
#conn = LibPQ.Connection("postgresql://postgres:postgres3@localhost:5432/mimic?user=postgres")

return DBInterface.connect(conn_obj, "postgresql://$user:$password@$host:$port/$db?user=$user")

end


"""
Workaround for LibPQ interface to DBInterface's `prepare` function; not supported in LibPQ.jl package currently
"""
Expand All @@ -27,5 +37,3 @@ Workaround for LibPQ interface to DBInterface's `execute` function; not supporte
"""
DBInterface.execute(conn::Union{LibPQ.Connection, LibPQ.Statement}, args...; kws...) =
LibPQ.execute(conn, args...; kws...)


4 changes: 2 additions & 2 deletions src/sqlite.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function _dbconnect(connector::Type{SQLite.DB}; file_path)
function _dbconnect(connector::Type{SQLite.DB}, file_path::String)

return connector(file_path.second)
return connector(file_path)

end
Empty file added test/data/sqlite.db
Empty file.
32 changes: 29 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,30 @@
using Test, Example
using Test
using MySQL,SQLite, MySQL.API

@test hello("Julia") == "Hello, Julia"
@test domath(2.0) ≈ 7.0



@testset "_dbconnect function for SQLite" begin

conn= _dbconnect(SQLite.DB, "DBConnector.jl/test/data/sqlite.db")
@test @isdefined conn

end
"""
@testset "_dbconnect function for MySQL" begin

conn = _dbconnect(MySQL.Connection, ENV['mysqlhost'], ENV['mysqluser'], ENV['mysqlpassword'], db="MySQL", port= 3306)

@test typeof(conn) == MySQL.Connection
@test isopen(conn)
close(conn)

end

@testset "_dbconnect function for LibPQ" begin

conn= _dbconnect(LibPQ.Connection, ENV['postgreshost'], ENV['postgresuser'], ENV['postgrespassword'], db = "mimic", port= 5432)
@test @isdefined conn

end
"""