Sha256: e9585dade48bcaa08c647bc417f1063cb5b0f742ed4440288403c4a78450d106

Contents?: true

Size: 694 Bytes

Versions: 6

Compression:

Stored size: 694 Bytes

Contents

module Skr
    class SequentialId < Skr::Model
        FUNCTION_NAME="#{Skr.config.table_prefix}next_sequential_id"

        self.primary_key = 'name'

        locked_fields :name, :current_value

        def self.next_for( klass )
            begin
                res=ActiveRecord::Base.connection.raw_connection.exec( "select #{FUNCTION_NAME}( $1 )", [ klass.to_s ] )
                res.getvalue(0,0).to_i
            ensure
                res.clear if res
            end
        end

        def self.set_next( klass, value )
            self.connection.raw_connection.exec( "update #{table_name} set current_value = $1 where name = $2", [ value, klass.to_s ] )
        end

    end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
stockor-0.3.0 lib/skr/models/sequential_id.rb
stockor-0.2 lib/skr/models/sequential_id.rb
stockor-0.1.9 lib/skr/models/sequential_id.rb
stockor-0.1.8 lib/skr/models/sequential_id.rb
stockor-0.1.7 lib/skr/models/sequential_id.rb
stockor-0.1.5 lib/skr/models/sequential_id.rb