Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

google app engine - auto increment

I am new to Google App Engine, I have this entites User class -
user_id - integer
user_name - string
password - string

I want to do auto increment for the user_id,How I can do this?

like image 427
Yosy Avatar asked Mar 27 '10 14:03

Yosy


People also ask

How does Google App Engine scale?

By default, your app uses automatic scaling, which means App Engine will manage the number of idle instances. Automatic scaling creates instances based on request rate, response latencies, and other application metrics.

What is the difference between APP engine standard and flexible?

The standard environment can scale from zero instances up to thousands very quickly. In contrast, the flexible environment must have at least one instance running for each active version and can take longer to scale up in response to traffic. Standard environment uses a custom-designed autoscaling algorithm.

What is App Engine flexible environment?

App Engine allows developers to focus on what they do best: writing code. Based on Compute Engine, the App Engine flexible environment automatically scales your app up and down while also balancing the load.

What is Google App Engine launcher?

Google App Engine (GAE) is a platform-as-a-service product that provides web app developers and enterprises with access to Google's scalable hosting and tier 1 internet service. GAE requires that applications be written in Java or Python, store data in Google Bigtable and use the Google query language.


2 Answers

You don't need to declare user_id, GAE will create a unique key id every time you insert a new row.

class User(db.Model):
user_name = db.StringProperty()
password = db.StringProperty()

and to store a new user you will do:

user = User()
user.user_name = "Username"
user.password = "Password"
user.put()

to retrieve it:

user = User.get_by_id(<id of the user>)

to retrieve all the ids:

query = datamodel.User().all()
for result in query:
    print result.key().id()

See The Model Class for further reference.

like image 113
systempuntoout Avatar answered Sep 28 '22 09:09

systempuntoout


Every entity in the AppEngine already has a unique key and id (see the documentation):

user().key().id()

You would be better off using that instead.

To do the converse, use User.get_by_id(id).

like image 24
Michael Avatar answered Sep 28 '22 10:09

Michael