Class: Orientdb4r::Client
- Inherits:
-
Object
- Object
- Orientdb4r::Client
- Includes:
- Utils
- Defined in:
- lib/orientdb4r/client.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#command(sql) ⇒ Object
Executes a command against the database.
-
#connect(options) ⇒ Object
Connects client to the server.
-
#connected? ⇒ Boolean
Gets flag whenever the client is connected or not.
-
#create_class(name, options = {}) ⇒ Object
Creates a new class in the schema.
-
#create_database(options) ⇒ Object
Creates a new database.
-
#create_document(doc) ⇒ Object
Create a new document.
-
#create_property(clazz, property, type, options = {}) ⇒ Object
Creates a new property in the schema.
-
#delete_document(rid) ⇒ Object
Deletes an existing document.
-
#disconnect ⇒ Object
Disconnects client from the server.
-
#drop_class(name, options = {}) ⇒ Object
Removes a class from the schema.
-
#get_class(name) ⇒ Object
Gets informations about requested class.
-
#get_document(rid) ⇒ Object
Retrieves a document by given ID.
-
#initialize ⇒ Client
constructor
Constructor.
-
#query(sql) ⇒ Object
Executes a query against the database.
-
#server(options = {}) ⇒ Object
Retrieve information about the connected OrientDB Server.
-
#update_document(doc) ⇒ Object
Updates an existing document.
Methods included from Utils
#blank?, #random_string, #verify_and_sanitize_options, #verify_options
Constructor Details
#initialize ⇒ Client
Constructor.
8 9 10 |
# File 'lib/orientdb4r/client.rb', line 8 def initialize @connected = false end |
Instance Method Details
#command(sql) ⇒ Object
Executes a command against the database.
71 72 73 |
# File 'lib/orientdb4r/client.rb', line 71 def command(sql) raise NotImplementedError, 'this should be overridden by concrete client' end |
#connect(options) ⇒ Object
Connects client to the server.
16 17 18 |
# File 'lib/orientdb4r/client.rb', line 16 def connect raise NotImplementedError, 'this should be overridden by concrete client' end |
#connected? ⇒ Boolean
Gets flag whenever the client is connected or not.
30 31 32 |
# File 'lib/orientdb4r/client.rb', line 30 def connected? @connected end |
#create_class(name, options = {}) ⇒ Object
Creates a new class in the schema.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/orientdb4r/client.rb', line 79 def create_class(name, ={}) raise ArgumentError, "class name is blank" if blank?(name) opt_pattern = { :extends => :optional , :cluster => :optional, :force => false } (, opt_pattern) sql = "CREATE CLASS #{name}" sql << " EXTENDS #{[:extends]}" if .include? :extends sql << " CLUSTER #{[:cluster]}" if .include? :cluster drop_class name if [:force] command sql if block_given? proxy = Orientdb4r::Utils::Proxy.new(self, name) def proxy.property(property, type, ={}) self.target.send :create_property, self.context, property, type, end yield proxy end end |
#create_database(options) ⇒ Object
Creates a new database. You can provide an additional authentication to the server with ‘database.create’ resource or the current one will be used.
49 50 51 |
# File 'lib/orientdb4r/client.rb', line 49 def create_database() raise NotImplementedError, 'this should be overridden by concrete client' end |
#create_document(doc) ⇒ Object
Create a new document. Returns the Record-id assigned.
150 151 152 |
# File 'lib/orientdb4r/client.rb', line 150 def create_document(doc) raise NotImplementedError, 'this should be overridden by concrete client' end |
#create_property(clazz, property, type, options = {}) ⇒ Object
Creates a new property in the schema. You need to create the class before.
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/orientdb4r/client.rb', line 126 def create_property(clazz, property, type, ={}) raise ArgumentError, "class name is blank" if blank?(clazz) raise ArgumentError, "property name is blank" if blank?(property) opt_pattern = { :mandatory => :optional , :notnull => :optional, :min => :optional, :max => :optional, :regexp => :optional, :custom => :optional } (, opt_pattern) cmd = "CREATE PROPERTY #{clazz}.#{property} #{type.to_s}" command cmd unless .empty? .each do |k,v| command "ALTER PROPERTY #{clazz}.#{property} #{k.to_s.upcase} #{v}" end end end |
#delete_document(rid) ⇒ Object
Deletes an existing document.
171 172 173 |
# File 'lib/orientdb4r/client.rb', line 171 def delete_document(rid) raise NotImplementedError, 'this should be overridden by concrete client' end |
#disconnect ⇒ Object
Disconnects client from the server.
23 24 25 |
# File 'lib/orientdb4r/client.rb', line 23 def disconnect raise NotImplementedError, 'this should be overridden by concrete client' end |
#drop_class(name, options = {}) ⇒ Object
Removes a class from the schema.
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/orientdb4r/client.rb', line 104 def drop_class(name, ={}) raise ArgumentError, "class name is blank" if blank?(name) # :mode=>:strict forbids to drop a class that is a super class for other one opt_pattern = { :mode => :nil } (, opt_pattern) if :strict == [:mode] response = @resource["connect/#{@database}"].get connect_info = process_response(response, :mode => :strict) children = connect_info['classes'].select { |i| i['superClass'] == name } unless children.empty? raise OrientdbError, "class is super-class, cannot be deleted, name=#{name}" end end command "DROP CLASS #{name}" end |
#get_class(name) ⇒ Object
Gets informations about requested class.
56 57 58 |
# File 'lib/orientdb4r/client.rb', line 56 def get_class(name) raise NotImplementedError, 'this should be overridden by concrete client' end |
#get_document(rid) ⇒ Object
Retrieves a document by given ID.
157 158 159 |
# File 'lib/orientdb4r/client.rb', line 157 def get_document(rid) raise NotImplementedError, 'this should be overridden by concrete client' end |
#query(sql) ⇒ Object
Executes a query against the database.
64 65 66 |
# File 'lib/orientdb4r/client.rb', line 64 def query(sql) raise NotImplementedError, 'this should be overridden by concrete client' end |
#server(options = {}) ⇒ Object
Retrieve information about the connected OrientDB Server. Enables additional authentication to the server with an account that can access the ‘server.info’ resource.
39 40 41 |
# File 'lib/orientdb4r/client.rb', line 39 def server(={}) raise NotImplementedError, 'this should be overridden by concrete client' end |
#update_document(doc) ⇒ Object
Updates an existing document.
164 165 166 |
# File 'lib/orientdb4r/client.rb', line 164 def update_document(doc) raise NotImplementedError, 'this should be overridden by concrete client' end |