Thanks for the reply.

I did try what you suggested with my basic example using var db = 
orient.getDatabase() instead of var db = orient.getGraph() and it now works 
(doesn't crash) on both the server and via ReactJs.  Not sure where I saw 
getGraph() but it was running in Studio so I didn't give that a second 
thought.

But the data isn't as I'd expect.

In Studio/Functions I see everything expanded but from Node/ReactJs I only 
get the ids...   *Any ideas how to expand that before it's sent down?*

[
    {
        "@type": "d",
        "@rid": "#5:0",
        "@version": 2,
        "@class": "OUser",
        "name": "admin",
        "password": 
"{SHA-256}AA6C00A14B7C8EC02F1849F51DC96EA55504E1F55E793C6840007848B6724EC2",
        "status": "ACTIVE",
        "roles": [
            "#4:0"
        ],
        "@fieldTypes": "roles=n"
    },
    {
        "@type": "d",
        "@rid": "#5:1",
        "@version": 1,
        "@class": "OUser",
        "name": "reader",
        "password": 
"{SHA-256}3D0941964AA3EBDCB00CCEF58B1BB399F9F898465E9886D5AEC7F31090A0FB30",
        "status": "ACTIVE",
        "roles": [
            "#4:1"
        ],
        "@fieldTypes": "roles=n"
    },...

JSON in JavaScript result...

[{"@type":"d","testfunction2":["#5:0","#5:1","#5:2"],"@rid":"#-2:1"}]

Oh, it's not expanded when I call it from the Browse tab of Orient Studio 
either...

SELECT testfunction2()

 #5:0    #5:1 #  #5:2  


My server side function is now as follows:

//var g = orient.getGraph();
//var results = g.command("sql", "SELECT FROM OUser");
//return results; 


var db = orient.getDatabase();
var cmd = 'SELECT * FROM OUser';
var result = db.command(cmd);
return result;



- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
- - 

PS  Maybe the bug is with orient.getGraph() -- it's in every example that I 
see..

>From http://orientdb.com/docs/2.0/orientdb.wiki/Functions.html

> Access to the databases from Functions
>
> OrientDB always binds a special variable "orient" to use OrientDB services 
> from inside the functions. The most important methods are:
>
>    - *orient.getGraph()*, returns the current transactional graph database 
>    
> <http://www.orientechnologies.com/javadoc/latest/com/tinkerpop/blueprints/impls/orient/OrientGraph.html>
>     instance
>    - *orient.getGraphNoTx()*, returns the current non-transactional graph 
>    database 
>    
> <http://www.orientechnologies.com/javadoc/latest/com/tinkerpop/blueprints/impls/orient/OrientGraphNoTx.html>
>     instance
>    - *orient.getDatabase()*, returns the current document database 
>    
> <http://www.orientechnologies.com/javadoc/latest/com/orientechnologies/orient/core/db/document/ODatabaseDocumentTx.html>
>     instance
>
>
and...

http://stackoverflow.com/questions/27657784/how-to-extract-the-result-of-a-query-from-json-inside-a-custom-javascript-functi
http://pizzaconnections.net/2015/04/02/orientdb-functions-by-samples-1/
https://groups.google.com/forum/#!topic/orient-database/3ByJk559flw
https://github.com/orientechnologies/orientdb/issues/4255
https://github.com/orientechnologies/orientdb/issues/4053



On Thursday, September 10, 2015 at 8:04:28 PM UTC+3, David Carr wrote:
>
> I use orientjs and javascript server-side functions extensively on 2.1.1. 
>> Not sure which part of this is causing your issue but my server-side 
>> functions generally follow this pattern:
>>
>
> var db = orient.getDatabase();
> var cmd = 'select from #19:1';
> var result = db.command(cmd);
> return result;
>
> I'd recommend running your server-side function via orient's web front-end
>
> http://<host>:2480/studio/index.html#/database/<db_name>/functions 
>
> to make sure they are performing properly and then if you are still having 
> problems you'll know the problem is on the orienjs side. Feel free to post 
> back if I can help more.
>

-- 

--- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to