sequel-activerecord_connection 0.2.0 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +27 -0
- data/README.md +4 -3
- data/lib/sequel/extensions/activerecord_connection.rb +19 -2
- data/lib/sequel/extensions/activerecord_connection/jdbc.rb +38 -0
- data/lib/sequel/extensions/activerecord_connection/sqlite.rb +13 -3
- data/sequel-activerecord_connection.gemspec +3 -6
- metadata +16 -50
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 2f7d0993543eb478053e24dbbde84de0aaefdb13eb03a8852dd7d8f7facd2532
         | 
| 4 | 
            +
              data.tar.gz: 104318c5d02c0731e945dd3022b109902cdf2f97176b71511d06e68b4bbf8a10
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: d70812ee57dc9225683adfe196a2bc0f72de24e38cbd2d9492317073ed50a97ed58294a718d799655d953f9b80fc37dd27af78566d9f2bfaf9b95c454faa7a6d
         | 
| 7 | 
            +
              data.tar.gz: b7ec97e1c602bd544df1fba4c0a554846100ac1daed3e866d8ba837ca20b68f9b44f0f89db3a97d6c5e166a80e8276d1c30159453626af5692c8f78401cd2e54
         | 
    
        data/CHANGELOG.md
    ADDED
    
    | @@ -0,0 +1,27 @@ | |
| 1 | 
            +
            ## 0.2.5 (2020-06-04)
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            * Use `#current_timestamp_utc` for the JDBC SQLite adapter as well (@HoneyryderChuck)
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            ## 0.2.4 (2020-06-03)
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            * Add JRuby support for ActiveRecord 6.0 and 5.2 (@HoneyryderChuck)
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            * Use `#current_timestamp_utc` setting for SQLite adapter on Sequel >= 5.33 (@HoneyryderChuck)
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            ## 0.2.3 (2020-05-25)
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            * Fix Ruby 2.7 kwargs warnings in `#transaction` (@HoneyryderChuck)
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            ## 0.2.2 (2020-05-02)
         | 
| 16 | 
            +
             | 
| 17 | 
            +
            * Add support for ActiveRecord 4.2 (@janko)
         | 
| 18 | 
            +
             | 
| 19 | 
            +
            ## 0.2.1 (2020-05-02)
         | 
| 20 | 
            +
             | 
| 21 | 
            +
            * Add support for Active Record 5.0, 5.1 and 5.2 (@janko)
         | 
| 22 | 
            +
             | 
| 23 | 
            +
            * Allow Sequel 4.x (@janko)
         | 
| 24 | 
            +
             | 
| 25 | 
            +
            ## 0.2.0 (2020-04-29)
         | 
| 26 | 
            +
             | 
| 27 | 
            +
            * Rename to `sequel-activerecord_connection` and make it a Sequel extension (@janko)
         | 
    
        data/README.md
    CHANGED
    
    | @@ -1,8 +1,9 @@ | |
| 1 1 | 
             
            # Sequel::ActiveRecordConnection
         | 
| 2 2 |  | 
| 3 3 | 
             
            This is an extension for [Sequel] that allows it to reuse an existing
         | 
| 4 | 
            -
            ActiveRecord connection for database interaction. It  | 
| 5 | 
            -
            `mysql2` and `sqlite3` | 
| 4 | 
            +
            ActiveRecord connection for database interaction. It works on ActiveRecord 4.2
         | 
| 5 | 
            +
            or higher, and supports the built-in `postgresql`, `mysql2` and `sqlite3`
         | 
| 6 | 
            +
            adapters.
         | 
| 6 7 |  | 
| 7 8 | 
             
            This can be useful if you're using a library that uses Sequel for database
         | 
| 8 9 | 
             
            interaction (e.g. [Rodauth]), but you want to avoid creating a separate
         | 
| @@ -158,7 +159,7 @@ DB.activerecord_model = MyModel | |
| 158 159 | 
             
            ### Timezone
         | 
| 159 160 |  | 
| 160 161 | 
             
            Sequel's database timezone will be automatically set to ActiveRecord's default
         | 
| 161 | 
            -
            timezone  | 
| 162 | 
            +
            timezone (`:utc` by default) when the extension is loaded.
         | 
| 162 163 |  | 
| 163 164 | 
             
            If you happen to be changing ActiveRecord's default timezone after you've
         | 
| 164 165 | 
             
            loaded the extension, make sure to reflect that in your Sequel database object,
         | 
| @@ -21,7 +21,12 @@ module Sequel | |
| 21 21 | 
             
                  raise Error, "creating a Sequel connection is not allowed"
         | 
| 22 22 | 
             
                end
         | 
| 23 23 |  | 
| 24 | 
            -
                def transaction( | 
| 24 | 
            +
                def transaction(options = {})
         | 
| 25 | 
            +
                  savepoint      = options.delete(:savepoint)
         | 
| 26 | 
            +
                  rollback       = options.delete(:rollback)
         | 
| 27 | 
            +
                  auto_savepoint = options.delete(:auto_savepoint)
         | 
| 28 | 
            +
                  server         = options.delete(:server)
         | 
| 29 | 
            +
             | 
| 25 30 | 
             
                  fail Error, "#{options} transaction options are currently not supported" unless options.empty?
         | 
| 26 31 |  | 
| 27 32 | 
             
                  if in_transaction?
         | 
| @@ -57,7 +62,11 @@ module Sequel | |
| 57 62 |  | 
| 58 63 | 
             
                # Avoid calling Sequel's connection pool, instead use ActiveRecord.
         | 
| 59 64 | 
             
                def synchronize(*)
         | 
| 60 | 
            -
                   | 
| 65 | 
            +
                  if ActiveRecord.version >= Gem::Version.new("5.1.0")
         | 
| 66 | 
            +
                    activerecord_connection.lock.synchronize do
         | 
| 67 | 
            +
                      yield activerecord_raw_connection
         | 
| 68 | 
            +
                    end
         | 
| 69 | 
            +
                  else
         | 
| 61 70 | 
             
                    yield activerecord_raw_connection
         | 
| 62 71 | 
             
                  end
         | 
| 63 72 | 
             
                end
         | 
| @@ -71,6 +80,14 @@ module Sequel | |
| 71 80 | 
             
                def activerecord_connection
         | 
| 72 81 | 
             
                  activerecord_model.connection
         | 
| 73 82 | 
             
                end
         | 
| 83 | 
            +
             | 
| 84 | 
            +
                def activesupport_interlock(&block)
         | 
| 85 | 
            +
                  if ActiveSupport::Dependencies.respond_to?(:interlock)
         | 
| 86 | 
            +
                    ActiveSupport::Dependencies.interlock.permit_concurrent_loads(&block)
         | 
| 87 | 
            +
                  else
         | 
| 88 | 
            +
                    yield
         | 
| 89 | 
            +
                  end
         | 
| 90 | 
            +
                end
         | 
| 74 91 | 
             
              end
         | 
| 75 92 |  | 
| 76 93 | 
             
              Database.register_extension(:activerecord_connection, ActiveRecordConnection)
         | 
| @@ -0,0 +1,38 @@ | |
| 1 | 
            +
            module Sequel
         | 
| 2 | 
            +
              module ActiveRecordConnection
         | 
| 3 | 
            +
                module Jdbc
         | 
| 4 | 
            +
                  def self.extended(db)
         | 
| 5 | 
            +
                    if db.timezone == :utc && db.respond_to?(:current_timestamp_utc)
         | 
| 6 | 
            +
                      db.current_timestamp_utc = true
         | 
| 7 | 
            +
                    end
         | 
| 8 | 
            +
                  end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                  def statement(conn)
         | 
| 11 | 
            +
                    stmt = activerecord_raw_connection.connection.createStatement
         | 
| 12 | 
            +
                    yield stmt
         | 
| 13 | 
            +
                  rescue ActiveRecord::StatementInvalid => exception
         | 
| 14 | 
            +
                    raise_error(exception.cause, classes: database_error_classes)
         | 
| 15 | 
            +
                  rescue *database_error_classes => e
         | 
| 16 | 
            +
                    raise_error(e, classes: database_error_classes)
         | 
| 17 | 
            +
                  ensure
         | 
| 18 | 
            +
                    stmt.close if stmt
         | 
| 19 | 
            +
                  end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                  def execute(sql, opts=OPTS)
         | 
| 22 | 
            +
                    activerecord_connection.send(:log, sql) do
         | 
| 23 | 
            +
                      super
         | 
| 24 | 
            +
                    end
         | 
| 25 | 
            +
                  rescue ActiveRecord::StatementInvalid => exception
         | 
| 26 | 
            +
                    raise_error(exception.cause, classes: database_error_classes)
         | 
| 27 | 
            +
                  end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                  def execute_dui(sql, opts=OPTS)
         | 
| 30 | 
            +
                    activerecord_connection.send(:log, sql) do
         | 
| 31 | 
            +
                      super
         | 
| 32 | 
            +
                    end
         | 
| 33 | 
            +
                  rescue ActiveRecord::StatementInvalid => exception
         | 
| 34 | 
            +
                    raise_error(exception.cause, classes: database_error_classes)
         | 
| 35 | 
            +
                  end
         | 
| 36 | 
            +
                end
         | 
| 37 | 
            +
              end
         | 
| 38 | 
            +
            end
         | 
| @@ -1,6 +1,12 @@ | |
| 1 1 | 
             
            module Sequel
         | 
| 2 2 | 
             
              module ActiveRecordConnection
         | 
| 3 3 | 
             
                module Sqlite
         | 
| 4 | 
            +
                  def self.extended(db)
         | 
| 5 | 
            +
                    if db.timezone == :utc && db.respond_to?(:current_timestamp_utc)
         | 
| 6 | 
            +
                      db.current_timestamp_utc = true
         | 
| 7 | 
            +
                    end
         | 
| 8 | 
            +
                  end
         | 
| 9 | 
            +
             | 
| 4 10 | 
             
                  def execute_ddl(sql, opts=OPTS)
         | 
| 5 11 | 
             
                    execute(sql, opts)
         | 
| 6 12 | 
             
                  end
         | 
| @@ -10,12 +16,16 @@ module Sequel | |
| 10 16 | 
             
                  # ActiveRecord doesn't send SQLite methods Sequel expects, so we need to
         | 
| 11 17 | 
             
                  # try to replicate what ActiveRecord does around connection excecution.
         | 
| 12 18 | 
             
                  def _execute(type, sql, opts, &block)
         | 
| 13 | 
            -
                    activerecord_raw_connection.extended_result_codes | 
| 19 | 
            +
                    if activerecord_raw_connection.respond_to?(:extended_result_codes=)
         | 
| 20 | 
            +
                      activerecord_raw_connection.extended_result_codes = true
         | 
| 21 | 
            +
                    end
         | 
| 14 22 |  | 
| 15 | 
            -
                     | 
| 23 | 
            +
                    if ActiveRecord::VERSION::MAJOR >= 6
         | 
| 24 | 
            +
                      activerecord_connection.materialize_transactions
         | 
| 25 | 
            +
                    end
         | 
| 16 26 |  | 
| 17 27 | 
             
                    activerecord_connection.send(:log, sql) do
         | 
| 18 | 
            -
                       | 
| 28 | 
            +
                      activesupport_interlock do
         | 
| 19 29 | 
             
                        case type
         | 
| 20 30 | 
             
                        when :select
         | 
| 21 31 | 
             
                          activerecord_raw_connection.query(sql, &block)
         | 
| @@ -1,6 +1,6 @@ | |
| 1 1 | 
             
            Gem::Specification.new do |spec|
         | 
| 2 2 | 
             
              spec.name          = "sequel-activerecord_connection"
         | 
| 3 | 
            -
              spec.version       = "0.2. | 
| 3 | 
            +
              spec.version       = "0.2.5"
         | 
| 4 4 | 
             
              spec.authors       = ["Janko Marohnić"]
         | 
| 5 5 | 
             
              spec.email         = ["janko.marohnic@gmail.com"]
         | 
| 6 6 |  | 
| @@ -11,12 +11,9 @@ Gem::Specification.new do |spec| | |
| 11 11 |  | 
| 12 12 | 
             
              spec.required_ruby_version = Gem::Requirement.new(">= 2.2.0")
         | 
| 13 13 |  | 
| 14 | 
            -
              spec.add_dependency "sequel", " | 
| 15 | 
            -
              spec.add_dependency "activerecord", ">=  | 
| 14 | 
            +
              spec.add_dependency "sequel", ">= 4.0", "< 6"
         | 
| 15 | 
            +
              spec.add_dependency "activerecord", ">= 4.2", "< 7"
         | 
| 16 16 |  | 
| 17 | 
            -
              spec.add_development_dependency "pg",      "~> 1.0"
         | 
| 18 | 
            -
              spec.add_development_dependency "mysql2",  "~> 0.5"
         | 
| 19 | 
            -
              spec.add_development_dependency "sqlite3", "~> 1.4"
         | 
| 20 17 | 
             
              spec.add_development_dependency "minitest"
         | 
| 21 18 |  | 
| 22 19 | 
             
              spec.files         = Dir["README.md", "LICENSE.txt", "CHANGELOG.md", "lib/**/*.rb", "*.gemspec"]
         | 
    
        metadata
    CHANGED
    
    | @@ -1,36 +1,42 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: sequel-activerecord_connection
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.2. | 
| 4 | 
            +
              version: 0.2.5
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Janko Marohnić
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2020-04 | 
| 11 | 
            +
            date: 2020-06-04 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: sequel
         | 
| 15 15 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 16 16 | 
             
                requirements:
         | 
| 17 | 
            -
                - - " | 
| 17 | 
            +
                - - ">="
         | 
| 18 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 19 | 
            +
                    version: '4.0'
         | 
| 20 | 
            +
                - - "<"
         | 
| 18 21 | 
             
                  - !ruby/object:Gem::Version
         | 
| 19 | 
            -
                    version: ' | 
| 22 | 
            +
                    version: '6'
         | 
| 20 23 | 
             
              type: :runtime
         | 
| 21 24 | 
             
              prerelease: false
         | 
| 22 25 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 23 26 | 
             
                requirements:
         | 
| 24 | 
            -
                - - " | 
| 27 | 
            +
                - - ">="
         | 
| 25 28 | 
             
                  - !ruby/object:Gem::Version
         | 
| 26 | 
            -
                    version: ' | 
| 29 | 
            +
                    version: '4.0'
         | 
| 30 | 
            +
                - - "<"
         | 
| 31 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 32 | 
            +
                    version: '6'
         | 
| 27 33 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 28 34 | 
             
              name: activerecord
         | 
| 29 35 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 30 36 | 
             
                requirements:
         | 
| 31 37 | 
             
                - - ">="
         | 
| 32 38 | 
             
                  - !ruby/object:Gem::Version
         | 
| 33 | 
            -
                    version: ' | 
| 39 | 
            +
                    version: '4.2'
         | 
| 34 40 | 
             
                - - "<"
         | 
| 35 41 | 
             
                  - !ruby/object:Gem::Version
         | 
| 36 42 | 
             
                    version: '7'
         | 
| @@ -40,52 +46,10 @@ dependencies: | |
| 40 46 | 
             
                requirements:
         | 
| 41 47 | 
             
                - - ">="
         | 
| 42 48 | 
             
                  - !ruby/object:Gem::Version
         | 
| 43 | 
            -
                    version: ' | 
| 49 | 
            +
                    version: '4.2'
         | 
| 44 50 | 
             
                - - "<"
         | 
| 45 51 | 
             
                  - !ruby/object:Gem::Version
         | 
| 46 52 | 
             
                    version: '7'
         | 
| 47 | 
            -
            - !ruby/object:Gem::Dependency
         | 
| 48 | 
            -
              name: pg
         | 
| 49 | 
            -
              requirement: !ruby/object:Gem::Requirement
         | 
| 50 | 
            -
                requirements:
         | 
| 51 | 
            -
                - - "~>"
         | 
| 52 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 53 | 
            -
                    version: '1.0'
         | 
| 54 | 
            -
              type: :development
         | 
| 55 | 
            -
              prerelease: false
         | 
| 56 | 
            -
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 57 | 
            -
                requirements:
         | 
| 58 | 
            -
                - - "~>"
         | 
| 59 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 60 | 
            -
                    version: '1.0'
         | 
| 61 | 
            -
            - !ruby/object:Gem::Dependency
         | 
| 62 | 
            -
              name: mysql2
         | 
| 63 | 
            -
              requirement: !ruby/object:Gem::Requirement
         | 
| 64 | 
            -
                requirements:
         | 
| 65 | 
            -
                - - "~>"
         | 
| 66 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 67 | 
            -
                    version: '0.5'
         | 
| 68 | 
            -
              type: :development
         | 
| 69 | 
            -
              prerelease: false
         | 
| 70 | 
            -
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 71 | 
            -
                requirements:
         | 
| 72 | 
            -
                - - "~>"
         | 
| 73 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 74 | 
            -
                    version: '0.5'
         | 
| 75 | 
            -
            - !ruby/object:Gem::Dependency
         | 
| 76 | 
            -
              name: sqlite3
         | 
| 77 | 
            -
              requirement: !ruby/object:Gem::Requirement
         | 
| 78 | 
            -
                requirements:
         | 
| 79 | 
            -
                - - "~>"
         | 
| 80 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 81 | 
            -
                    version: '1.4'
         | 
| 82 | 
            -
              type: :development
         | 
| 83 | 
            -
              prerelease: false
         | 
| 84 | 
            -
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 85 | 
            -
                requirements:
         | 
| 86 | 
            -
                - - "~>"
         | 
| 87 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 88 | 
            -
                    version: '1.4'
         | 
| 89 53 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 90 54 | 
             
              name: minitest
         | 
| 91 55 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| @@ -107,9 +71,11 @@ executables: [] | |
| 107 71 | 
             
            extensions: []
         | 
| 108 72 | 
             
            extra_rdoc_files: []
         | 
| 109 73 | 
             
            files:
         | 
| 74 | 
            +
            - CHANGELOG.md
         | 
| 110 75 | 
             
            - LICENSE.txt
         | 
| 111 76 | 
             
            - README.md
         | 
| 112 77 | 
             
            - lib/sequel/extensions/activerecord_connection.rb
         | 
| 78 | 
            +
            - lib/sequel/extensions/activerecord_connection/jdbc.rb
         | 
| 113 79 | 
             
            - lib/sequel/extensions/activerecord_connection/mysql2.rb
         | 
| 114 80 | 
             
            - lib/sequel/extensions/activerecord_connection/postgres.rb
         | 
| 115 81 | 
             
            - lib/sequel/extensions/activerecord_connection/sqlite.rb
         |