Sha256: c2a69f91f3eb650111ef2f12c1c8c70cd8cf8dc9e6005976a7e0980b141af5c6
Contents?: true
Size: 974 Bytes
Versions: 6
Compression:
Stored size: 974 Bytes
Contents
module ApacheAge class Node include ApacheAge::Entities::Node attribute :label, :string attribute :properties # attribute :properties, :hash # def display = [label, properties&.values&.first].compact.join(' - ') def display info = properties&.values&.first info.blank? ? "#{label} (#{id})" : "#{info} (#{label})" end def self.all all_nodes_sql = <<~SQL SELECT * FROM cypher('age_schema', $$ MATCH (node) RETURN node $$) as (node agtype); SQL age_results = ActiveRecord::Base.connection.execute(all_nodes_sql) return [] if age_results.values.count.zero? age_results.values.map do |result| json_string = result.first.split('::').first hash = JSON.parse(json_string) attribs = hash.slice('id', 'label').symbolize_keys attribs[:properties] = hash['properties'].symbolize_keys new(**attribs) end end end end
Version data entries
6 entries across 6 versions & 1 rubygems