Skip to content

Commit

Permalink
Merge pull request #300 from JuliaDatabases/ed/jq-dbinterface
Browse files Browse the repository at this point in the history
Rebase of #289
  • Loading branch information
iamed2 authored Aug 17, 2024
2 parents 9eca383 + 9ed0a0a commit 9609dee
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
30 changes: 25 additions & 5 deletions src/dbinterface.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,29 @@
DBInterface.connect(::Type{Connection}, args...; kws...) = Connection(args...; kws...)
struct DBConnection <: DBInterface.Connection
conn::Connection
end

function DBInterface.connect(::Type{Connection}, args...; kwargs...)
return DBConnection(Connection(args...; kwargs...))
end

function DBInterface.prepare(conn::DBConnection, args...; kwargs...)
return prepare(conn.conn, args...; kwargs...)
end

DBInterface.prepare(conn::Connection, args...; kws...) = prepare(conn, args...; kws...)
function DBInterface.execute(conn::DBConnection, args...; kwargs...)
return execute(conn.conn, args...; kwargs...)
end

function DBInterface.execute(conn::DBConnection, str::AbstractString; kwargs...)
return execute(conn.conn, str; kwargs...)
end

function DBInterface.execute(conn::DBConnection, str::AbstractString, params; kwargs...)
return execute(conn.conn, str, params; kwargs...)
end

function DBInterface.execute(conn::Union{Connection,Statement}, args...; kws...)
return execute(conn, args...; kws...)
function DBInterface.execute(stmt::Statement, args...; kwargs...)
return execute(stmt, args...; kwargs...)
end

DBInterface.close!(conn::Connection) = close(conn)
DBInterface.close!(conn::DBConnection) = close(conn.conn)
4 changes: 2 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1912,7 +1912,7 @@ end

@testset "DBInterface integration" begin
conn = DBInterface.connect(LibPQ.Connection, "dbname=postgres user=$DATABASE_USER")
@test conn isa LibPQ.Connection
@test conn isa LibPQ.DBConnection

result = DBInterface.execute(
conn,
Expand Down Expand Up @@ -1944,7 +1944,7 @@ end
@test LibPQ.column_name(result, 2) == "typname"

DBInterface.close!(conn)
@test !isopen(conn)
@test !isopen(conn.conn)

end
end
Expand Down

0 comments on commit 9609dee

Please sign in to comment.