Hello,

I have been testing a bit more with the syntax you proposed.
My final goal was to be able to call a function insertOrUpdate( json-object 
) that would help support a json webservice.

So I tried your propsal:

*select jsonParameterTest( $j ) LET $j = (select 1 as a, 'zE' as b)*

And that works syntactically.
I also tried some other ways such as

*select jsonParameterTest( map( "a", 1, "b", 'zE' ) )*

*select jsonParameterTest( document( "a", 1, "b", 'zE' ) )*

and they all work, but the 'problem' is.
As soon as you are in javascript I would have expected to be working with 
these parameters as javascript maps or lists, but instead, they are Java 
classes. (=> typeof par == 'object')
Moreover, they all have a different class.


   - in the first example the par.getclass() will return 
   *class com.orientechnologies.orient.core.sql.query.OResultSet*
   (you can cal the iterator that returns ODocuments)
   - in the second exmple the par.getclass() will return 
   *class java.util.HashMap*
   - in the third exmple the par.getclass() will return 
   *class com.orientechnologies.orient.core.record.impl.ODocument*

QUESTIONS:

   - would it be an idea to wrap these as javascript lists and maps, when 
   they are passed to a javascript function, because that's easier to work 
   with from javascript?
   - or alternatively: is there a function that can be called to transform 
   these (regardless whether it's a HashMap, an ODocument or an OResultSet) 
   either to javascript objects directly or that transforms them into json, so 
   I can use JSON.parse( jsonString )
   *[ODocument has a method toJSON, but HashMaps and ResultSets haven't]*

*What do you think?*



Op vrijdag 9 mei 2014 17:19:06 UTC+2 schreef Lvc@:
>
> Hi,
> That syntax is cool, please can you open a new issue to support it?
>
> In the meanwhile as workaround, with 1.7-SNAPSHOT you could do:
>
>
> *select jsonParameterTest( $j ) LET $j = (select 1 as a, 'zE' as b) 
> FETCHPLAN *:1 *
>
> Lvc@
>
>
>
> Lvc@
>
>
> On 6 May 2014 10:35, MrFT <[email protected] <javascript:>> wrote:
>
>> Hello,
>>
>> from what I get so far, the parameters for a server-side javascript 
>> function can be simple things like strings and numbers.
>>
>> My question is: is it possible to have a json object as the parameter?
>>
>> For example, when calling the function 
>>
>> function jsonparameterTest( par )
>>   if ( typeof par == 'object' ) {
>>  return JSON.stringify( par );
>>   }
>>   else { 
>>     return "NO OBJECT: " + par;
>>   }
>> }
>>
>> in the studio like this:
>>
>> select jsonParameterTest( 'mystringparameter' ) FETCHPLAN *:1
>>
>> It works as expected.
>>
>> But when I try (and that's what I would like to do, if possible):
>> select jsonParameterTest( { "a": 1, "b": "zE" } ) FETCHPLAN *:1
>>
>> I get:
>> com.orientechnologies.orient.core.command.script.OCommandScriptException: 
>> Error on parsing script at position #0: Error on execution of the script 
>> Script: jsonParameterTest ------^ --> javax.script.ScriptException: 
>> sun.org.mozilla.javascript.internal.EvaluatorException: Java class 
>> "[Ljava.lang.annotation.Annotation;" has no public instance field or method 
>> named "toJSON". (#93) in at line number 93 --> 
>> sun.org.mozilla.javascript.internal.EvaluatorException: Java class 
>> "[Ljava.lang.annotation.Annotation;" has no public instance field or method 
>> named "toJSON". (#93)
>>
>>  So my question is:
>>
>>    - can this be done, and  
>>    - if so, what am I doing wrong?
>>    
>>
>>  -- 
>>
>> --- 
>> 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] <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 

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