Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Empty all the rows in Orient-DB

Is there are a command to flush/empty all the classes/clusters in Orient-DB.

Like Empty function in MySQL.

P.S : Searched here as well : https://github.com/orientechnologies/orientdb/wiki/Console-Commands

like image 808
rgb Avatar asked Mar 17 '23 06:03

rgb


1 Answers

There is no such command available.

If you want to preserve the meta data of the classes, you can use the truncate command (same as most RDBMS). It deletes all records from all clusters of the specified class (but keeps the meta data about the class):

truncate class <yourclass>

If you want to truncate all custom classes (so excluding the OrientDB classes, which all start with capital "O"), you can use this script:

  connect plocal:<yoururl> <yourusername> <yourpassword>;
  js var result = db.query('select name from (select expand(classes) from metadata:schema) where name.charAt(0) <> "O"'); 
  for (var i = 0; i < result.length; i++) { 
    var className = result[i].getRecord().field('name'); 
    db.command('truncate class ' + className);
  }; 
  result.length + ' classes truncated'; 
  end;
  exit

Save this script as truncate-all.osql. To execute this script, go to ORIENTDB_HOME/bin directory and execute:

$ ./console.sh truncate-all.osql
like image 147
rmuller Avatar answered Mar 28 '23 07:03

rmuller