Module: ActiveGraph::Core::Schema
- Included in:
- Base
- Defined in:
- lib/active_graph/core/schema.rb
Constant Summary collapse
- FILTER =
{ 3 => [:type, 'node_unique_property'], 4 => [:uniqueness, 'UNIQUE'], }
Instance Method Summary collapse
- #constraint_owned?(record) ⇒ Boolean
- #constraints ⇒ Object
- #indexes ⇒ Object
- #normalize(result, *extra) ⇒ Object
- #raw_indexes ⇒ Object
- #version ⇒ Object
- #version?(requirement) ⇒ Boolean
Instance Method Details
#constraint_owned?(record) ⇒ Boolean
53 54 55 |
# File 'lib/active_graph/core/schema.rb', line 53 def constraint_owned?(record) FILTER[major]&.then { |(key, value)| record[key] == value } || record[:owningConstraint] end |
#constraints ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/active_graph/core/schema.rb', line 32 def constraints if version?('<4.3') raw_indexes.select(&method(:constraint_owned?)) else raw_constraints.select(&method(:constraint_filter)) end.map { |row| definition(row, :constraint_cypher).merge(type: :uniqueness) } end |
#indexes ⇒ Object
21 22 23 |
# File 'lib/active_graph/core/schema.rb', line 21 def indexes normalize(raw_indexes, *%i[type state]) end |
#normalize(result, *extra) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/active_graph/core/schema.rb', line 25 def normalize(result, *extra) result.map do |row| definition(row, version?('<4') ? :index_cypher_v3 : :index_cypher) .merge(extra.to_h { |key| [key, row[key].to_sym] }) end end |
#raw_indexes ⇒ Object
46 47 48 49 50 51 |
# File 'lib/active_graph/core/schema.rb', line 46 def raw_indexes read_transaction do query(version?('<4.3') ? 'CALL db.indexes()' : 'SHOW INDEXES YIELD *', {}, skip_instrumentation: true) .reject { |row| row[:type] == 'LOOKUP' } end end |
#version ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/active_graph/core/schema.rb', line 9 def version @version ||= read_transaction do # BTW: community / enterprise could be retrieved via `result.first.edition` query('CALL dbms.components()', {}, skip_instrumentation: true).first[:versions][0] .then(&Gem::Version.method(:new)) end end |
#version?(requirement) ⇒ Boolean
17 18 19 |
# File 'lib/active_graph/core/schema.rb', line 17 def version?(requirement) Gem::Requirement.create(requirement).satisfied_by?(Gem::Version.new(version)) end |