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?
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.
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.
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.
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.
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.
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)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With