Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MySQL test #8

Open
wants to merge 24 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 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
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,
devbranch = "main",
)
54 changes: 54 additions & 0 deletions docs/src/Functions.md
Copy link
Collaborator

Choose a reason for hiding this comment

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

I am holding off on reviewing this documentation until we chat about tests and further about the API!

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
7 changes: 5 additions & 2 deletions src/mysql.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
function _dbconnect(conn_obj::Type{MySQL.Connection}, 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.


return DBInterface.connect(conn_obj; kwargs...)
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
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/database.db
Empty file.
18 changes: 18 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
using Test, Example
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/database.db")
@test @isdefined conn

end

@testset "_dbconnect function for MySQL" begin

conn = _dbconnect(MySQL.Connection, "localhost", "debian-sys-maint","HGGsOLypO2LVqq1v", db="mydatabase", port=3306, unix_socket="/var/run/mysqld/mysqld.sock")
@test typeof(conn) == MySQL.Connection
@test isopen(conn)
close(conn)

end
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is very great that this is working! Like you said, we'll need to determine how to run these tests somewhere else. I'd like to somehow get this connection made to the GSoC Server for testing over the summer while somehow maintaining secrecy for our server credentials. Let's talk about this at our weekly check-in!