Complex queries on Parse

I want to join multiple clauses for a single request.

Eg.

    

    

    headers[“Content-Type”] = “application/json”

    

    local params = {}

    params.headers = headers

    

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

    

    

    local clauseTabel=

    {

        NumComments = 1

    }

    

    

    local query = “?where=” … url.escape(json.encode(clauseTabel))

    

    query=query…"?limit=20"

    

    

    

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

    

    network.request( baseUrl…“Stories”…query, “GET”, networkListener,  params)

of course this is just my estimation on how to enjoin where clause & limit, it’s not working, am not finding any documentation on it, plz help.

I split the task into chunks like this:

[lua]

local obj = {} – temp table for calculation of query string

    obj.q0 = “$or”

    obj.q1 = “player”

    obj.q2 = “oppo” – store required query keywords and fields

    local t0 = “?” … url.escape(“where={”)

    local t1 = url.escape(json.encode(obj.q0)) – this encodes the word for sending within a URL, including the double-quotes

    local t2 = url.escape(":[{")

    local t3 = url.escape(json.encode(obj.q1))

    local t4 = url.escape(":")

    local t5 = url.escape(json.encode(settings.userID))

    local t6 = url.escape("},{")

    local t7 = url.escape(json.encode(obj.q2))

    local t8 = url.escape(":")

    local t9 = url.escape(json.encode(settings.userID))

    local t10 = url.escape("}]}")

    obj.string = t0 … t1 … t2 … t3 … t4 … t5 … t6 … t7 … t8 … t9 … t10 – put the entire string together

[/lua]

I split the task into chunks like this:

[lua]

local obj = {} – temp table for calculation of query string

    obj.q0 = “$or”

    obj.q1 = “player”

    obj.q2 = “oppo” – store required query keywords and fields

    local t0 = “?” … url.escape(“where={”)

    local t1 = url.escape(json.encode(obj.q0)) – this encodes the word for sending within a URL, including the double-quotes

    local t2 = url.escape(":[{")

    local t3 = url.escape(json.encode(obj.q1))

    local t4 = url.escape(":")

    local t5 = url.escape(json.encode(settings.userID))

    local t6 = url.escape("},{")

    local t7 = url.escape(json.encode(obj.q2))

    local t8 = url.escape(":")

    local t9 = url.escape(json.encode(settings.userID))

    local t10 = url.escape("}]}")

    obj.string = t0 … t1 … t2 … t3 … t4 … t5 … t6 … t7 … t8 … t9 … t10 – put the entire string together

[/lua]

try this…

function getQueryVal(name) {
    name = name.replace(/[[]/, “\[”).replace(/[]]/, “\]”);
    var regex = new RegExp("[\?&]" + name + “=([^&#]*)”),
        results = regex.exec(location.search);
    return results === null ? “” : decodeURIComponent(results[1].replace(/+/g, " "));
}

Full Source: Getting Query String Values

Balmer

Hi,

You should also take a look at mod_parse to see if it helps in anyway.

Cheers.

try this…

function getQueryVal(name) {
    name = name.replace(/[[]/, “\[”).replace(/[]]/, “\]”);
    var regex = new RegExp("[\?&]" + name + “=([^&#]*)”),
        results = regex.exec(location.search);
    return results === null ? “” : decodeURIComponent(results[1].replace(/+/g, " "));
}

Full Source: Getting Query String Values

Balmer

Hi,

You should also take a look at mod_parse to see if it helps in anyway.

Cheers.