Search code examples
orientdb

How do I execute an orient db batch script?


I'm playing around with orient db for the first time. I have it up and running and I can execute simple scripts via the console.

However, what I really want to do is to use the extra SQL Batch commands such as 'let.'

e.g. the sample script from the wiki:

begin
let account = create vertex Account set name = 'Luke'
let city = select from City where name = 'London'
let edge = create edge Lives from $account to $city
commit retry 100
return $edge

If I write a script using those commands, the console throws errors as they don't appear to be supported. The wiki suggests that's because they are only available via the Java and HTTP APIs.

Pasting the content of the script into Studio works fine, but that's a fairly unsatisfactory way to run a simple script.

Am I missing something or is there no way to run a script containing SQL Batch commands via a simple command line instruction?


Solution

  • You can execute it from console by using the script sql command. Remember to close it by typing end on a new line. Example:

    MacBook-Pro:bin luca$ ./console.sh
    
    OrientDB console v.2.0-SNAPSHOT (build 2539) www.orientechnologies.com
    Type 'help' to display all the supported commands.
    Installing extensions for GREMLIN language v.2.6.0
    
    orientdb> connect plocal:/temp/databases/ETLDemo admin admin
    
    Connecting to database [plocal:/temp/databases/ETLDemo] with user 'admin'...OK
    orientdb {db=ETLDemo}> script sql
    [Started multi-line command. Type just 'end' to finish and execute]
    orientdb {db=ETLDemo}> begin
    orientdb {db=ETLDemo}> let a = create vertex v
    orientdb {db=ETLDemo}> commit retry 100
    orientdb {db=ETLDemo}> end
    
    Server side script executed in 0,117000 sec(s). Value returned is: V#9:199 v1
    orientdb {db=ETLDemo}>