Nashorn JS Driver/wrapper

21 views
Skip to first unread message

ad...@cs.miami.edu

unread,
Sep 11, 2017, 9:12:47 PM9/11/17
to OrientDB
Hi,

My day job is mostly server-side JS using Nashorn.

I noticed that there are native wrappers for groovy/scala but there does not seem to be a native wrapper for Nashorn,  So, I started working on one for my own purposes.  Do you think this is something the larger community would be interested in?

The goal is a light JS/Nashorn wrapper with a streamlined API suitable for scripting environments and  server-side script.   No extra jars are necessary, just include a single JS script the top of your nashorn file.  Here is an example script:

load("OrientDB_Doc.js");
odb
= new ODB();

// opens a DB pool
odb
.openDB("plocal:/orientDB/databases/myTest", "admin", "admin");
odb
.execute("insert into Person (name, age) VALUES ('George Washington', 67)");

// returns native JS code
r
= odb.select("select * from Person");
r
.forEach(function (obj) {
    println
(obj.name + "  " + obj.age);
});
odb
.closePool();


The benefit of using a script like this is the user does not need to worry themselves with the complicated Types that OrientDB has (IMHO).  And the functions (by default, but optionally) return native JS objects instead of ODocuments, which is eaiser to deal with in Nashorn.

The Doc API is almost done, and later I can make the graph API.  Let me know if this is something that the community might want... or perhaps it is already done I just did not see it.

Best,

-Adam

Luca Garulli

unread,
Sep 12, 2017, 10:01:22 AM9/12/17
to OrientDB
Hi Adam,

I think this is very interesting, especially for our JS Functions. Would you like to contribute with a PR?

By the way, have you found a way to protect the user to call things like System.exit()?

Best Regards,

Luca Garulli
Founder & CEO

--

---
You received this message because you are subscribed to the Google Groups "OrientDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to orient-database+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

ad...@cs.miami.edu

unread,
Sep 12, 2017, 1:36:15 PM9/12/17
to OrientDB
Luca,

Sure I will contribute a PR (hopefully in a few days, a little displaced right now from the hurricane).

Regarding protecting certain calls, I have never done this myself, but I think it can be done with a ClassFilter.  https://docs.oracle.com/javase/8/docs/technotes/guides/scripting/nashorn/api.html#classfilter_introduction

You can pass the the ClassFilter to the engine, and control which classes are visible to the script engine, I will see if I can create an example that restricts System.exit().

-Adam
To unsubscribe from this group and stop receiving emails from it, send an email to orient-databa...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages