SQL Commands

In the Backendless API you have the IN operator, can I apply NOT as NOT IN? Also, do you have a way query a list records results randomly?

Thanks,

Michael

Hi @Michael_Iverson,

Yes, ‘NOT IN’ is also supported.

To get a random object from a table, you can apply the following algorithm:

  1. Run a query to get the number of objects in the table or the number of objects matching a query using the COUNT function.
  2. Pick a random number between 0 and the result of (1)
  3. Run a query to get the object with pageSize=1 and offset=RESULT-OF-STEP2.

Hope this helps.

Regards,
Mark

What about random objects? Say like the 10 objects, all selected randomly based on a query?

Thanks,

Michael

We do not support this (yet). Out of curiosity, what is the use case that requires this functionality?

We promise to show, and explain when we complete our beta version. As for the multiple random objects, how soon will this be? We are expecting to handle rather large data sets,

Thanks,

Michael Iverson

For now that will do, I guess that will be an upgrade for later versions

Thanks,

Michael Iverson

Here’s a temporary workaround for you:

  1. Add an event handler (Cloud Code) for the API when a new object is saved.
  2. In the event handler use the atomic counter API to add a property/value to the object which is being saved. This will let you mimic an auto-increment value. For the sake of further instructions say the property name is “myId”.
  3. To retrieve random records, get the total count of the objects matching a query. Pick random numbers and run the following query to get your objects.
    myId IN (randomValue1, randomValue2, randomValue3) and some-additional-query-conditions.

This approach may require you to re-run the entire query multiple times. Because the random numbers (id’s) you generate may not be the objects which match some-additional-query-conditions.

The approach is so-so. If you come up with a better idea, please let me know.

Cheers,
Mark

I might have an idea. Does code cloud supports threading?

Thanks

Michael Iverson

Yes

Another Question: Say i have array of classes using Swift’s arrays [Class B]. Class B, has a table on the backend. I want to do bulk save, can I save it as [Class B], or do I ned to make an array of JSON object?

Thanks,

Michael

When you use Backendless SDK, you can use classes which represent objects in the database. Here’s the doc for bulk save:
https://backendless.com/docs/ios/data_multiple_objects_bulk_create.html

Also, could you please create a new support topic for every new question? It will help you, us and many others who have similar questions find the answers. Thanks in advance.

Regards,
Mark