Hi n8gray,

Excellent question!

Given the amount of information you're likely to store against Players2Games
(GamePlayers, perhaps?), and the number of games any one player may have,
and the likely access patterns, I would suggest sticking with a separate
model for it.

The main lesson for using the datastore instead of a relational database is
simply to denormalize and precalculate. In this case, that likely means
storing running totals (number of turns, score, etc) against the
Players2Games entity, instead of calculating them when needed as you might
in a relational database.

Tony's point about entity groups is an excellent one. Based on the sort of
updates you're likely to want to do, and the access patterns in an app like
this, I would suggest making the Players2Games entities child entities of
the related Games entity, and making the Turns entities likewise child
entities of their Games entity. This way, each game has its own entity
group, so you can make atomic (transactional) updates across the whole game
with ease.

-Nick Johnson

On Tue, Jun 9, 2009 at 6:47 PM, n8gray <n8g...@gmail.com> wrote:

>
> Hi everybody,
>
> I'm about to start working on an AppEngine backend for an iPhone game
> I'm developing.  It's a simple board game, with 2-4 players who each
> take turns making plays.  Originally I had planned to set up a LAMP
> server for my project, but AE has changed my plans (for the better!).
> I've never written database code before but I've read up on the basics
> of database design, and I came to the conclusion that I would need a
> DB schema with tables something like this:
>
> Players:  username, email, userid, ...
> Games: gameid, time_started, current_player, is_finished, ...
> Players2Games:  userid, gameid, score, ...
> Turns: userid, gameid, timestamp, turn_number, play, turn_score, ...
>
> It seems clear, however, that Datastore is not a traditional database
> and perhaps my schema needs to be revisited.  Is it still necessary or
> advisable to use a table like Players2Games in order to represent many-
> to-many relationships?  What should my roots and parent/child
> relationships be?
>
> Typical queries will be (unsurprising) things like:
> get all games for player x
> get all players for game x
> get the scores of all players in game x
> get any turns in game x that have occurred since time t
>
> Any advice, or pointers to articles/posts/documentation are
> appreciated!
>
> Thanks,
> -n8
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to