Skip to content

Commit

Permalink
Merge pull request #28 from nickrobinson251/npr/methoderrors
Browse files Browse the repository at this point in the history
 Replace `NotImplementedError`s with `MethodError`s
  • Loading branch information
quinnj authored Jun 16, 2020
2 parents 025a5dd + 3d9e4e9 commit cbca69a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "DBInterface"
uuid = "a10d1c49-ce27-4219-8d33-6db1a4562965"
authors = ["Jacob Quinn <[email protected]>"]
version = "2.1.0"
version = "2.2.0"

[compat]
julia = "1"
Expand Down
20 changes: 6 additions & 14 deletions src/DBInterface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ that returns a valid, live database connection that can be queried against.
"""
function connect end

connect(T, args...; kw...) = throw(NotImplementedError("`DBInterface.connect` not implemented for `$T`"))
# Different `close!` signatures have their own docstrings.
function close! end

"""
DBInterface.close!(conn::DBInterface.Connection)
Immediately closes a database connection so further queries cannot be processed.
"""
function close! end
close!(conn::Connection)

close!(conn::Connection) = throw(NotImplementedError("`DBInterface.close!` not implemented for `$(typeof(conn))`"))

"Database packages should provide a `DBInterface.Statement` subtype which represents a valid, prepared SQL statement that can be executed repeatedly"
abstract type Statement end
Expand All @@ -38,7 +38,6 @@ which is often convenient when building applications.
"""
function prepare end

prepare(conn::Connection, sql::AbstractString) = throw(NotImplementedError("`DBInterface.prepare` not implemented for `$(typeof(conn))`"))
prepare(f::Function, sql::AbstractString) = prepare(f(), sql)

const PREPARED_STMTS = Dict{Symbol, Statement}()
Expand Down Expand Up @@ -79,8 +78,6 @@ For use-cases involving multiple resultsets from a single query, see `DBInterfac
"""
function execute end

execute(stmt::Statement, params=()) = throw(NotImplementedError("`DBInterface.execute` not implemented for `$(typeof(stmt))`"))

execute(conn::Connection, sql::AbstractString, params=()) = execute(prepare(conn, sql), params)

struct LazyIndex{T} <: AbstractVector{Any}
Expand Down Expand Up @@ -138,28 +135,23 @@ executemultiple(conn::Connection, sql::AbstractString, params=()) = executemulti
Close a prepared statement so further queries cannot be executed.
"""
close!(stmt::Statement) = throw(NotImplementedError("`DBInterface.close!` not implemented for `$(typeof(stmt))`"))
close!(stmt::Statement)

"""
DBInterface.lastrowid(x::Cursor) => Int
If supported by the specific database cursor, returns the last inserted row id after executing an INSERT statement.
"""
lastrowid(::T) where {T} = throw(NotImplementedError("`DBInterface.lastrowid` not implemented for $T"))
function lastrowid end

"""
DBInterface.close!(x::Cursor) => Nothing
Immediately close a resultset cursor. Database packages should overload for the provided resultset `Cursor` object.
"""
close!(x) = throw(NotImplementedError("`DBInterface.close!` not implemented for `$(typeof(x))`"))
close!(x::Cursor)

# exception handling
"Error for signaling a database package hasn't implemented an interface method"
struct NotImplementedError <: Exception
msg::String
end

"Error for signaling that parameters are used inconsistently or incorrectly."
struct ParameterError <: Exception
msg::String
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
using DBInterface, Test

@test_throws DBInterface.NotImplementedError DBInterface.connect(Int64)
@test_throws MethodError DBInterface.connect(Int64)

2 comments on commit cbca69a

@quinnj
Copy link
Member Author

@quinnj quinnj commented on cbca69a Jun 16, 2020

Choose a reason for hiding this comment

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

@JuliaRegistrator register()

@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/16481

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.2.0 -m "<description of version>" cbca69ad7d4bf5597cf9bac7a861431eee4f1381
git push origin v2.2.0

Please sign in to comment.