Module: Legion::Extensions::Neo4j::Runners::Admin

Includes:
Helpers::Lex, Helpers::Client
Included in:
Client
Defined in:
lib/legion/extensions/neo4j/runners/admin.rb

Instance Method Summary collapse

Methods included from Helpers::Client

#connection, #execute_cypher

Instance Method Details

#call_procedure(name:, args: [], database: 'neo4j', url: nil, username: nil, password: nil) ⇒ Object



56
57
58
59
60
61
62
# File 'lib/legion/extensions/neo4j/runners/admin.rb', line 56

def call_procedure(name:, args: [], database: 'neo4j', url: nil, username: nil, password: nil, **)
  arg_placeholders = args.each_index.map { |i| "$arg#{i}" }.join(', ')
  params = args.each_with_index.to_h { |v, i| ["arg#{i}", v] }
  cypher = "CALL #{name}(#{arg_placeholders})"
  execute_cypher(cypher, parameters: params, database: database,
                        url: url, username: username, password: password)
end

#create_database(name:, url: nil, username: nil, password: nil, read_only: false) ⇒ Object

Raises:



32
33
34
35
36
37
# File 'lib/legion/extensions/neo4j/runners/admin.rb', line 32

def create_database(name:, url: nil, username: nil, password: nil, read_only: false, **)
  raise ReadOnlyError, 'Write operations disabled (read_only mode)' if read_only

  execute_cypher("CREATE DATABASE #{name}", parameters: {}, database: 'system',
                                           url: url, username: username, password: password)
end

#database_info(name: 'neo4j', url: nil, username: nil, password: nil) ⇒ Object



27
28
29
30
# File 'lib/legion/extensions/neo4j/runners/admin.rb', line 27

def database_info(name: 'neo4j', url: nil, username: nil, password: nil, **)
  execute_cypher('SHOW DATABASE $name', parameters: { name: name }, database: 'system',
                                        url: url, username: username, password: password)
end

#db_stats(database: 'neo4j', url: nil, username: nil, password: nil) ⇒ Object



64
65
66
67
68
69
70
71
# File 'lib/legion/extensions/neo4j/runners/admin.rb', line 64

def db_stats(database: 'neo4j', url: nil, username: nil, password: nil, **)
  execute_cypher(
    'CALL apoc.meta.stats() YIELD labels, relTypes, nodeCount, relCount ' \
    'RETURN labels, relTypes, nodeCount, relCount',
    parameters: {}, database: database,
    url: url, username: username, password: password
  )
end

#discovery(url: nil, username: nil, password: nil) ⇒ Object



17
18
19
20
# File 'lib/legion/extensions/neo4j/runners/admin.rb', line 17

def discovery(url: nil, username: nil, password: nil, **)
  resp = connection(url: url, username: username, password: password).get('/db/data/')
  resp.body
end

#drop_database(name:, url: nil, username: nil, password: nil, read_only: false) ⇒ Object

Raises:



39
40
41
42
43
44
# File 'lib/legion/extensions/neo4j/runners/admin.rb', line 39

def drop_database(name:, url: nil, username: nil, password: nil, read_only: false, **)
  raise ReadOnlyError, 'Write operations disabled (read_only mode)' if read_only

  execute_cypher("DROP DATABASE #{name} IF EXISTS", parameters: {}, database: 'system',
                                                   url: url, username: username, password: password)
end

#list_databases(url: nil, username: nil, password: nil) ⇒ Object



22
23
24
25
# File 'lib/legion/extensions/neo4j/runners/admin.rb', line 22

def list_databases(url: nil, username: nil, password: nil, **)
  execute_cypher('SHOW DATABASES', parameters: {}, database: 'system',
                                  url: url, username: username, password: password)
end

#list_functions(database: 'neo4j', url: nil, username: nil, password: nil) ⇒ Object



51
52
53
54
# File 'lib/legion/extensions/neo4j/runners/admin.rb', line 51

def list_functions(database: 'neo4j', url: nil, username: nil, password: nil, **)
  execute_cypher('SHOW FUNCTIONS', parameters: {}, database: database,
                                  url: url, username: username, password: password)
end

#list_procedures(database: 'neo4j', url: nil, username: nil, password: nil) ⇒ Object



46
47
48
49
# File 'lib/legion/extensions/neo4j/runners/admin.rb', line 46

def list_procedures(database: 'neo4j', url: nil, username: nil, password: nil, **)
  execute_cypher('SHOW PROCEDURES', parameters: {}, database: database,
                                   url: url, username: username, password: password)
end

#server_info(url: nil, username: nil, password: nil) ⇒ Object



12
13
14
15
# File 'lib/legion/extensions/neo4j/runners/admin.rb', line 12

def server_info(url: nil, username: nil, password: nil, **)
  resp = connection(url: url, username: username, password: password).get('/')
  resp.body
end