Sha256: 18b73d6e9628cf2ecd37ea99e88e6dae663d97f33ab6e9853f3786206cda122d

Contents?: true

Size: 1.04 KB

Versions: 3

Compression:

Stored size: 1.04 KB

Contents

module Koine
  module Repository
    module Persistence
      class Adapter
        class Sql < Adapter
          attr_reader :adapter, :table_name, :table, :id_field

          def initialize(adapter, table_name, id_field = :id)
            @adapter = adapter
            @table_name = table_name
            @table = adapter[table_name]
            @id_field = id_field
          end

          def exists?(criterias)
            table.where(criterias).limit(2).count > 0
          end

          def find(id)
            find_one_by(id_field => id)
          end

          def find_one_by(criterias)
            table.where(criterias).first!
          end

          def find_all_by(criterias)
            table.where(criterias)
          end

          def insert(values)
            table.insert(values)
          end

          def update_where(criterias, values)
            find_all_by(criterias).update(values)
          end

          def delete_where(criterias)
            find_all_by(criterias).delete
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
koine-repository-1.1 lib/koine/repository/persistence/adapter/sql.rb
koine-repository-1.0 lib/koine/repository/persistence/adapter/sql.rb
koine-repository-0.9.0 lib/koine/repository/persistence/adapter/sql.rb