Class: OrientdbClient::Node
- Inherits:
-
Object
- Object
- OrientdbClient::Node
- Defined in:
- lib/orientdb_client.rb
Instance Attribute Summary collapse
-
#database ⇒ Object
readonly
Returns the value of attribute database.
-
#debug ⇒ Object
writeonly
Sets the attribute debug.
Instance Method Summary collapse
- #alter_property(class_name, property_name, field, value) ⇒ Object
- #command(sql) ⇒ Object
- #connect(database) ⇒ Object
- #connected? ⇒ Boolean
- #create_class(name, options) ⇒ Object
- #create_database(name, storage, type, options) ⇒ Object
- #create_property(class_name, property_name, type, options) ⇒ Object
- #delete_database(name, options) ⇒ Object
- #disconnect ⇒ Object
- #drop_class(name) ⇒ Object
- #get_class(name) ⇒ Object
- #get_database(name, options) ⇒ Object
- #has_class?(name) ⇒ Boolean
-
#initialize(host:, port:, http_client:, client:) ⇒ Node
constructor
A new instance of Node.
- #list_databases ⇒ Object
- #query(sql, options) ⇒ Object
- #query_unparsed(sql, options) ⇒ Object
Constructor Details
#initialize(host:, port:, http_client:, client:) ⇒ Node
Returns a new instance of Node.
143 144 145 146 147 148 149 150 151 |
# File 'lib/orientdb_client.rb', line 143 def initialize(host:, port:, http_client:, client:) @host = host @port = port @http_client = http_client @client = client @connected = false @database = nil @debug = false end |
Instance Attribute Details
#database ⇒ Object (readonly)
Returns the value of attribute database.
140 141 142 |
# File 'lib/orientdb_client.rb', line 140 def database @database end |
#debug=(value) ⇒ Object (writeonly)
Sets the attribute debug
141 142 143 |
# File 'lib/orientdb_client.rb', line 141 def debug=(value) @debug = value end |
Instance Method Details
#alter_property(class_name, property_name, field, value) ⇒ Object
212 213 214 |
# File 'lib/orientdb_client.rb', line 212 def alter_property(class_name, property_name, field, value) command("ALTER PROPERTY #{class_name}.#{property_name} #{field} #{value}") end |
#command(sql) ⇒ Object
227 228 229 230 |
# File 'lib/orientdb_client.rb', line 227 def command(sql) r = request(:post, "command/#{@database}/sql/#{CGI::escape(sql)}") parse_response(r) end |
#connect(database) ⇒ Object
153 154 155 156 157 158 |
# File 'lib/orientdb_client.rb', line 153 def connect(database) request(:get, "connect/#{database}") @connected = true @database = database true end |
#connected? ⇒ Boolean
247 248 249 |
# File 'lib/orientdb_client.rb', line 247 def connected? @connected == true end |
#create_class(name, options) ⇒ Object
193 194 195 196 197 198 199 |
# File 'lib/orientdb_client.rb', line 193 def create_class(name, ) sql = "CREATE CLASS #{name}" sql << " EXTENDS #{[:extends]}" if .key?(:extends) sql << " CLUSTER #{[:cluster]}" if .key?(:cluster) sql << ' ABSTRACT' if .key?(:abstract) command(sql) end |
#create_database(name, storage, type, options) ⇒ Object
166 167 168 169 |
# File 'lib/orientdb_client.rb', line 166 def create_database(name, storage, type, ) r = request(:post, "database/#{name}/#{storage}/#{type}", ) parse_response(r) end |
#create_property(class_name, property_name, type, options) ⇒ Object
205 206 207 208 209 210 |
# File 'lib/orientdb_client.rb', line 205 def create_property(class_name, property_name, type, ) command("CREATE PROPERTY #{class_name}.#{property_name} #{type}") .each do |k, v| alter_property(class_name, property_name, k, v) end end |
#delete_database(name, options) ⇒ Object
171 172 173 174 |
# File 'lib/orientdb_client.rb', line 171 def delete_database(name, ) r = request(:delete, "database/#{name}", ) parse_response(r) end |
#disconnect ⇒ Object
160 161 162 163 164 |
# File 'lib/orientdb_client.rb', line 160 def disconnect request(:get, 'disconnect') rescue UnauthorizedError @connected = false true end |
#drop_class(name) ⇒ Object
201 202 203 |
# File 'lib/orientdb_client.rb', line 201 def drop_class(name) command("DROP CLASS #{name}") end |
#get_class(name) ⇒ Object
232 233 234 235 236 237 |
# File 'lib/orientdb_client.rb', line 232 def get_class(name) r = request(:get, "class/#{@database}/#{name}") parse_response(r) rescue IllegalArgumentException raise NotFoundError end |
#get_database(name, options) ⇒ Object
176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/orientdb_client.rb', line 176 def get_database(name, ) r = request(:get, "database/#{name}", ) r = parse_response(r) rescue UnauthorizedError => e # Attempt to get not-found db, when connected, will return 401 error. if connected? raise NotFoundError.new("Database #{name} not found, or you are not authorized to access it.", 401) else raise e end end |
#has_class?(name) ⇒ Boolean
239 240 241 242 243 244 245 |
# File 'lib/orientdb_client.rb', line 239 def has_class?(name) if get_class(name) return true end rescue NotFoundError return false end |
#list_databases ⇒ Object
188 189 190 191 |
# File 'lib/orientdb_client.rb', line 188 def list_databases r = request(:get, 'listDatabases') parse_response(r)['databases'] end |
#query(sql, options) ⇒ Object
216 217 218 |
# File 'lib/orientdb_client.rb', line 216 def query(sql, ) parse_response(query_unparsed(sql, ))['result'] end |
#query_unparsed(sql, options) ⇒ Object
220 221 222 223 224 225 |
# File 'lib/orientdb_client.rb', line 220 def query_unparsed(sql, ) limit = limit_string() request(:get, "query/#{@database}/sql/#{CGI::escape(sql)}#{limit}") rescue NegativeArraySizeException raise NotFoundError end |