rgb
rgb

Reputation: 553

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

Upvotes: 5

Views: 3006

Answers (1)

rmuller
rmuller

Reputation: 12859

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

Upvotes: 7

Related Questions