neo4j_bolt 0.1.10 → 0.1.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 45867052ad9a321932107079e772e8761b0eff8e365b7eb6b43f90d54cd04eda
4
- data.tar.gz: d5b5eadc6aa0de7688e1541dd9d51f631054037cb3dadb2dac2c509fc434db83
3
+ metadata.gz: a6a4dbb95903cee8767e0bedddfc189bb84c928b0a8b2f62808334657dcf7b8d
4
+ data.tar.gz: fccd788fece9a384523f4c078545c9ee91d926dd8b24ef948c34e050f1341654
5
5
  SHA512:
6
- metadata.gz: 59133a33da831e7f411e7ba43fc15a98c24335418736ed328277e95462777ab7e5cf649fd26af53f0449075ca589f3b796e543b9d7c25f7232fba4007ebfbba4
7
- data.tar.gz: bca9930c52c1a06e7a47a010b5f2f0c029dbd38ee4c360f550ea84a8f2d0c8913b66c48978ff1fc0211768367290692ffcb9997b68b77515fcd550e9ad271bbe
6
+ metadata.gz: d9894b97771c25b396a6a6782a7b6cc5b2788f4aec0cb5484a0a57230c7e9d32ef708042b271425f4d2c5c829f7f5148e2ba96cee5ff9b525d8c1fdcaafebbaa
7
+ data.tar.gz: d40735d1326f0318dc54ec67568b35d091a0736447a6d082b32e538c8d9d241dbf25af50e591c3e924b46a64fe65ef2c9578e2796f4c6cac3f8c089d1c9f33b1
data/Gemfile.lock CHANGED
@@ -1,7 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- neo4j_bolt (0.1.8)
4
+ neo4j_bolt (0.1.12)
5
+ gli
5
6
 
6
7
  GEM
7
8
  remote: https://rubygems.org/
data/bin/neo4j_bolt CHANGED
@@ -83,6 +83,52 @@ class App
83
83
 
84
84
  # --------------------------------------------
85
85
 
86
+ desc 'Show or remove constraints and indexes'
87
+ # long_desc 'Clear all nodes and relationships'
88
+ command :index do |c|
89
+ c.command :ls do |c2|
90
+ c2.action do |global_options, options, args|
91
+ neo4j_query("SHOW ALL CONSTRAINTS") do |row|
92
+ # STDERR.puts row.to_yaml
93
+ puts "#{row['type']} #{row['name']} #{row['labelsOrTypes'].join('/')}/#{row['properties'].join('/')}"
94
+ end
95
+ neo4j_query("SHOW ALL INDEXES") do |row|
96
+ # STDERR.puts row.to_yaml
97
+ puts "#{row['uniqueness']} #{row['entityType']} #{row['state']} #{row['populationPercent']}% #{row['name']} #{row['labelsOrTypes'].join('/')}/#{row['properties'].join('/')}"
98
+ end
99
+ end
100
+ end
101
+ c.command :rm do |c2|
102
+ c2.switch [:f, :force], :required => true, :negatable => false, :desc => 'Specify --force to really remove all constraints and indexes'
103
+ c2.action do |global_options, options, args|
104
+ if options[:force]
105
+ all_constraints = []
106
+ all_indexes = []
107
+ neo4j_query("SHOW ALL CONSTRAINTS") do |row|
108
+ all_constraints << row['name']
109
+ end
110
+ neo4j_query("SHOW ALL INDEXES") do |row|
111
+ all_indexes << row['name']
112
+ end
113
+ transaction do
114
+ all_constraints.each do |name|
115
+ STDERR.puts "Removing constraint #{name}"
116
+ neo4j_query("DROP CONSTRAINT #{name} IF EXISTS")
117
+ end
118
+ all_indexes.each do |name|
119
+ STDERR.puts "Removing index #{name}"
120
+ neo4j_query("DROP INDEX #{name} IF EXISTS")
121
+ end
122
+ end
123
+ else
124
+ STDERR.puts "Doing nothing unless you specify --force."
125
+ end
126
+ end
127
+ end
128
+ end
129
+
130
+ # --------------------------------------------
131
+
86
132
  desc 'Visualize database'
87
133
  long_desc 'Generate a GraphViz-formatted visual representation of the database'
88
134
  command :visualize do |c|
@@ -156,6 +202,30 @@ class App
156
202
  end
157
203
  end
158
204
 
205
+ indexes = {}
206
+ INDEX_TR = {
207
+ 'UNIQUENESS' => '<u>unique</u>',
208
+ 'BTREE' => 'indexed',
209
+ }
210
+
211
+ ['SHOW ALL CONSTRAINTS', 'SHOW ALL INDEXES'].each do |query|
212
+ neo4j_query(query) do |row|
213
+ # STDERR.puts row.to_json
214
+ labels_or_types = row['labelsOrTypes'] || []
215
+ properties = row['properties'] || []
216
+ type = row['type']
217
+ entity = row['entityType']
218
+ if labels_or_types.size == 1 && properties.size == 1
219
+ label_or_type = labels_or_types.first
220
+ property = properties.first
221
+ indexes[entity.downcase.to_sym] ||= {}
222
+ indexes[entity.downcase.to_sym][label_or_type] ||= {}
223
+ indexes[entity.downcase.to_sym][label_or_type][property] ||= Set.new()
224
+ indexes[entity.downcase.to_sym][label_or_type][property] << type
225
+ end
226
+ end
227
+ end
228
+
159
229
  dot = StringIO.open do |io|
160
230
  io.puts "digraph {"
161
231
  io.puts "graph [fontname = Helvetica, fontsize = 10, nodesep = 0.2, ranksep = 0.3];"
@@ -172,7 +242,12 @@ class App
172
242
  label += "</td></tr>"
173
243
  properties_for_label[lbl].keys.sort.each do |key|
174
244
  label += "<tr>"
175
- label += "<td border='1' valign='top' align='left' colspan='1'>#{key}</td>"
245
+ parts = Set.new()
246
+ ((((indexes[:node] || {})[lbl] || {})[key.to_s]) || Set.new()).each do |it|
247
+ parts << INDEX_TR[it] || it
248
+ end
249
+ index_s = parts.empty? ? '' : " <i>(#{parts.join(', ')})</i>"
250
+ label += "<td border='1' valign='top' align='left' colspan='1'>#{key}#{index_s}</td>"
176
251
  label += "<td border='1' valign='top' align='left' colspan='1'>#{properties_for_label[lbl][key][:classes].to_a.map { |x| TR[x.to_s] || x.to_s }.sort.join(' / ')}</td>"
177
252
  label += "</tr>"
178
253
  end
@@ -186,15 +261,20 @@ class App
186
261
  lb = parts[2]
187
262
 
188
263
  label = "<<table valign='top' align='left' border='0' cellborder='0' cellspacing='0' cellpadding='4'>"
189
- label += "<tr><td border='1' bgcolor='#d3d7cf' valign='top' align='left' colspan='2'><b>#{type}</b>"
264
+ label += "<tr><td border='1' color='#888888' bgcolor='#d3d7cf' valign='top' align='left' colspan='2'>#{type}"
190
265
  if options[:properties]
191
266
  label += " <i>(#{counts_for_label[s]})</i>"
192
267
  end
193
268
  label += "</td></tr>"
194
269
  (properties_for_label[s] || {}).keys.sort.each do |key|
195
270
  label += "<tr>"
196
- label += "<td border='1' valign='top' align='left' colspan='1'>#{key}</td>"
197
- label += "<td border='1' valign='top' align='left' colspan='1'>#{properties_for_label[s][key][:classes].to_a.map { |x| TR[x.to_s] || x.to_s }.sort.join(' / ')}</td>"
271
+ parts = Set.new()
272
+ ((((indexes[:relationship] || {})[type] || {})[key.to_s]) || Set.new()).each do |it|
273
+ parts << INDEX_TR[it] || it
274
+ end
275
+ index_s = parts.empty? ? '' : " <i>(#{parts.join(', ')})</i>"
276
+ label += "<td border='1' color='#888888' valign='top' align='left' colspan='1'>#{key}#{index_s}</td>"
277
+ label += "<td border='1' color='#888888' valign='top' align='left' colspan='1'>#{properties_for_label[s][key][:classes].to_a.map { |x| TR[x.to_s] || x.to_s }.sort.join(' / ')}</td>"
198
278
  label += "</tr>"
199
279
  end
200
280
  label += "</table>>"
@@ -1,3 +1,3 @@
1
1
  module Neo4jBolt
2
- VERSION = "0.1.10"
2
+ VERSION = "0.1.12"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: neo4j_bolt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.1.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Specht