Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to check if value already exists in datastore

I have made a registration form for a blog I made using Google Datastore, and now I an trying to make it better.

First thing I seen that can be changed is the way that web application looks for the username in the data store, to see is the username already used.

I did it this way:

db.GqlQuery("SELECT * FROM UserData where username = :1", username)

Can you please refer me to better solution, which will be faster.

Thank you.

like image 870
depecheSoul Avatar asked Dec 31 '25 01:12

depecheSoul


1 Answers

If the usernames are unique, then you can make the username the key, in which you can use a db.Model.get_by_key_name()

Actually, for even better performance, use ndb, which caches your entities for get requests, so it'll be even faster.

like image 174
dragonx Avatar answered Jan 03 '26 14:01

dragonx



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!