Class: OrientdbClient::Client

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/orientdb_client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Client

Returns a new instance of Client.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/orientdb_client.rb', line 26

def initialize(options)
  options = {
    host: 'localhost',
    port: '2480'
  }.merge(options)
  @host = options[:host]
  @port = options[:port]
  adapter_klass = if options[:adapter]
                    HttpAdapters.const_get(options[:adapter])
                  else
                    HttpAdapters::TyphoeusAdapter
                  end
  @instrumenter = options[:instrumenter] || Instrumenters::Noop
  @http_client = adapter_klass.new(timeout: options[:timeout])
  @node = Node.new(host: @host, port: @port, http_client: @http_client, client: self)
  @connected = false
  self
end

Instance Attribute Details

#http_clientObject (readonly)

Returns the value of attribute http_client.



22
23
24
# File 'lib/orientdb_client.rb', line 22

def http_client
  @http_client
end

Instance Method Details

#alter_property(class_name, property_name, field, value) ⇒ Object



85
86
87
# File 'lib/orientdb_client.rb', line 85

def alter_property(class_name, property_name, field, value)
  @node.alter_property(class_name, property_name, field, value)
end

#command(sql) ⇒ Object



121
122
123
# File 'lib/orientdb_client.rb', line 121

def command(sql)
  @node.command(sql)
end

#connect(username:, password:, db:) ⇒ Object

Raises:



45
46
47
48
49
50
51
52
53
# File 'lib/orientdb_client.rb', line 45

def connect(username:, password:, db:)
  raise ClientError.new('Already connected') if connected?
  @username = username
  @password = password
  @db = db
  @http_client.username = @username
  @http_client.password = @password
  @node.connect(@db)
end

#connected?Boolean

Returns:

  • (Boolean)


125
126
127
# File 'lib/orientdb_client.rb', line 125

def connected?
  @node.connected?
end

#create_class(name, options = {}) ⇒ Object



73
74
75
76
77
78
79
# File 'lib/orientdb_client.rb', line 73

def create_class(name, options = {})
  response = @node.create_class(name, options)
  if block_given?
    yield ClassConfigurator.new(name, @node)
  end
  response
end

#create_database(name, storage, type, options = {}) ⇒ Object

Raises:

  • (ArgumentError)


64
65
66
67
# File 'lib/orientdb_client.rb', line 64

def create_database(name, storage, type, options = {})
  raise ArgumentError, "Invalid database type: #{type}" unless DATABASE_TYPES.include?(type)
  @node.create_database(name, storage, type, options)
end

#create_property(class_name, property_name, type, options = {}) ⇒ Object



81
82
83
# File 'lib/orientdb_client.rb', line 81

def create_property(class_name, property_name, type, options = {})
  @node.create_property(class_name, property_name, type, options)
end

#databaseObject



129
130
131
# File 'lib/orientdb_client.rb', line 129

def database
  @node.database
end

#database_exists?(name) ⇒ Boolean

Returns:

  • (Boolean)


105
106
107
# File 'lib/orientdb_client.rb', line 105

def database_exists?(name)
  list_databases.include?(name)
end

#debug=(val) ⇒ Object



133
134
135
# File 'lib/orientdb_client.rb', line 133

def debug=(val)
  @node.debug = val
end

#delete_database(name, options = {}) ⇒ Object



69
70
71
# File 'lib/orientdb_client.rb', line 69

def delete_database(name, options = {})
  @node.delete_database(name, options)
end

#disconnectObject

Raises:



55
56
57
58
59
60
61
62
# File 'lib/orientdb_client.rb', line 55

def disconnect
  raise ClientError.new('Not connected') unless connected?
  @username = nil
  @password = nil
  @db = nil
  @http_client.reset_credentials
  @node.disconnect
end

#drop_class(name) ⇒ Object



97
98
99
# File 'lib/orientdb_client.rb', line 97

def drop_class(name)
  @node.drop_class(name)
end

#get_class(name) ⇒ Object



89
90
91
# File 'lib/orientdb_client.rb', line 89

def get_class(name)
  @node.get_class(name)
end

#get_database(name, options = {}) ⇒ Object



101
102
103
# File 'lib/orientdb_client.rb', line 101

def get_database(name, options = {})
  @node.get_database(name, options)
end

#has_class?(name) ⇒ Boolean

Returns:

  • (Boolean)


93
94
95
# File 'lib/orientdb_client.rb', line 93

def has_class?(name)
  @node.has_class?(name)
end

#list_databasesObject



109
110
111
# File 'lib/orientdb_client.rb', line 109

def list_databases
  @node.list_databases
end

#query(sql, options = {}) ⇒ Object



113
114
115
# File 'lib/orientdb_client.rb', line 113

def query(sql, options = {})
  @node.query(sql, options)
end

#query_unparsed(sql, options = {}) ⇒ Object



117
118
119
# File 'lib/orientdb_client.rb', line 117

def query_unparsed(sql, options = {})
  @node.query_unparsed(sql, options)
end