Module: RestDelete
- Included in:
- ActiveOrient::OrientDB
- Defined in:
- lib/rest/delete.rb
Instance Method Summary collapse
-
#delete_class(o_class) ⇒ Object
Deletes the specified class and returns true on success todo: remove all instances of the class.
-
#delete_database(database:) ⇒ Object
Deletes the database and returns true on success After the removal of the database, the working-database might be empty.
-
#delete_property(o_class, field) ⇒ Object
PROPERTY #############.
-
#delete_record(*rid) ⇒ Object
(also: #delete_document)
Deletes a single Record when providing a single rid-link (#00:00) or a record Deletes multible Records when providing a list of rid-links or a record Todo: implement delete_edges after querying the database in one statement.
-
#delete_records(o_class, where: {}) ⇒ Object
(also: #delete_documents)
Deletes records.
Instance Method Details
#delete_class(o_class) ⇒ Object
Deletes the specified class and returns true on success
todo: remove all instances of the class
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/rest/delete.rb', line 37 def delete_class o_class cl = classname(o_class) return if cl.nil? logger.progname = 'RestDelete#DeleteClass' begin ## to do: if cl contains special characters, enclose with backticks response = @res["/class/#{ActiveOrient.database}/#{cl}"].delete if response.code == 204 logger.info{"Class #{cl} deleted."} ActiveOrient.database_classes.delete(cl) end rescue RestClient::InternalServerError => e sentence= JSON.parse( e.response)['errors'].last['content'] if database_classes(requery: true).include?(cl) logger.error{"Class #{cl} still present."} logger.error{ sentence } false else logger.error{e.inspect} true end rescue Exception => e logger.error{e.} logger.error{e.inspect} end end |
#delete_database(database:) ⇒ Object
Deletes the database and returns true on success
After the removal of the database, the working-database might be empty
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/rest/delete.rb', line 10 def delete_database database: logger.progname = 'RestDelete#DeleteDatabase' old_ds = ActiveOrient.database change_database database begin response = @res["/database/#{ActiveOrient.database}"].delete if database == old_ds change_database 'temp' logger.info{"Working database deleted, switched to temp"} else change_database old_ds logger.info{"Database #{database} deleted, working database is still #{ActiveOrient.database}"} end rescue RestClient::InternalServerError => e change_database old_ds logger.info{"Database #{database} NOT deleted, working database is still #{ActiveOrient.database}"} end !response.nil? && response.code == 204 ? true : false end |
#delete_property(o_class, field) ⇒ Object
PROPERTY #############
123 124 125 126 127 128 129 130 131 132 |
# File 'lib/rest/delete.rb', line 123 def delete_property o_class, field logger.progname = 'RestDelete#DeleteProperty' begin response = @res["/property/#{ActiveOrient.database}/#{classname(o_class)}/#{field}"].delete true if response.code == 204 rescue RestClient::InternalServerError => e logger.error{"Property #{field} in class #{classname(o_class)} NOT deleted" } false end end |
#delete_record(*rid) ⇒ Object Also known as: delete_document
Deletes a single Record when providing a single rid-link (#00:00) or a record
Deletes multible Records when providing a list of rid-links or a record
Todo: implement delete_edges after the database in one statement
Example:
record = Vertex.create_document attributes: { something: 'something' }
Vertex.delete_record record
records= (1..100).map{|x| Vertex.create_document attributes: { something: x } }
Vertex.delete_record *records
delete_records provides the removal of datasets after quering the database.
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/rest/delete.rb', line 82 def delete_record *rid logger.progname = "ActiveOrient::RestDelete#DeleteRecord" ridvec= rid.map( &:to_orient).flatten unless ridvec.empty? ridvec.map do |rid| begin ActiveOrient::Base.remove_rid( ActiveOrient::Base.get_rid(rid) ) @res["/document/#{ActiveOrient.database}/#{rid[1..-1]}"].delete rescue RestClient::InternalServerError => e logger.error{"Record #{rid} NOT deleted"} rescue RestClient::ResourceNotFound logger.error{"Record #{rid} does not exist in the database"} else logger.info{"Record #{rid} deleted"} end end else logger.info{"No record deleted."} return nil end end |
#delete_records(o_class, where: {}) ⇒ Object Also known as: delete_documents
Deletes records. They are defined by a query. All records which match the attributes are deleted.
An Array with freed index-values is returned
110 111 112 113 114 115 116 117 118 |
# File 'lib/rest/delete.rb', line 110 def delete_records o_class, where: {} logger.progname = 'RestDelete#DeleteRecords' records_to_delete = get_records(from: o_class, where: where) if records_to_delete.empty? logger.info{"No record found"} else delete_record records_to_delete end end |