depecheSoul
depecheSoul

Reputation: 956

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.

Upvotes: 3

Views: 1334

Answers (2)

dragonx
dragonx

Reputation: 15143

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.

Upvotes: 5

njsokol
njsokol

Reputation: 119

Instead of Select * you can just do Select username ...

Upvotes: 2

Related Questions