Skip to content

Commit b3cd750

Browse files
committed
Change execute w/ no bang
1 parent a77881c commit b3cd750

3 files changed

Lines changed: 25 additions & 25 deletions

File tree

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "DBInterface"
22
uuid = "a10d1c49-ce27-4219-8d33-6db1a4562965"
33
authors = ["Jacob Quinn <quinn.jacobd@gmail.com>"]
4-
version = "1.0.1"
4+
version = "2.0.0"
55

66
[compat]
77
julia = "1"

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ conn = DBInterface.connect(T, args...; kw...) # create a connection to a specifi
1111

1212
stmt = DBInterface.prepare(conn, sql) # prepare a sql statement against the connection; returns a statement object
1313

14-
results = DBInterface.execute!(stmt) # execute a prepared statement; returns an iterator of rows (property-accessible & indexable)
14+
results = DBInterface.execute(stmt) # execute a prepared statement; returns an iterator of rows (property-accessible & indexable)
1515

1616
rowid = DBInterface.lastrowid(results) # get the last row id of an INSERT statement, as supported by the database
1717

@@ -26,17 +26,17 @@ end
2626
df = DataFrame(results)
2727
CSV.write("results.csv", results)
2828

29-
results = DBInterface.execute!(conn, sql) # convenience method if statement preparation/re-use isn't needed
29+
results = DBInterface.execute(conn, sql) # convenience method if statement preparation/re-use isn't needed
3030

3131
stmt = DBInterface.prepare(conn, "INSERT INTO test_table VALUES(?, ?)") # prepare a statement with positional parameters
3232

33-
DBInterface.execute!(stmt, [1, 3.14]) # execute the prepared INSERT statement, passing 1 and 3.14 as positional parameters
33+
DBInterface.execute(stmt, [1, 3.14]) # execute the prepared INSERT statement, passing 1 and 3.14 as positional parameters
3434

3535
stmt = DBInterface.prepare(conn, "INSERT INTO test_table VALUES(:col1, :col2)") # prepare a statement with named parameters
3636

37-
DBInterface.execute!(stmt, (col1=1, col2=3.14)) # execute the prepared INSERT statement, with 1 and 3.14 as named parameters
37+
DBInterface.execute(stmt, (col1=1, col2=3.14)) # execute the prepared INSERT statement, with 1 and 3.14 as named parameters
3838

39-
DBInterface.executemany!(stmt, (col1=[1,2,3,4,5], col2=[3.14, 1.23, 2.34 3.45, 4.56])) # execute the prepared statement multiple times for each set of named parameters; each named parameter must be an indexable collection
39+
DBInterface.executemany(stmt, (col1=[1,2,3,4,5], col2=[3.14, 1.23, 2.34 3.45, 4.56])) # execute the prepared statement multiple times for each set of named parameters; each named parameter must be an indexable collection
4040

4141
DBInterface.close!(stmt) # close the prepared statement
4242
```
@@ -49,6 +49,6 @@ DBInterface.connect
4949
DBInterface.close!
5050
DBInterface.Statement
5151
DBInterface.prepare
52-
DBInterface.execute!
52+
DBInterface.execute
5353
DBInterface.lastrowid
5454
```

src/DBInterface.jl

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -58,27 +58,27 @@ macro prepare(getDB, sql)
5858
end
5959
end
6060

61-
"Any object that iterates \"rows\", which are objects that are property-accessible and indexable. See `DBInterface.execute!` for more details on fetching query results."
61+
"Any object that iterates \"rows\", which are objects that are property-accessible and indexable. See `DBInterface.execute` for more details on fetching query results."
6262
abstract type Cursor end
6363

6464
"""
65-
DBInterface.execute!(conn::DBInterface.Connection, sql::AbstractString, [params]) => DBInterface.Cursor
66-
DBInterface.execute!(stmt::DBInterface.Statement, [params]) => DBInterface.Cursor
65+
DBInterface.execute(conn::DBInterface.Connection, sql::AbstractString, [params]) => DBInterface.Cursor
66+
DBInterface.execute(stmt::DBInterface.Statement, [params]) => DBInterface.Cursor
6767
68-
Database packages should overload `DBInterface.execute!` for a valid, prepared `DBInterface.Statement` subtype (the first method
68+
Database packages should overload `DBInterface.execute` for a valid, prepared `DBInterface.Statement` subtype (the first method
6969
signature is defined in DBInterface.jl using `DBInterface.prepare`), which takes an optional `params` argument, which should be
7070
an indexable collection (`Vector` or `Tuple`) for positional parameters, or a `NamedTuple` for named parameters.
71-
`DBInterface.execute!` should return a valid `DBInterface.Cursor` object, which is any iterator of "rows",
71+
`DBInterface.execute` should return a valid `DBInterface.Cursor` object, which is any iterator of "rows",
7272
which themselves must be property-accessible (i.e. implement `propertynames` and `getproperty` for value access by name),
7373
and indexable (i.e. implement `length` and `getindex` for value access by index). These "result" objects do not need
7474
to subtype `DBInterface.Cursor` explicitly as long as they satisfy the interface. For DDL/DML SQL statements, which typically
7575
do not return results, an iterator is still expected to be returned that just iterates `nothing`, i.e. an "empty" iterator.
7676
"""
77-
function execute! end
77+
function execute end
7878

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

81-
execute!(conn::Connection, sql::AbstractString, params=()) = execute!(prepare(conn, sql), params)
81+
execute(conn::Connection, sql::AbstractString, params=()) = execute(prepare(conn, sql), params)
8282

8383
struct LazyIndex{T} <: AbstractVector{Any}
8484
x::T
@@ -91,38 +91,38 @@ Base.size(x::LazyIndex) = (length(x.x),)
9191
Base.getindex(x::LazyIndex, i::Int) = x.x[i][x.i]
9292

9393
"""
94-
DBInterface.executemany!(conn::DBInterface.Connect, sql::AbstractString, [params]) => Nothing
95-
DBInterface.executemany!(stmt::DBInterface.Statement, [params]) => Nothing
94+
DBInterface.executemany(conn::DBInterface.Connect, sql::AbstractString, [params]) => Nothing
95+
DBInterface.executemany(stmt::DBInterface.Statement, [params]) => Nothing
9696
97-
Similar in usage to `DBInterface.execute!`, but allows passing multiple sets of parameters to be executed in sequence.
98-
`params`, like for `DBInterface.execute!`, should be an indexable collection (`Vector` or `Tuple`) or `NamedTuple`, but instead
97+
Similar in usage to `DBInterface.execute`, but allows passing multiple sets of parameters to be executed in sequence.
98+
`params`, like for `DBInterface.execute`, should be an indexable collection (`Vector` or `Tuple`) or `NamedTuple`, but instead
9999
of a single scalar value per parameter, an indexable collection should be passed for each parameter. By default, each set of
100-
parameters will be looped over and `DBInterface.execute!` will be called for each. Note that no result sets or cursors are returned
100+
parameters will be looped over and `DBInterface.execute` will be called for each. Note that no result sets or cursors are returned
101101
for any execution, so the usage is mainly intended for bulk INSERT statements.
102102
"""
103-
function executemany!(stmt::Statement, params=())
103+
function executemany(stmt::Statement, params=())
104104
if !isempty(params)
105105
param = params[1]
106106
len = length(param)
107107
all(x -> length(x) == len, params) || throw(ParameterError("parameters provided to `DBInterface.executemany!` do not all have the same number of parameters"))
108108
for i = 1:len
109109
xargs = LazyIndex(params, i)
110-
execute!(stmt, xargs)
110+
execute(stmt, xargs)
111111
end
112112
else
113-
execute!(stmt)
113+
execute(stmt)
114114
end
115115
return
116116
end
117117

118-
executemany!(conn::Connection, sql::AbstractString, params=()) = executemany!(prepare(conn, sql), params)
118+
executemany(conn::Connection, sql::AbstractString, params=()) = executemany(prepare(conn, sql), params)
119119

120120
"""
121121
DBInterface.close!(stmt::DBInterface.Statement)
122122
123123
Close a prepared statement so further queries cannot be executed.
124124
"""
125-
function close! end
125+
close!(stmt::Statement) = throw(NotImplementedError("`DBInterface.close!` not implemented for `$(typeof(stmt))`"))
126126

127127
"""
128128
DBInterface.lastrowid(x::Cursor) => Int

0 commit comments

Comments
 (0)