Answer 1: Nope. No good docs.
Answer 2: The following worked in 2.1 rc3

orient.getGraph().command( "sql", "update Item set l_tags = '' where @rid in 
?", [tagged] );


So you could try

var nearbyNodes = mydb.command('sql',"select in('Contributes_To') from " 
+originNode, []);


Notice the the empty array. Maybe it's a required parameter.


Answer 3:

Check out 

https://github.com/orientechnologies/orientdb/issues/2390


Here's what I'm using (from above link without some logging code).

toJSObject = """
// This function should return a javascript object when you give it java object 
like List, Map, OResultSet etc. //
//function toJSObject(obj) {
    function mapToJSObject(m) {
        var ret = {};
        // log("" + m + " IS A MAP (" + m.getClass() + ")");
        var it = m.keySet().iterator();
        while (it.hasNext()) {
            var key = it.next();
            ret[key] = toJSObject(m.get(key));
        }

        return ret;
    };

    function collectionToJSObject(c) {
        var ret = [];
        // log("" + c + " IS A COLLECTION (" + c.getClass() + ")");
        var it = c.iterator();
        while (it.hasNext()) {
            ret.push(toJSObject(it.next()));
        }

        return ret;
    };

    if (obj == null) {
        return "";
    } else if (typeof obj == 'object') {
        if (obj.getClass) {
            //it's a java object !!!
            var objClass = obj.getClass();
            if (objClass == "class java.lang.String") {
                return new String(obj);
            } else if (objClass == "class java.lang.Integer" || objClass == 
"class java.lang.Long") {
                return parseInt(obj);
            } else if (objClass == "class java.lang.Float" || objClass == 
"class java.lang.Double") {
                return parseFloat(obj);
            } else if (obj.iterator) {
                //Java COLLECTION (example ArrayList)
                return collectionToJSObject(obj);
            } else if (obj.keySet) {
                //it's a Map (class java.util.HashMap for example)
                return mapToJSObject(obj);
            } else if (obj.getKey) {
                // class java.util.LinkedHashMap
                var ret = {};
                ret[obj.getKey()] = toJSObject(obj.getValue());
                return ret;
            } else {
                var ret = "[" + obj.getClass() + " Fields] ";
                for (var key in obj) {
                    ret += key + ", ";
                }
                return ret;
            }
        } else {
            var ret = {};
            for (var key in obj) {
                if (obj.hasOwnProperty(key)) {
                    ret[key] = toJSObject(obj[key]);
                }
            }
            return ret;
        }
    } else { //return as-is
        return obj;
    }
//}
"""



*Other tips.*

*1. Hook functions provide the 'doc' variable that you can use. For example.*

*var val = doc.field('propName')*


*2. See the following file for other methods provided by 'doc'*

core/src/main/java/com/orientechnologies/orient/core/record/impl/ODocument.java 
<https://github.com/orientechnologies/orientdb/blob/9c8c12bc1207e6607048ba94527bd1c09b32bcfa/core/src/main/java/com/orientechnologies/orient/core/record/impl/ODocument.java>
 


3. If you are making changes in the hook function, be sure to 

return 'RECORD_CHANGED';


4. Where java function requires a vararg (...), provide an array, even for 
single values. For example, to save an array to a field.

var OType = com.orientechnologies.orient.core.metadata.schema.OType

doc.field('prop1', arrayValue, [OType.EMBEDDEDSET])





On Monday, May 25, 2015 at 10:21:30 AM UTC-7, Joao Barcia wrote:
>
> Hi everyone,
>
> First of all, thanks for the great work on OrientDB! We've been really 
> amazed with it. The only major roadblock we have found is functions.
>
> We've spent some time trying to implement simple functions in the studio 
> and the lack of documentation mixed with seemingly changing syntax makes 
> things quite difficult. i.e.: orient.getGraph() function seems to work on 
> 2.0.3 but not on 2.0.9 or 2.1-rc2. 
>
> Here is the code we have so far running on 2.0.3:
> "
> var mydb = orient.getGraph();
>
> var nearbyNodes = mydb.command('sql',"select in('Contributes_To') from " 
> +originNode);
>
> return nearbyNodes;
> "
>
> I would like to iterate through each of the nodes returned from the query. 
> Inside of each node I would like to apply a javascript function 
> "propagation()" to the parameter "activation" from that node and change it 
> accordingly.
>
> So,
>
> *QUESTION 1* - Is there an updated and reliable documentation source for 
> JavaScript Functions in OrientDB?
> *QUESTION 2* - What is the correct way of doing an SQL command for newer 
> versions (2.0.9 and 2.1-rc2)? The example above does not seem to work in 
> new versions.
> *QUESTION 3* - What is the correct way of handling the returned objects? 
> As it was explained here 
> <http://stackoverflow.com/questions/27657784/how-to-extract-the-result-of-a-query-from-json-inside-a-custom-javascript-functi>
>  
> does not seem to work
>
> Thank you very much
>
>
> Cheers,
> Joao
>

-- 

--- 
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