Skip to content

Commit eda1870

Browse files
committed
Fix :invalid_chunk_size error
1 parent 7d4a832 commit eda1870

File tree

5 files changed

+27
-6
lines changed

5 files changed

+27
-6
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# Changelog
22

33

4+
## [0.5.3] - 2021-03-23
5+
6+
### Fixed
7+
- `:invalid_chunk_size` being emitted by the `DBConnection.execute`
8+
9+
410
## [0.5.2] - 2021-03-23
511

612
### Added

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Package: https://hex.pm/packages/exqlite
3131

3232
```elixir
3333
defp deps do
34-
{:exqlite, "~> 0.5.1"}
34+
{:exqlite, "~> 0.5.3"}
3535
end
3636
```
3737

lib/exqlite/connection.ex

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ defmodule Exqlite.Connection do
3333
:db,
3434
:path,
3535
:transaction_status,
36-
:status
36+
:status,
37+
:chunk_size
3738
]
3839

3940
@type t() :: %__MODULE__{
@@ -88,13 +89,20 @@ defmodule Exqlite.Connection do
8889
negative value turns auto-checkpointing off.
8990
* `:busy_timeout` - Sets the busy timeout in milliseconds for a connection.
9091
Default is `2000`.
92+
* `:chunk_size` - The chunk size for bulk fetching. Defaults to `50`.
9193
9294
For more information about the options above, see [sqlite documenation][1]
9395
9496
[1]: https://www.sqlite.org/pragma.html
9597
"""
9698
def connect(options) do
9799
database = Keyword.get(options, :database)
100+
options =
101+
Keyword.put_new(
102+
options,
103+
:chunk_size,
104+
Application.get_env(:exqlite, :default_chunk_size, 50)
105+
)
98106

99107
case database do
100108
nil ->
@@ -384,7 +392,8 @@ defmodule Exqlite.Connection do
384392
db: db,
385393
path: path,
386394
transaction_status: :idle,
387-
status: :idle
395+
status: :idle,
396+
chunk_size: Keyword.get(options, :chunk_size)
388397
}
389398

390399
{:ok, state}
@@ -491,7 +500,7 @@ defmodule Exqlite.Connection do
491500
end
492501

493502
defp get_rows(query, state) do
494-
case Sqlite3.fetch_all(state.db, query.ref) do
503+
case Sqlite3.fetch_all(state.db, query.ref, state.chunk_size) do
495504
{:ok, rows} -> {:ok, rows}
496505
{:error, reason} -> {:error, %Error{message: reason}, state}
497506
end

lib/exqlite/sqlite3.ex

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,19 @@ defmodule Exqlite.Sqlite3 do
118118
Sqlite3NIF.execute(conn, String.to_charlist("PRAGMA shrink_memory"))
119119
end
120120

121+
@spec fetch_all(db(), statement(), integer()) :: {:ok, [row()]} | {:error, reason()}
122+
def fetch_all(conn, statement, chunk_size) do
123+
fetch_all(conn, statement, chunk_size, [])
124+
end
125+
121126
@spec fetch_all(db(), statement()) :: {:ok, [row()]} | {:error, reason()}
122-
def fetch_all(conn, statement, chunk_size \\ 50) do
127+
def fetch_all(conn, statement) do
123128
# TODO: Should this be done in the NIF? It can be _much_ faster to build a
124129
# list there, but at the expense that it could block other dirty nifs from
125130
# getting work done.
126131
#
127132
# For now this just works
133+
chunk_size = Application.get_env(:exqlite, :default_chunk_size, 50)
128134
fetch_all(conn, statement, chunk_size, [])
129135
end
130136

mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
defmodule Exqlite.MixProject do
22
use Mix.Project
33

4-
@version "0.5.2"
4+
@version "0.5.3"
55

66
def project do
77
[

0 commit comments

Comments
 (0)