Skip to content

Commit adbe5a2

Browse files
authored
use multi_select in stream (#223)
1 parent 5803888 commit adbe5a2

File tree

1 file changed

+10
-24
lines changed

1 file changed

+10
-24
lines changed

lib/exqlite/connection.ex

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -306,35 +306,21 @@ defmodule Exqlite.Connection do
306306
end
307307

308308
@impl true
309-
def handle_fetch(%Query{statement: statement}, cursor, _opts, state) do
310-
case Sqlite3.step(state.db, cursor) do
311-
:done ->
312-
{
313-
:halt,
314-
%Result{
315-
rows: [],
316-
command: :fetch,
317-
num_rows: 0
318-
},
319-
state
320-
}
309+
def handle_fetch(%Query{statement: statement}, cursor, opts, state) do
310+
chunk_size = opts[:chunk_size] || opts[:max_rows] || state.chunk_size
321311

322-
{:row, row} ->
323-
{
324-
:cont,
325-
%Result{
326-
rows: [row],
327-
command: :fetch,
328-
num_rows: 1
329-
},
330-
state
331-
}
312+
case Sqlite3.multi_step(state.db, cursor, chunk_size) do
313+
{:done, rows} ->
314+
{:halt, %Result{rows: rows, command: :fetch, num_rows: length(rows)}, state}
332315

333-
:busy ->
334-
{:error, %Error{message: "Database busy", statement: statement}, state}
316+
{:rows, rows} ->
317+
{:cont, %Result{rows: rows, command: :fetch, num_rows: chunk_size}, state}
335318

336319
{:error, reason} ->
337320
{:error, %Error{message: reason, statement: statement}, state}
321+
322+
:busy ->
323+
{:error, %Error{message: "Database is busy", statement: statement}, state}
338324
end
339325
end
340326

0 commit comments

Comments
 (0)