Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Parse
Started by Michael W. Nov 24 2015 01:20 PM

71 replies to this topic
release android ios tvos windows os x lua
[TOPIC CONTROLS]
Page 1 of 3 1 2 3
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

Michael W.

[GLOBAL: userInfoPane.html]
Michael W.
  • Contributor

  • 276 posts
  • Alumni

Parse

by develephant


View and activate on the Corona Store


A Parse.com plugin for Corona SDK development based on the full Parse REST API. Parse handles everything you need to store data securely and efficiently in the cloud. Store basic data types, including locations and photos, and query across them without spinning up a single server. Parse also features analytics, A/B testing, push, email, and more.

Documentation
  • bluetardis and JonPM like this

[TOPIC: post.html]
#2

Develephant

[GLOBAL: userInfoPane.html]
Develephant
  • Corona Geek

  • 1,455 posts
  • Corona SDK

Thanks Michael!

 

It's finally here folks. Have at it!

 

Need help? Visit http://support.coronium.io

 

Cheers.



[TOPIC: post.html]
#3

nmichaud

[GLOBAL: userInfoPane.html]
nmichaud
  • Contributor

  • 492 posts
  • Corona SDK

This is amazing news. Thank you @develephant for this.



[TOPIC: post.html]
#4

nmichaud

[GLOBAL: userInfoPane.html]
nmichaud
  • Contributor

  • 492 posts
  • Corona SDK

HI,

 

I have started porting my code from previous parse module to the new plugin.

 

Doing the following code; always failed saying missing password.

    local function cb( ok, res, info )
        print( ok, res, info )
    end
 
    parse.request( parse.User.login )
        :set("username", "userNameForTest")
        :set("password", "testing123")
        :response(cb)

Here is the message I always receive :

 

********************************************************************
** Parse RESPONSE @ 11-24 22:44:26 [1]
********************************************************************
> code: 201
> error: missing user password
********************************************************************
 
PS: I can create object successfully.
 
thanks for your help


[TOPIC: post.html]
#5

Develephant

[GLOBAL: userInfoPane.html]
Develephant
  • Corona Geek

  • 1,455 posts
  • Corona SDK

Whoo hoo, first bug! Let me take a look.

 

Cheers



[TOPIC: post.html]
#6

Develephant

[GLOBAL: userInfoPane.html]
Develephant
  • Corona Geek

  • 1,455 posts
  • Corona SDK

Looks like a documentation error. Its been updated. The proper syntax is:

 

parse.request( parse.User.login )
:options( { username = "Nestor", password = "1234abcd" } )
:response(cb)

 

Thanks for bringing it to my attention.

 

Cheers.


  • nmichaud likes this

[TOPIC: post.html]
#7

nmichaud

[GLOBAL: userInfoPane.html]
nmichaud
  • Contributor

  • 492 posts
  • Corona SDK

Thank you sir, it is indeed now working properly :)



[TOPIC: post.html]
#8

nmichaud

[GLOBAL: userInfoPane.html]
nmichaud
  • Contributor

  • 492 posts
  • Corona SDK

I think I found another bug while migrating our code. In the case of a reset password :

    parse.request( parse.User.requestPasswordReset )
        :options( { email = "thisIsThePswd" } )
        :response(cb)

We always receive this error :

 

********************************************************************
** Parse RESPONSE @ 11-25 16:00:00 [1]
********************************************************************
> code: 204
> error: you must provide an email
 
thanks for your help


[TOPIC: post.html]
#9

nmichaud

[GLOBAL: userInfoPane.html]
nmichaud
  • Contributor

  • 492 posts
  • Corona SDK

I have a few more questions.

 

In modParse we were using the method modParse:linkObject to link a user to an object. WIth the new plugin, how would you suggest we do that? 

 

Also in modParse we were using the method :

modParse:linkFile( modParse.USER, objectId, "userData", fileUri, fileUrl, onLinkFile ) to link a file to an object. With the new API, I am not sure to understand how to establish the link between the objectId and the file information.

 

 

thank you

Nick



[TOPIC: post.html]
#10

tap32

[GLOBAL: userInfoPane.html]
tap32
  • Contributor

  • 243 posts
  • Corona SDK

Great plugin, got everything I needed working in a day! Fantastic work. 

 

Out of interest does the plugin support batch requests? 



[TOPIC: post.html]
#11

Develephant

[GLOBAL: userInfoPane.html]
Develephant
  • Corona Geek

  • 1,455 posts
  • Corona SDK

Hi,

 

Batch requests are in the pipeline. Should be soon.

 

@nick - I'll take a look at the issues.

 

Cheers.



[TOPIC: post.html]
#12

wgh92281

[GLOBAL: userInfoPane.html]
wgh92281
  • Observer

  • 9 posts
  • Corona SDK

here is my code,i can create,update,and i want get the string from parse that i created,i use query [res.color] to get string,but it return nil?

any idea?

 

parse.request( parse.Object.create, "test" )
:data( { color = "Green",  yes = "red", })
:response()



parse.request( parse.Object.query, "test" )
:response(function( ok, res )
    if not ok then
      print('err', res)
    else
    print('yes', res)
      print(res.color, res.yes)
    end
  end)

parse.request( parse.Object.update, "test","4PP8K8jecJ")
:data( {color = "black"})
:response()



[TOPIC: post.html]
#13

Develephant

[GLOBAL: userInfoPane.html]
Develephant
  • Corona Geek

  • 1,455 posts
  • Corona SDK

Updated release 0.2.4

 

Added Macros

Added Batch Operations

 

Refactored Misc Stuff

 

Updated Docs

 

Enjoy.



[TOPIC: post.html]
#14

Develephant

[GLOBAL: userInfoPane.html]
Develephant
  • Corona Geek

  • 1,455 posts
  • Corona SDK

here is my code,i can create,update,and i want get the string from parse that i created,i use query [res.color] to get string,but it return nil?

any idea?

 

parse.request( parse.Object.create, "test" )
:data( { color = "Green",  yes = "red", })
:response()



parse.request( parse.Object.query, "test" )
:response(function( ok, res )
    if not ok then
      print('err', res)
    else
    print('yes', res)
      print(res.color, res.yes)
    end
  end)

parse.request( parse.Object.update, "test","4PP8K8jecJ")
:data( {color = "black"})
:response()

 

Hi,

 

To retrieve the Object record you can use a "get" or a "query" (See here). In this case you are using a query, but it's not properly built up. More on that in a sec.

 

Also, be mindful that "test" is the Class name on Parse, not your object identifier. You could consider "test" the category that your data objects are stored in. In the response of certain plugin calls to Parse you will find identifiers. Turning on debugging -- after your Parse plugin "init" -- can be helpful in these cases.

 

parse.config:debugEnabled( true )

 

How you manage and store these ids is up to you. Parses methodology is the User system, being the only entry point accessible by a users credentials. You can then create relations as needed to other Object ids using the User id as your "master" identifier.

 

Now, back to the code. On the "test" Class instance you have added 2 properties ( color and yes ), these are searchable with a parse.Object.query:

 

parse.request( parse.Object.query, "test" ) --Class (category)

:where( { color = "red" } ) --The search key query

:response(function( ok, res )

  if not ok then

    print( 'err', res )

  else

    parse.trace( res ) --parse.trace() outputs table data

    print( res.objectId ) --the actual id

  end

end)

 

This would bring back all Objects from the "test" Class that contain a key called "color" that is equal to "red". The plugin offers Macros (shortcuts) as well, so you could also use:

 

parse.macro.findWhereEqual( "test", "color", "red" ) --Class, key, value

:response(cb)

 

Generally you'll be working with objectIds, so to fetch the Object as shown in your example, you would us a parse.Object.get:

 

parse.request( parse.Object.get, "test", "4PP8K8jecJ" ) --Class, objectId

:response(function( ok, res )

  if not ok then

    print( 'err', res )

  else

    print( res.color ) -- red

  end

end)

 

Hope that helps. Be sure to read through the documentation at parse.develephant.com

 

Cheers.



[TOPIC: post.html]
#15

wgh92281

[GLOBAL: userInfoPane.html]
wgh92281
  • Observer

  • 9 posts
  • Corona SDK

i try again,it still don't work,i can create,get,update,but i use query to get objectId value but it return nil(code line 31)

please see code line 31​

please see code line 31​
it return value=nil and I want to get objectId value(s6Au2jeHmF)

 

this is my parse screen picture

Attached File  p1.PNG   9.88KB   0 downloads

 

this is my console output picture

Attached File  p2.PNG   18.01KB   0 downloads

 

my code

parse.config:debugEnabled( true )
--get
  local req = parse.request( parse.Object.get, "countertest","s6Au2jeHmF" )
  req:response(function( ok, res )
    if not ok then
      print('err', res)
    else
    print('get', res)
      print(res.counter, res.yes)
    end
  end)
  
--create 
parse.request( parse.Object.create, "countertest" )
:data( { counter = "1",  yes = "kkk", })
:response()

--macro
parse.macro.findWhereEqual( "countertest", "counter", "1" ) --Class, key, value

:response(cb)

--query
parse.request( parse.Object.query, "countertest" )
:where( { counter = "1" } ) --The search key query
:response(function( ok, res )
    if not ok then
      print('err', res)
    else
        print('yes', res)
        print( res.objectId ) --the actual id(I want this actual id,but it return nil)
    end
  end)



[TOPIC: post.html]
#16

nmichaud

[GLOBAL: userInfoPane.html]
nmichaud
  • Contributor

  • 492 posts
  • Corona SDK

@wgh92281 can you be more specific of what is the problem and what are you trying to achieve here ? Its very hard to understand what you want to do exactly and your code is really not easy to read. Please use proper code formating and focus on the code that does not work.



[TOPIC: post.html]
#17

wgh92281

[GLOBAL: userInfoPane.html]
wgh92281
  • Observer

  • 9 posts
  • Corona SDK

@nmichaud

 

i edit my post,thanks anyway



[TOPIC: post.html]
#18

nmichaud

[GLOBAL: userInfoPane.html]
nmichaud
  • Contributor

  • 492 posts
  • Corona SDK

You should look at res.result (as you are doing a query in this case). Careful here, it is a table...

 

Also, I would suggest you use a debugger in the future and put a breakpoint in the callback method. You will then be able to look at the values and then find out very quickly of the returned data. Its the best way to learn how to deal with methods you are unsure of the data you receive.



[TOPIC: post.html]
#19

wgh92281

[GLOBAL: userInfoPane.html]
wgh92281
  • Observer

  • 9 posts
  • Corona SDK

i very appreciate your help,but i use res.result  instead of res.objectId.(code line 27), it still return value=nil

 

and I found that I use res.objectId( code line 7)  it return value= s6Au2jeHmF

 

I don't understand why it work on get method, but it don't work on query method

 

I really want to know how to get my objectId that I create.

  local req = parse.request( parse.Object.get, "countertest","s6Au2jeHmF" )
  req:response(function( ok, res )
    if not ok then
      print('err', res)
    else
	print('get', res)
      print(res.counter, res.yes,res.objectId)
    end
  end)
  --]]
 ---[[ 
parse.request( parse.Object.create, "countertest" )
:data( { counter = "1",  yes = "kkk", })
:response()
--]]
parse.macro.findWhereEqual( "countertest", "counter", "1" ) --Class, key, value

:response(cb)

parse.request( parse.Object.query, "countertest" )
:where( { counter = "1" } ) --The search key query
:response(function( ok, res )
    if not ok then
      print('err', res)
    else
	-- parse.trace( res ) --parse.trace() outputs table data
	print('yes', res)
        print( res.result ) --the actual id
    end
  end)


[TOPIC: post.html]
#20

Develephant

[GLOBAL: userInfoPane.html]
Develephant
  • Corona Geek

  • 1,455 posts
  • Corona SDK

Hi,

 

I'm pretty sure a "query" will always return a table array of the results, even if it's only one record. So:

 

local function callback( ok, res )

  for _, result in ipairs( res ) do

    print( result.objectId )

  end

end

 

You should be able to see the structure in the debug output.

 

@nmichaud thanks for jumping in.

 

Cheers.



[TOPIC: post.html]
#21

nmichaud

[GLOBAL: userInfoPane.html]
nmichaud
  • Contributor

  • 492 posts
  • Corona SDK

I confirm that a query will always return a table array of the results as we are doing so many of them.



[TOPIC: post.html]
#22

wgh92281

[GLOBAL: userInfoPane.html]
wgh92281
  • Observer

  • 9 posts
  • Corona SDK

hi,

thanks again.i use your code and it is my whole code now

local function cb( ok, res ,info)

  for key, value in pairs( res) do

    print( key,value )
 
  end

end

parse.request( parse.Object.query, "countertest" )
:where( { yes = "kkk" } ) --The search key query
:response(cb)

console return=results table: 072F8038

********************************************************************
** Parse RESPONSE @ 12-12 20:50:14 [1]
********************************************************************
> results:
>    1:
>       createdAt: 2015-12-11T07:58:19.547Z
>       objectId: s6Au2jeHmF
>       updatedAt: 2015-12-11T07:58:19.547Z
>       yes: kkk
********************************************************************
results table: 072F8038

and I change code 3,info instead of res

local function cb( ok, res ,info)

  for key, value in pairs( info) do

    print( key,value )
 
  end

end

parse.request( parse.Object.query, "countertest" )
:where( { yes = "kkk" } ) --The search key query
:response(cb)

it can show the info table key and value,i really don't understand why res can not get value

********************************************************************
** Parse RESPONSE @ 12-12 20:51:17 [1]
********************************************************************
> results:
>    1:
>       createdAt: 2015-12-11T07:58:19.547Z
>       objectId: s6Au2jeHmF
>       updatedAt: 2015-12-11T07:58:19.547Z
>       yes: kkk
********************************************************************
isError false
responseHeaders table: 072910B8
responseType    text
status  200
url     https://api.parse.com/1/classes/countertest?where=%7b%22yes%22%3a%22kkk%22%7d
bytesEstimated  130
bytesTransferred        130



[TOPIC: post.html]
#23

Develephant

[GLOBAL: userInfoPane.html]
Develephant
  • Corona Geek

  • 1,455 posts
  • Corona SDK

Hi,

 

Well, you actually didn't use my code, my example was like so:

 

local function callback( ok, res )

  for _, result in ipairs( res ) do

    print( result.objectId )

  end

end

 

I am specifically using ipairs, not pairs. Notice the "_" meaning that is a "throwaway" value (an index), the result is a result object (keyed table) that you can use like any other, including result.objectId.

 

There is no "key" (only index), in a collection of result objects. So you must cycle through them. If you use pairs, it is not the same thing.

 

Any content with multiple results is going to be contained in a collection of some type, and this isn't necessarily specific to Lua. But in this case it's a Lua table array. Do you feel comfortable in knowing the difference between a table array and a keyed table? Because it's a fundamental concept, for any Lua coding you are going to be doing. What are you going to do if you have multiple results? You must to have some way to contain them.

 

If you want one record, use .get methods with id, if you are performing a .query, you are commonly expecting multiple results, and possibly only 1 or no results. It's up to you to adjust accordingly. This is a generally accepted practice and is directly related to the Parse API. 

 

If you are absolutely positive that your query will result in one and only one record, then you can access it directly like so:

 

function (ok, res)

  if ok then

    res[1].objectId

  end

end

 

I am not saying that I recommend that though. If you are looking for only one specific record, but don't have an id, then try a Macro like findWhereEqual:

 

parse.macro.findWhereEqual( 'countertest', 'yes', 'kkk' )

:response(cb)

 

That should only return one result.

 

Cheers.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 



[TOPIC: post.html]
#24

wgh92281

[GLOBAL: userInfoPane.html]
wgh92281
  • Observer

  • 9 posts
  • Corona SDK

hi

i did try your code before,but it show nothing ,so i didn't tell you,sorry, it my fault.

here is my code

parse.request( parse.Object.create, "countertest" )
:data({ yes = "kkk" } )
:response(function( ok, res )
    if not ok then
      print('err', res)
    else
	print('create ok', res)

    end
  end)


parse.macro.findWhereEqual( 'countertest', 'yes', 'kkk' )

:response(cb)


local function cb( ok, res )
print("yes i am in begin of cb function")
 for _, result in ipairs( res ) do

    print( result.objectId )

  end
print("yes i am in the end of cb function")
end

parse.request( parse.Object.query, "countertest" )
:where( { yes = "kkk" } ) --The search key query
:response(cb)

it return

********************************************************************
** Parse RESPONSE @ 12-14 08:59:09 [1]
********************************************************************
> results:
>    1:
>       createdAt: 2015-12-14T08:52:00.425Z
>       objectId: 41jmOfO6IG
>       updatedAt: 2015-12-14T08:52:00.425Z
>       yes: kkk
>    2:
>       createdAt: 2015-12-14T08:52:28.765Z
>       objectId: RGwpfMevi8
>       updatedAt: 2015-12-14T08:52:28.765Z
>       yes: kkk
********************************************************************
yes i am in begin of cb function
yes i am in the end of cb function
********************************************************************
** Parse RESPONSE @ 12-14 08:59:09 [2]
********************************************************************
> createdAt: 2015-12-14T08:59:07.681Z
> objectId: c0L0uNHfcq
********************************************************************
create ok       table: 0767E1E0
********************************************************************
** Parse RESPONSE @ 12-14 08:59:09 [3]
********************************************************************
> code: 102
> error: Invalid key $eq for find
********************************************************************

here is my parse screen picture

Attached File  666.PNG   16.97KB   0 downloads

 

 

code line 13

 

it return as below,i did try before and I post it before,but someone say he can not understand it, so I edit and delete it. 

> code: 102
> error: Invalid key $eq for find

and I try your code line 22,it return nothing

you can see line 19 and 25,this is nothing between them. 

 

yes i am in begin of cb function

yes i am in the end of cb function

 

 

plus,if I change code to

function (ok, res)

  if ok then

    res[1].objectId

  end

end

simulator will show error window,it can not even run code

 

Attached File  777.PNG   4.11KB   0 downloads

 

 

 

 

 

 

 

 

 



[TOPIC: post.html]
#25

nmichaud

[GLOBAL: userInfoPane.html]
nmichaud
  • Contributor

  • 492 posts
  • Corona SDK

@wgh92281, There is many bugs in your code, that its hard to understand what you are really trying to accomplish here. Sometime you do not declare the callback, other time you do not define a name for your function...

 

How much experience do you have in coding ? and with Lua ?

 

I believe the best way we can help you is if you paste the whole source code from beginning to end that your are executing. No more snippets please as it is too hard for us to help you. Put the whole things here so we can understand the whole execution. 




[topic_controls]
Page 1 of 3 1 2 3
 
[/topic_controls]

Also tagged with one or more of these keywords: release, android, ios, tvos, windows, os x, lua