occams-record 1.12.0 → 1.14.0
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/README.md +2 -2
- data/lib/occams-record/binds_converter/abstract.rb +5 -2
- data/lib/occams-record/binds_converter/named.rb +13 -2
- data/lib/occams-record/binds_converter/positional.rb +8 -3
- data/lib/occams-record/binds_converter.rb +2 -2
- data/lib/occams-record/errors.rb +12 -0
- data/lib/occams-record/measureable.rb +2 -0
- data/lib/occams-record/raw_query.rb +1 -1
- data/lib/occams-record/type_caster.rb +1 -1
- data/lib/occams-record/version.rb +1 -1
- metadata +5 -5
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: f8c516a796e28c82bb9143b832a04731756fcff86c45c0aea39c8cd44360130c
         | 
| 4 | 
            +
              data.tar.gz: 84949e1481e0ba095fb07f6fb5025e41f173754b2bc8f8043f7b87a96227349f
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 19e8dc49487a7268eb00607ce7a2a05937ace0102080fe2321e8dddd20760900e841d36f37f5fb5a9cd45d413a81b8bcc47ff3438de8480e13070c502e908953
         | 
| 7 | 
            +
              data.tar.gz: 6111775732bdf38efed21fdb8ecfccd254f1f80d775a543698cef217a564b31a2aa39ae1b56944df03fc02c2762e0f05965d20251a81c0b9320c2b58db37a210
         | 
    
        data/README.md
    CHANGED
    
    | @@ -361,8 +361,8 @@ It's possible to run tests without Docker Compose, but you'll be limited by the | |
| 361 361 |  | 
| 362 362 | 
             
            ```bash
         | 
| 363 363 | 
             
            bundle install
         | 
| 364 | 
            -
            bundle exec appraisal ar- | 
| 365 | 
            -
            bundle exec appraisal ar- | 
| 364 | 
            +
            bundle exec appraisal ar-8.0 bundle install
         | 
| 365 | 
            +
            bundle exec appraisal ar-8.0 rake test
         | 
| 366 366 | 
             
            ```
         | 
| 367 367 |  | 
| 368 368 | 
             
            # License
         | 
| @@ -10,21 +10,24 @@ module OccamsRecord | |
| 10 10 | 
             
                  # @private
         | 
| 11 11 | 
             
                  ESCAPE = "\\".freeze
         | 
| 12 12 |  | 
| 13 | 
            -
                  def initialize(sql, bind_sigil)
         | 
| 13 | 
            +
                  def initialize(sql, binds, bind_sigil)
         | 
| 14 14 | 
             
                    @sql = sql
         | 
| 15 | 
            +
                    @binds = binds
         | 
| 15 16 | 
             
                    @end = sql.size - 1
         | 
| 16 17 | 
             
                    @start_i, @i = 0, 0
         | 
| 17 18 | 
             
                    @bind_sigil = bind_sigil
         | 
| 19 | 
            +
                    @found = []
         | 
| 18 20 | 
             
                  end
         | 
| 19 21 |  | 
| 20 22 | 
             
                  # @return [String] The converted SQL string
         | 
| 21 23 | 
             
                  def to_s
         | 
| 22 24 | 
             
                    sql = ""
         | 
| 23 25 | 
             
                    each { |frag| sql << frag }
         | 
| 26 | 
            +
                    raise MissingBindValuesError.new(sql, missing_bind_values_msg) if @binds.size < @found.uniq.size
         | 
| 24 27 | 
             
                    sql
         | 
| 25 28 | 
             
                  end
         | 
| 26 29 |  | 
| 27 | 
            -
                   | 
| 30 | 
            +
                  private
         | 
| 28 31 |  | 
| 29 32 | 
             
                  # Yields each SQL fragment and converted bind to the given block
         | 
| 30 33 | 
             
                  def each
         | 
| @@ -4,20 +4,31 @@ module OccamsRecord | |
| 4 4 | 
             
                # Converts Rails-style named binds (:foo) into native Ruby format (%{foo}).
         | 
| 5 5 | 
             
                #
         | 
| 6 6 | 
             
                class Named
         | 
| 7 | 
            -
                  def initialize(sql)
         | 
| 7 | 
            +
                  def initialize(sql, binds)
         | 
| 8 8 | 
             
                    @sql = sql
         | 
| 9 | 
            +
                    @binds = binds
         | 
| 10 | 
            +
                    @found = []
         | 
| 9 11 | 
             
                  end
         | 
| 10 12 |  | 
| 11 13 | 
             
                  def to_s
         | 
| 12 | 
            -
                    @sql.gsub(/([:\\]?):([a-zA-Z]\w*)/) do |match|
         | 
| 14 | 
            +
                    sql = @sql.gsub(/([:\\]?):([a-zA-Z]\w*)/) do |match|
         | 
| 13 15 | 
             
                      if $1 == ":".freeze # skip PostgreSQL casts
         | 
| 14 16 | 
             
                        match # return the whole match
         | 
| 15 17 | 
             
                      elsif $1 == "\\".freeze # escaped literal colon
         | 
| 16 18 | 
             
                        match[1..-1] # return match with escaping backslash char removed
         | 
| 17 19 | 
             
                      else
         | 
| 20 | 
            +
                        @found << $2
         | 
| 18 21 | 
             
                        "%{#{$2}}"
         | 
| 19 22 | 
             
                      end
         | 
| 20 23 | 
             
                    end
         | 
| 24 | 
            +
                    raise MissingBindValuesError.new(sql, missing_bind_values_msg) if @binds.size < @found.uniq.size
         | 
| 25 | 
            +
                    sql
         | 
| 26 | 
            +
                  end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                  private
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                  def missing_bind_values_msg
         | 
| 31 | 
            +
                    (@found - @binds.keys.map(&:to_s)).join(", ")
         | 
| 21 32 | 
             
                  end
         | 
| 22 33 | 
             
                end
         | 
| 23 34 | 
             
              end
         | 
| @@ -4,17 +4,22 @@ module OccamsRecord | |
| 4 4 | 
             
                # Converts Rails-style positional binds (?) into native Ruby format (%s).
         | 
| 5 5 | 
             
                #
         | 
| 6 6 | 
             
                class Positional < Abstract
         | 
| 7 | 
            -
                  def initialize(sql)
         | 
| 8 | 
            -
                    super(sql, "?".freeze)
         | 
| 7 | 
            +
                  def initialize(sql, binds)
         | 
| 8 | 
            +
                    super(sql, binds, "?".freeze)
         | 
| 9 9 | 
             
                  end
         | 
| 10 10 |  | 
| 11 | 
            -
                   | 
| 11 | 
            +
                  private
         | 
| 12 12 |  | 
| 13 13 | 
             
                  def get_bind
         | 
| 14 14 | 
             
                    @i += 1
         | 
| 15 15 | 
             
                    @start_i = @i
         | 
| 16 | 
            +
                    @found << @found.size
         | 
| 16 17 | 
             
                    "%s".freeze
         | 
| 17 18 | 
             
                  end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                  def missing_bind_values_msg
         | 
| 21 | 
            +
                    (@found.size - @binds.size).to_s
         | 
| 22 | 
            +
                  end
         | 
| 18 23 | 
             
                end
         | 
| 19 24 | 
             
              end
         | 
| 20 25 | 
             
            end
         | 
| @@ -13,8 +13,8 @@ module OccamsRecord | |
| 13 13 | 
             
                def self.convert(sql, binds)
         | 
| 14 14 | 
             
                  converter =
         | 
| 15 15 | 
             
                    case binds
         | 
| 16 | 
            -
                    when Hash then Named.new(sql)
         | 
| 17 | 
            -
                    when Array then Positional.new(sql)
         | 
| 16 | 
            +
                    when Hash then Named.new(sql, binds)
         | 
| 17 | 
            +
                    when Array then Positional.new(sql, binds)
         | 
| 18 18 | 
             
                    else raise ArgumentError, "OccamsRecord: Unsupported SQL bind params '#{binds.inspect}'. Only Hash and Array are supported"
         | 
| 19 19 | 
             
                    end
         | 
| 20 20 | 
             
                  converter.to_s
         | 
    
        data/lib/occams-record/errors.rb
    CHANGED
    
    | @@ -1,4 +1,16 @@ | |
| 1 1 | 
             
            module OccamsRecord
         | 
| 2 | 
            +
              # Exception raised when not enough bind values were given
         | 
| 3 | 
            +
              class MissingBindValuesError < StandardError
         | 
| 4 | 
            +
                def initialize(sql, message)
         | 
| 5 | 
            +
                  @sql = sql
         | 
| 6 | 
            +
                  @message = message
         | 
| 7 | 
            +
                end
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                def to_s = message
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                def message = "Missing binds (#{@message}) in #{@sql}"
         | 
| 12 | 
            +
              end
         | 
| 13 | 
            +
             | 
| 2 14 | 
             
              # Exception raised when a record wasn't loaded with all requested data
         | 
| 3 15 | 
             
              class MissingDataError < StandardError
         | 
| 4 16 | 
             
                # @return [String]
         | 
| @@ -194,7 +194,7 @@ module OccamsRecord | |
| 194 194 | 
             
                end
         | 
| 195 195 |  | 
| 196 196 | 
             
                #
         | 
| 197 | 
            -
                # Returns a cursor you can open and perform operations on. A lower-level alternative to | 
| 197 | 
            +
                # Returns a cursor you can open and perform operations on. A lower-level alternative to
         | 
| 198 198 | 
             
                # find_each_with_cursor and find_in_batches_with_cursor.
         | 
| 199 199 | 
             
                #
         | 
| 200 200 | 
             
                # NOTE Postgres only. See the docs for OccamsRecord::Cursor for more details.
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: occams-record
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 1. | 
| 4 | 
            +
              version: 1.14.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Jordan Hollinger
         | 
| 8 8 | 
             
            autorequire:
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date:  | 
| 11 | 
            +
            date: 2025-03-06 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: activerecord
         | 
| @@ -19,7 +19,7 @@ dependencies: | |
| 19 19 | 
             
                    version: '6.0'
         | 
| 20 20 | 
             
                - - "<"
         | 
| 21 21 | 
             
                  - !ruby/object:Gem::Version
         | 
| 22 | 
            -
                    version: ' | 
| 22 | 
            +
                    version: '8.1'
         | 
| 23 23 | 
             
              type: :runtime
         | 
| 24 24 | 
             
              prerelease: false
         | 
| 25 25 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| @@ -29,7 +29,7 @@ dependencies: | |
| 29 29 | 
             
                    version: '6.0'
         | 
| 30 30 | 
             
                - - "<"
         | 
| 31 31 | 
             
                  - !ruby/object:Gem::Version
         | 
| 32 | 
            -
                    version: ' | 
| 32 | 
            +
                    version: '8.1'
         | 
| 33 33 | 
             
            description: A faster, lower-memory, fuller-featured querying API for ActiveRecord
         | 
| 34 34 | 
             
              that returns results as unadorned, read-only objects.
         | 
| 35 35 | 
             
            email: jordan.hollinger@gmail.com
         | 
| @@ -84,7 +84,7 @@ required_ruby_version: !ruby/object:Gem::Requirement | |
| 84 84 | 
             
              requirements:
         | 
| 85 85 | 
             
              - - ">="
         | 
| 86 86 | 
             
                - !ruby/object:Gem::Version
         | 
| 87 | 
            -
                  version: 3. | 
| 87 | 
            +
                  version: 3.1.0
         | 
| 88 88 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 89 89 | 
             
              requirements:
         | 
| 90 90 | 
             
              - - ">="
         |