@@ -693,10 +693,41 @@ def connect
693
693
end
694
694
695
695
def configure_connection
696
- # FIXME: missing from adapter
697
- # @connection.busy_timeout(self.class.type_cast_config_to_integer(@config[:timeout])) if @config[:timeout]
696
+ if @config [ :timeout ] && @config [ :retries ]
697
+ raise ArgumentError , "Cannot specify both timeout and retries arguments"
698
+ elsif @config [ :timeout ]
699
+ # FIXME: missing from adapter
700
+ # @raw_connection.busy_timeout(self.class.type_cast_config_to_integer(@config[:timeout]))
701
+ elsif @config [ :retries ]
702
+ retries = self . class . type_cast_config_to_integer ( @config [ :retries ] )
703
+ raw_connection . busy_handler do |count |
704
+ count <= retries
705
+ end
706
+ end
698
707
699
- execute ( "PRAGMA foreign_keys = ON" , "SCHEMA" )
708
+ # Enforce foreign key constraints
709
+ # https://www.sqlite.org/pragma.html#pragma_foreign_keys
710
+ # https://www.sqlite.org/foreignkeys.html
711
+ raw_execute ( "PRAGMA foreign_keys = ON" , "SCHEMA" )
712
+ unless @memory_database
713
+ # Journal mode WAL allows for greater concurrency (many readers + one writer)
714
+ # https://www.sqlite.org/pragma.html#pragma_journal_mode
715
+ raw_execute ( "PRAGMA journal_mode = WAL" , "SCHEMA" )
716
+ # Set more relaxed level of database durability
717
+ # 2 = "FULL" (sync on every write), 1 = "NORMAL" (sync every 1000 written pages) and 0 = "NONE"
718
+ # https://www.sqlite.org/pragma.html#pragma_synchronous
719
+ raw_execute ( "PRAGMA synchronous = NORMAL" , "SCHEMA" )
720
+ # Set the global memory map so all processes can share some data
721
+ # https://www.sqlite.org/pragma.html#pragma_mmap_size
722
+ # https://www.sqlite.org/mmap.html
723
+ raw_execute ( "PRAGMA mmap_size = #{ 128 . megabytes } " , "SCHEMA" )
724
+ end
725
+ # Impose a limit on the WAL file to prevent unlimited growth
726
+ # https://www.sqlite.org/pragma.html#pragma_journal_size_limit
727
+ raw_execute ( "PRAGMA journal_size_limit = #{ 64 . megabytes } " , "SCHEMA" )
728
+ # Set the local connection cache to 2000 pages
729
+ # https://www.sqlite.org/pragma.html#pragma_cache_size
730
+ raw_execute ( "PRAGMA cache_size = 2000" , "SCHEMA" )
700
731
end
701
732
702
733
end
0 commit comments