Skip to content

Commit 9724a17

Browse files
authored
Support DBInterface.jl v2.5 (#268)
DBInterface.jl now supports overloading `DBInterface.transaction` that is now used in `DBInterface.executemany` to wrap multiple `execute` calls in transactions for efficiency. This speeds up the use of `executemany` on SQLite prepared statements, as reported as slow in
1 parent 31465d1 commit 9724a17

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "SQLite"
22
uuid = "0aa819cd-b072-5ff4-a722-6bc24af294d9"
33
authors = ["Jacob Quinn <[email protected]>"]
4-
version = "1.3.0"
4+
version = "1.4.0"
55

66
[deps]
77
BinaryProvider = "b99e7846-7c00-51b0-8f62-c81ae34c0232"
@@ -17,7 +17,7 @@ WeakRefStrings = "ea10d353-3f73-51f8-a26c-33c1cb351aa5"
1717

1818
[compat]
1919
BinaryProvider = "0.5"
20-
DBInterface = "2.4"
20+
DBInterface = "2.5"
2121
SQLite_jll = "3"
2222
Tables = "1"
2323
WeakRefStrings = "0.4,0.5,0.6,1"

src/SQLite.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ end
177177
# it from the db.stmts collection
178178
_finalize(stmt::Stmt) = DBInterface.close!(stmt)
179179

180+
DBInterface.getconnection(stmt::Stmt) = stmt.db
181+
180182
# explicitly close prepared statement
181183
function DBInterface.close!(stmt::Stmt)
182184
_st = _stmt_safe(stmt)
@@ -549,6 +551,8 @@ function transaction(db::DB, mode="DEFERRED")
549551
end
550552
end
551553

554+
DBInterface.transaction(f, db::DB) = transaction(f, db)
555+
552556
@inline function transaction(f::Function, db::DB)
553557
# generate a random name for the savepoint
554558
name = string("SQLITE", Random.randstring(10))

src/tables.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ function load!(sch::Tables.Schema, rows, db::DB, name::AbstractString, db_tablei
238238
kind = replace ? "REPLACE" : "INSERT"
239239
stmt = _Stmt(db, "$kind INTO $(esc_id(string(name))) ($columns) VALUES ($params)")
240240
# start a transaction for inserting rows
241-
transaction(db) do
241+
DBInterface.transaction(db) do
242242
if row === nothing
243243
state = iterate(rows)
244244
state === nothing && return

test/runtests.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,4 +566,16 @@ DBInterface.execute(db, "insert into tmp values (?)", (:a,))
566566
tbl = DBInterface.execute(db, "select x from tmp") |> columntable
567567
@test isequal(tbl.x, [missing, :a])
568568

569+
db = SQLite.DB()
570+
DBInterface.execute(db, "create table tmp (a integer, b integer, c integer)")
571+
stmt = DBInterface.prepare(db, "INSERT INTO tmp VALUES(?, ?, ?)")
572+
tbl = (
573+
a = [1, 1, 1],
574+
b = [3, 4, 5],
575+
c = [4, 5, 6]
576+
)
577+
DBInterface.executemany(stmt, tbl)
578+
tbl2 = DBInterface.execute(db, "select * from tmp") |> columntable
579+
@test tbl == tbl2
580+
569581
end

0 commit comments

Comments
 (0)