Forum BigDB CreateObject() overwrites existing object?

Discussion and help relating to the PlayerIO database solution, BigDB.

CreateObject() overwrites existing object?

Postby wildbunny » June 23rd, 2011, 9:38 pm

Hi there,

The documentation doesn't say - does CreateObject() overwrite any pre-existing object with the same key?

If not, how do you do that?

Cheers, Paul.
wildbunny
 
Posts: 217
Joined: March 9th, 2011, 10:35 am

Re: CreateObject() overwrites existing object?

Postby Henrik » June 23rd, 2011, 10:16 pm

No, you'll get an error if an object already exists with that key.

Use the loadOrCreate() method instead to avoid that error, and then you can clear all the properties on the object if you want to: http://playerio.com/documentation/refer ... ysOrCreate
Henrik
.IO
 
Posts: 1880
Joined: January 4th, 2010, 1:53 pm

Re: CreateObject() overwrites existing object?

Postby wildbunny » June 24th, 2011, 12:23 pm

Hi Henrik,

Can I make a feature request that CreateObject() optionally overwrite an existing object? Its a real pain having to manually clear every single property and then call save() :)

Cheers, Paul.
wildbunny
 
Posts: 217
Joined: March 9th, 2011, 10:35 am

Re: CreateObject() overwrites existing object?

Postby Henrik » June 24th, 2011, 1:11 pm

Hm, I think a better solution would be to have a clear() method on the databaseobject to remove everything.
Henrik
.IO
 
Posts: 1880
Joined: January 4th, 2010, 1:53 pm

Re: CreateObject() overwrites existing object?

Postby wildbunny » June 24th, 2011, 2:54 pm

But then you still have to manually set all the new properties even after you've cleared...

Mysql has REPLACE as i'm sure you know, which is what i'm after here :)
wildbunny
 
Posts: 217
Joined: March 9th, 2011, 10:35 am

Re: CreateObject() overwrites existing object?

Postby jasonMcIntosh » June 24th, 2011, 7:50 pm

Since the object's schema is game-specific, there's no easy way to have the object "reset" from the PlayerIO API (unlike SQL).

It's not hard to wrap your DatabaseObject instances and provide this functionality yourself, though.
Jason McIntosh
Otherwhere Gameworks
jasonMcIntosh
 
Posts: 81
Joined: February 25th, 2011, 4:51 am

Re: CreateObject() overwrites existing object?

Postby wildbunny » June 25th, 2011, 11:53 am

jasonMcIntosh wrote:Since the object's schema is game-specific, there's no easy way to have the object "reset" from the PlayerIO API (unlike SQL).

It's not hard to wrap your DatabaseObject instances and provide this functionality yourself, though.


The schema is irrelevant in this case - all I'm after is an atomic transaction which does:

PlayerIO.BigDB.DeleteKeys(DatabaseTableNames.Rooms, RoomId)
PlayerIO.BigDB.CreateObject(DatabaseTableNames.Rooms, RoomId, ...)

I realise you might interpret REPLACE on a schema-less DB in a slightly different way (maybe adding properties and replacing others), but for me this is all I need and must be a very common use case, id have thought?

:)

Cheers, Paul.
wildbunny
 
Posts: 217
Joined: March 9th, 2011, 10:35 am

Re: CreateObject() overwrites existing object?

Postby Henrik » June 25th, 2011, 12:41 pm

Let's back up a bit...

What are you trying to do? What functionality requires you to replace entire BigDB objects regularly?
Henrik
.IO
 
Posts: 1880
Joined: January 4th, 2010, 1:53 pm

Re: CreateObject() overwrites existing object?

Postby wildbunny » June 25th, 2011, 2:51 pm

Henrik wrote:Let's back up a bit...

What are you trying to do? What functionality requires you to replace entire BigDB objects regularly?


My use case is basically saving individual players - for simplicity I just turn each player into a BigDB object and write them to PlayerObjects; i don't bother to write only changes, I just write the entire object. Its more robust that way...

Of course this means I need to delete and then create every time, hence the requirement for REPLACE like functionality :)

Cheers, Paul.
wildbunny
 
Posts: 217
Joined: March 9th, 2011, 10:35 am

Re: CreateObject() overwrites existing object?

Postby jasonMcIntosh » June 27th, 2011, 1:34 pm

wildbunny wrote:My use case is basically saving individual players - for simplicity I just turn each player into a BigDB object and write them to PlayerObjects; i don't bother to write only changes, I just write the entire object. Its more robust that way...

From what I understand, PlayerIO only saves deltas under the hood (unless you are explicitly deleting BigDB objects), so it sounds like what you are doing is not necessary.
Jason McIntosh
Otherwhere Gameworks
jasonMcIntosh
 
Posts: 81
Joined: February 25th, 2011, 4:51 am

Re: CreateObject() overwrites existing object?

Postby wildbunny » June 27th, 2011, 1:48 pm

jasonMcIntosh wrote:
wildbunny wrote:My use case is basically saving individual players - for simplicity I just turn each player into a BigDB object and write them to PlayerObjects; i don't bother to write only changes, I just write the entire object. Its more robust that way...

From what I understand, PlayerIO only saves deltas under the hood (unless you are explicitly deleting BigDB objects), so it sounds like what you are doing is not necessary.


The trouble is if you want to save only changes you need to set each changed property individually, which would take an age in my case, and be error prone, so I just save the entire object again... Which requires it be deleted, since there is no REPLACE functionality...

Cheers, Paul.
wildbunny
 
Posts: 217
Joined: March 9th, 2011, 10:35 am

Re: CreateObject() overwrites existing object?

Postby Henrik » June 27th, 2011, 2:09 pm

wildbunny wrote:My use case is basically saving individual players - for simplicity I just turn each player into a BigDB object and write them to PlayerObjects; i don't bother to write only changes, I just write the entire object. Its more robust that way...

But won't the objects be similar each time, i.e. have the same set of properties? So by loading the PlayerObject automatically, then you only need to set the properties and call Save on it? I don't understand how that could go wrong in your case? Does it matter if there are extra properties on it?

wildbunny wrote:Of course this means I need to delete and then create every time, hence the requirement for REPLACE like functionality :)

Well, if what you want can be accomplished by first calling Delete on a key, and the CreateObject on the same, there you have it.

However, that's really not an optimal use-case. If you're re-using the same key every time, the best (i.e. fastest and most bandwidth-saving way) is to load the object, change the properties that are changed, and save it back.
Henrik
.IO
 
Posts: 1880
Joined: January 4th, 2010, 1:53 pm

Re: CreateObject() overwrites existing object?

Postby wildbunny » June 27th, 2011, 2:48 pm

Hi Henrik,

For me thats just not an option unfortunately, because there are so many little properties on each player,many nested inside class hierarchies, and I'm constantly adding new ones, so it would be a maintenance nightmare to save each individual property...

If there was a way you could add a function which would do the same thing as DeleteKeys() followed by CreateObject() but in one atomic transaction, I would really appreciate it! :)

Cheers, Paul.
wildbunny
 
Posts: 217
Joined: March 9th, 2011, 10:35 am

Re: CreateObject() overwrites existing object?

Postby Oliver » July 2nd, 2011, 10:12 am

Hey,

The BigDB DatabaseObject.Save() method has a fullOverwrite argument -- Can't you use that?

Best,
Oliver
User avatar
Oliver
.IO
 
Posts: 1159
Joined: January 12th, 2010, 8:29 am

Re: CreateObject() overwrites existing object?

Postby Oliver » July 2nd, 2011, 10:35 am

Erhm... my bad... just realised that fullOverwrite was a feature we discussed but never fully implemented.

Bumping it on the priority list.

Best,
Oliver
User avatar
Oliver
.IO
 
Posts: 1159
Joined: January 12th, 2010, 8:29 am


Return to BigDB



cron