Sha256: 81d086a6f38292306a01183bb35bb26e5369b981395fb7dafcae00a8f799778e

Contents?: true

Size: 1 KB

Versions: 2

Compression:

Stored size: 1 KB

Contents

module Architect4r
  module Model
    module Queries
      extend ActiveSupport::Concern
      
      module InstanceMethods
        
      end
      
      module ClassMethods
        
        def count(opts = {}, &block)
          data = connection.execute_cypher("start s=node(#{self.model_root.id}) match (s)<-[:model_type]-(d) return count(d)")
          data.first['count(d)']
        end
        
        def find_by_id(id)
          data = connection.execute_cypher("start s=node(#{self.model_root.id}), d=node(#{id.to_i}) match s<-[r:model_type]-d return d")
          data &&= data.first && data.first['d']
          self.build_from_database(data)
        end
        
        def find_by_id!(id)
          raise 'not implemented'
        end
        
        def find_by_cypher(query, identifier)
          if data = connection.execute_cypher(query)
            data.map { |item| build_from_database(item[identifier]) }
          else
            nil
          end
        end
        
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
architect4r-0.3.3.1 lib/architect4r/model/queries.rb
architect4r-0.3.2 lib/architect4r/model/queries.rb