@@ -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
0 commit comments