Skip to content

Commit

Permalink
add railtie/rails support
Browse files Browse the repository at this point in the history
  • Loading branch information
jethrodaniel committed Oct 20, 2024
1 parent 348e71a commit d8b954f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
34 changes: 34 additions & 0 deletions lib/sqlite_extensions/uuid/rails.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# frozen_string_literal: true

require "sqlite_extensions/uuid"

module SqliteExtensions
module UUID
class Railtie < Rails::Railtie
initializer "sqlite_extensions-uuid.patch_database_adapter" do
ActiveSupport.on_load(:active_record_sqlite3adapter) do
prepend DatabaseAdapterExtension
end
end

module DatabaseAdapterExtension
# https://github.com/rails/rails/blob/v8.0.0.rc1/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb#L815
def configure_connection
super

begin
@raw_connection.enable_load_extension(true)
@raw_connection.load_extension(SqliteExtensions::UUID.extension_path)
rescue SQLite3::Exception => e
# no such function: uuid (SQLite3::SQLException)
Rails.logger.error do
"Error loading sqlite extension '#{SqliteExtensions::UUID.extension_path}' (#{e})"
end
end
end
end

private_constant :DatabaseAdapterExtension
end
end
end
1 change: 1 addition & 0 deletions sqlite_extensions-uuid.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Gem::Specification.new do |spec|

spec.files = %w[
lib/sqlite_extensions/uuid.rb
lib/sqlite_extensions/uuid/rails.rb
ext/sqlite_extensions/uuid/sqlite3ext.h
ext/sqlite_extensions/uuid/sqlite3.h
ext/sqlite_extensions/uuid/sqlite3rc.h
Expand Down
4 changes: 4 additions & 0 deletions test/test_uuid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,8 @@ def test_it_works
uuid
)
end

def test_rails_integration
skip "TODO"
end
end

0 comments on commit d8b954f

Please sign in to comment.