cParseCom can't query greaterthan and etc keys

26 views
Skip to first unread message

roman.ka...@artua.com

unread,
Mar 10, 2015, 11:06:04 AM3/10/15
to excel-r...@googlegroups.com
Hi,

I found cParseCom library deals inccorrect with $gte $lt and other parse.com keys.

tested:
  var w = getParsed("TimeLog").getObjectsByQuery({sessionTime:{"$gte":115}});

expected:

https://api.parse.com/1/classes/TimeLog?where={"createdAt":{"$gte":"2015-03-06T14:59:29.647Z"}}

got: 

https://api.parse.com/1/classes/TimeLog?where={"createdAt.$gte":"2015-03-06T14:59:29.647Z"}

with error from parse.com: 400:{"code":102,"error":"Invalid key createdAt.$gte for find"}

How to use parse.com keys?

Bruce Mcpherson

unread,
Mar 10, 2015, 11:55:42 AM3/10/15
to excel-r...@googlegroups.com
cParsecom can only do equality for queries.It doesnt know about $gte etc .. so it has translated $gte as a property of createdAt.

But there is an abstraction layer that is the same for a selection of backends including parse (it uses cParsecom behind the scenes) - you just select the appropriate library. I recommend you use this.

You can do > < etc... constraints with this. see the examples below and this write up http://ramblings.mcpher.com/Home/excelquirks/dbabstraction


 function ptest () {
 
 
  // get api key from property store
  var creds = JSON.parse(PropertiesService.getScriptProperties().getProperty('parseKeys'));
  
  // get an abstraction handler
  var handler = new cDbAbstraction.DbAbstraction ( cDriverParse,  {
    "siloid": "polymerdbab",
    "dbid": creds.applicationID,
    "driverob": creds
  });

  // do a query of all data
  var result = handler.query();
  if (result.handleCode < 0) throw JSON.stringify(result);
  
  // show the data
  Logger.log(JSON.stringify(result.data));
  
  // do a normal query
  var result = handler.query({name:"wilma"});
  if (result.handleCode < 0) throw JSON.stringify(result);
  
  // show the data
  Logger.log(JSON.stringify(result.data));
  
  // write something
  var result = handler.save({name:"saved now"});
  if (result.handleCode < 0) throw JSON.stringify(result);
  
  // do a query on creation data with constraints
  var c = cDbAbstraction.ENUMS.CONSTRAINTS;

  var result = handler.query({
    createdAt:handler.constraints([[c.GTE,"2015-03-06T14:59:29.647Z"]]) 
  });
  if (result.handleCode < 0) throw JSON.stringify(result);
  
  // show the data
  Logger.log(JSON.stringify(result.data));

 }



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

Roman Kalisetskiy

unread,
Mar 10, 2015, 12:11:26 PM3/10/15
to excel-r...@googlegroups.com
Thanks, got it.

--
You received this message because you are subscribed to a topic in the Google Groups "Excel Liberation" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/excel-ramblings/mNxbRbkR3SM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to excel-ramblin...@googlegroups.com.

roman.ka...@artua.com

unread,
Mar 10, 2015, 1:16:28 PM3/10/15
to excel-r...@googlegroups.com, roman.ka...@artua.com
Ok, it's worked. But I didn't get createdAt, updatedAt, ACL, objectId fields in results. How to fetch them too?

Bruce Mcpherson

unread,
Mar 10, 2015, 1:27:33 PM3/10/15
to excel-r...@googlegroups.com
  // do a normal query
  var result = handler.query({name:"wilma"},undefined, undefined, true);
  if (result.handleCode < 0) throw JSON.stringify(result);
  
  // show the data
  Logger.log(JSON.stringify(result.data));
  Logger.log(JSON.stringify(result.driverIds));
  Logger.log(JSON.stringify(result.handleKeys));

btw..please cross post with solution to  the g+ community .. the groups forum is dprecated

--

Roman Kalisetskiy

unread,
Mar 10, 2015, 1:35:27 PM3/10/15
to excel-ramblings
Ok, I'll repost it.

Still didn't get objectId, createdAt, updatedAt, ACL. Please look at my code:

  var result = handler.query({
    createdAt:handler.constraints([[c.GTE,"2015-03-10T15:00:00.000Z"], [c.LT, "2015-03-10T15:14:00.000Z"]])
  });
  if (result.handleCode < 0) throw JSON.stringify(result);
  for(var i=0;i<result.data.length;i++){
    Logger.log(i + ": " + JSON.stringify(result.data[i]) + "\n");
  }


And the results in log are:
[15-03-10 19:31:52:530 EET] 0: {"ProjectName":"Time agent 4","project":{"__type":"Pointer","className":"Project","objectId":"Vwct1m2afT"},"sessionTime":5,"updatedAtLocal":{"__type":"Date","iso":"2015-03-10T15:03:57.757Z"},"xenUser":"Digital"}

[15-03-10 19:31:52:531 EET] 1: {"ProjectName":"TimeAgent Test","project":{"__type":"Pointer","className":"Project","objectId":"CVBop4ANMq"},"sessionTime":5,"updatedAtLocal":{"__type":"Date","iso":"2015-03-10T15:04:13.303Z"},"xenUser":"Digital"}

[15-03-10 19:31:52:531 EET] 2: {"ProjectName":"Time agent 4","project":{"__type":"Pointer","className":"Project","objectId":"Vwct1m2afT"},"sessionTime":5,"updatedAtLocal":{"__type":"Date","iso":"2015-03-10T15:14:59.707Z"},"xenUser":"Digital"}

So what's wrong?

--
You received this message because you are subscribed to a topic in the Google Groups "Excel Liberation" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/excel-ramblings/mNxbRbkR3SM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to excel-ramblin...@googlegroups.com.

Bruce Mcpherson

unread,
Mar 10, 2015, 1:41:37 PM3/10/15
to excel-r...@googlegroups.com
You need some additional parameters to ask for special driver fields in a query ... notice that true in my example.. remember that since this is a handler for multiple databases, these fields are all different. Also the special parse fields will be in result.driverIds, not result.data which is reserved for the straight data that was saved. ObjectIds or their equivalent are in result.handleKeys for all drivers.

  var result = handler.query({
    createdAt:handler.constraints([[c.GTE,"2015-03-10T15:00:00.000Z"], [c.LT, "2015-03-10T15:14:00.000Z"]],undefined, undefined, true) 
  });
  if (result.handleCode < 0) throw JSON.stringify(result);
  for(var i=0;i<result.data.length;i++){
    Logger.log(i + ": " + JSON.stringify(result.data[i]) + "\n");
  }
  // show the data
  Logger.log(JSON.stringify(result.data));
  Logger.log(JSON.stringify(result.driverIds));
  Logger.log(JSON.stringify(result.handleKeys));

Roman Kalisetskiy

unread,
Mar 10, 2015, 1:49:18 PM3/10/15
to excel-ramblings
Ok, request with additional parameters still gives me nothing:

  var result = handler.query({
    createdAt:handler.constraints([[c.GTE,"2015-03-10T15:00:00.000Z"], [c.LT, "2015-03-10T15:14:00.000Z"]], undefined, undefined, true) 
  });
  if (result.handleCode < 0) throw JSON.stringify(result);
  Logger.log(JSON.stringify(result.data));
  Logger.log(JSON.stringify(result.driverIds));
  Logger.log(JSON.stringify(result.handleKeys));


***** results are: 

[15-03-10 19:45:54:852 EET] [{"ProjectName":"Time agent 4","project":{"__type":"Pointer","className":"Project","objectId":"Vwct1m2afT"},"sessionTime":5,"updatedAtLocal":{"__type":"Date","iso":"2015-03-10T15:03:57.757Z"},"xenUser":"Digital"},{"ProjectName":"TimeAgent Test","project":{"__type":"Pointer","className":"Project","objectId":"CVBop4ANMq"},"sessionTime":5,"updatedAtLocal":{"__type":"Date","iso":"2015-03-10T15:04:13.303Z"},"xenUser":"Digital"},{"ProjectName":"Time agent 4","project":{"__type":"Pointer","className":"Project","objectId":"Vwct1m2afT"},"sessionTime":5,"updatedAtLocal":{"__type":"Date","iso":"2015-03-10T15:14:59.707Z"},"xenUser":"Digital"}]
[15-03-10 19:45:54:852 EET] undefined
[15-03-10 19:45:54:852 EET] undefined

Bruce Mcpherson

unread,
Mar 10, 2015, 2:01:41 PM3/10/15
to excel-r...@googlegroups.com
your args are inside the object definition, 

should be

  var c = cDbAbstraction.ENUMS.CONSTRAINTS;
  // do a normal query
   var result = handler.query({
    createdAt:handler.constraints( [[c.GTE,"2015-03-10T15:00:00.000Z"], [c.LT, "2015-03-10T17:14:00.000Z"]] )
   }, undefined, undefined, true);
   
  if (result.handleCode < 0) throw JSON.stringify(result);
  Logger.log(JSON.stringify(result.data));
  Logger.log(JSON.stringify(result.driverIds));
  Logger.log(JSON.stringify(result.handleKeys));

log is
[15-03-10 17:59:56:371 GMT] [{"name":"saved now"}]
[15-03-10 17:59:56:372 GMT] [{"createdAt":"2015-03-10T15:50:31.859Z","objectId":"vC11d5r0bK","updatedAt":"2015-03-10T15:50:31.859Z"}]
[15-03-10 17:59:56:372 GMT] ["vC11d5r0bK"]



Reply all
Reply to author
Forward
0 new messages