It depends on what exactly you need it for.  If you need it for the
total count, you can use the count() method on queries (slow) or
maintain a counter on another entity (good), or on a collection of
entity shards (better).  If you want to know how many entities of a
kind you've created ever (even if some are deleted), you can use the
key_name property to implement your own "auto_increment" policy.
Something like this (mind you this code is probably terrible :P):

class Counter(db.Model):
  count = db.IntegerProperty()

class Item(db.Model):
  some_prop = db.StringProperty()
  created_at = db.DateTimeProperty(auto_now_add=True)

  @classmethod
  def new_item(cls):
    counter = Counter.get_by_key_name("item_counter")
    count = counter.count
    counter.count += 1
    counter.put()

    ## or, something like this, which wouldn't require you to maintain
a counter (but requires a query)
    count = Item.all(keys_only=True).order(-created_at).get().name
().split("_")[1]

    return cls(key_name="num_"+str(count+1))


On Jun 22, 9:17 pm, Captain___nemo <fireball...@gmail.com> wrote:
> Hi,
> I am new in google app engine.
>
> I am a PHP-MySql developer. I used auto increment (integer type)
> always in my database. It helps for total count, works as primary key
> and so on. But as I can see auto_increment is not available for Data
> Store. I was wondering what is the alternative idea that Data Store
> provides and recommend us to use?
>
> Thanks in advance.
--~--~---------~--~----~------------~-------~--~----~
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