|
19 | 19 |
|
20 | 20 | module ActiveRecord
|
21 | 21 | module ConnectionAdapters # :nodoc:
|
22 |
| - # = Active Record SQLite3 Adapter |
| 22 | + # = Active Record \SQLite3 Adapter |
23 | 23 | #
|
24 |
| - # The SQLite3 adapter works with the sqlite3-ruby drivers |
25 |
| - # (available as gem from https://rubygems.org/gems/sqlite3). |
| 24 | + # The \SQLite3 adapter works with the sqlite3[https://sparklemotion.github.io/sqlite3-ruby/] |
| 25 | + # driver. |
26 | 26 | #
|
27 | 27 | # Options:
|
28 | 28 | #
|
29 |
| - # * <tt>:database</tt> - Path to the database file. |
| 29 | + # * +:database+ (String): Filesystem path to the database file. |
| 30 | + # * +:statement_limit+ (Integer): Maximum number of prepared statements to cache per database connection. (default: 1000) |
| 31 | + # * +:timeout+ (Integer): Timeout in milliseconds to use when waiting for a lock. (default: no wait) |
| 32 | + # * +:strict+ (Boolean): Enable or disable strict mode. When enabled, this will |
| 33 | + # {disallow double-quoted string literals in SQL |
| 34 | + # statements}[https://www.sqlite.org/quirks.html#double_quoted_string_literals_are_accepted]. |
| 35 | + # (default: see strict_strings_by_default) |
| 36 | + # * +:extensions+ (Array): (<b>requires sqlite3 v2.4.0</b>) Each entry specifies a sqlite extension |
| 37 | + # to load for this database. The entry may be a filesystem path, or the name of a class that |
| 38 | + # responds to +.to_path+ to provide the filesystem path for the extension. See {sqlite3-ruby |
| 39 | + # documentation}[https://sparklemotion.github.io/sqlite3-ruby/SQLite3/Database.html#class-SQLite3::Database-label-SQLite+Extensions] |
| 40 | + # for more information. |
| 41 | + # |
| 42 | + # There may be other options available specific to the SQLite3 driver. Please read the |
| 43 | + # documentation for |
| 44 | + # {SQLite::Database.new}[https://sparklemotion.github.io/sqlite3-ruby/SQLite3/Database.html#method-c-new] |
| 45 | + # |
30 | 46 | class SQLite3Adapter < AbstractAdapter
|
31 | 47 | ADAPTER_NAME = "SQLite"
|
32 | 48 |
|
@@ -58,12 +74,19 @@ def dbconsole(config, options = {})
|
58 | 74 |
|
59 | 75 | ##
|
60 | 76 | # :singleton-method:
|
61 |
| - # Configure the SQLite3Adapter to be used in a strict strings mode. |
62 |
| - # This will disable double-quoted string literals, because otherwise typos can silently go unnoticed. |
63 |
| - # For example, it is possible to create an index for a non existing column. |
| 77 | + # |
| 78 | + # Configure the SQLite3Adapter to be used in a "strict strings" mode. When enabled, this will |
| 79 | + # {disallow double-quoted string literals in SQL |
| 80 | + # statements}[https://www.sqlite.org/quirks.html#double_quoted_string_literals_are_accepted], |
| 81 | + # which may prevent some typographical errors like creating an index for a non-existent |
| 82 | + # column. The default is +false+. |
| 83 | + # |
64 | 84 | # If you wish to enable this mode you can add the following line to your application.rb file:
|
65 | 85 | #
|
66 | 86 | # config.active_record.sqlite3_adapter_strict_strings_by_default = true
|
| 87 | + # |
| 88 | + # This can also be configured on individual databases by setting the +strict:+ option. |
| 89 | + # |
67 | 90 | class_attribute :strict_strings_by_default, default: false
|
68 | 91 |
|
69 | 92 | NATIVE_DATABASE_TYPES = {
|
@@ -125,10 +148,16 @@ def initialize(...)
|
125 | 148 | @last_affected_rows = nil
|
126 | 149 | @previous_read_uncommitted = nil
|
127 | 150 | @config[:strict] = ConnectionAdapters::SQLite3Adapter.strict_strings_by_default unless @config.key?(:strict)
|
| 151 | + |
| 152 | + extensions = @config.fetch(:extensions, []).map do |extension| |
| 153 | + extension.safe_constantize || extension |
| 154 | + end |
| 155 | + |
128 | 156 | @connection_parameters = @config.merge(
|
129 | 157 | database: @config[:database].to_s,
|
130 | 158 | results_as_hash: true,
|
131 | 159 | default_transaction_mode: :immediate,
|
| 160 | + extensions: extensions |
132 | 161 | )
|
133 | 162 | end
|
134 | 163 |
|
|
0 commit comments