-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdatabase_compatibility.rb
More file actions
53 lines (44 loc) · 1.31 KB
/
database_compatibility.rb
File metadata and controls
53 lines (44 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# frozen_string_literal: true
# Implements some methods to make Extralite::Database compatible enough with
# SQLite3::Database to be used by ActiveRecord's SQLite adapter.
module EnhancedSQLite3
module Extralite
module DatabaseCompatibility
def transaction(mode = :deferred)
execute "BEGIN #{mode.to_s.upcase} TRANSACTION"
if block_given?
abort = false
begin
yield self
rescue StandardError
abort = true
raise
ensure
abort and rollback or commit
end
end
true
end
def commit
execute "COMMIT TRANSACTION"
end
def rollback
execute "ROLLBACK TRANSACTION"
end
# NOTE: Extralite only supports UTF-8 encoding while the sqlite3 gem can use UTF-16
# if utf16: true is passed to the Database initializer.
def encoding
"UTF-8"
end
# NOTE: The sqlite3 gem appears to support both busy_timeout= and busy_timeout
# The ActiveRecord adapter #configure_connection method uses the latter, which
# could potentially be changed, allowing us to get rid of the monkey patch.
def busy_timeout(timeout)
self.busy_timeout = timeout
end
def readonly?
read_only?
end
end
end
end