0

how to make own unique key based upon more than one peoperties(fields) of a model(Kind) in datastore.

here it is a situation i have 4 fields name,device,id,data. now i want to make a key based upon my 3 fields i.e name,device,id so that whenever data comes and if key is already present against that data then it will be replaced against that key else a new data data with new key is inserted.in this way i can save a db hit(i.e i will not need that hit which is required to check that a data against a key in model is present or not it will just replace data itself if already present else insert a newone record)
so how can i make this key using my 3 fields.

yasir
  • 137
  • 2
  • 14
  • 2
    If you do not provide a key, you will get a unique key. IN this way every put is unique. If you create your own key (concatenating fields), you can check if the key is unique with get_or_insert. – voscausa Nov 29 '12 at 15:12
  • Could you also clarify if what you are trying to do is create ancestor relationship? – Sologoub Nov 29 '12 at 17:59
  • here it is a situation i have 4 fields name,device,id,data – yasir Nov 29 '12 at 18:08

2 Answers2

1

At the risk of stating the obvious, the simplest answer is just to make a single key that concatenates your three fields, with some delimiter that can't appear in any of them. In Java, for example, something along the lines of:

String delimiter = ":";
String key = name + delimiter + device + delimiter + id;
Sean
  • 51
  • 2
  • it is working now i have made a unique key, now i pass this uniqe key to key_name which is unique(default) field in Datastore. key_name_ = game_code+game_version+device_type+device_id EventLogModel( key_name = key_name_, game_code = game_code, game_version = game_version, device_type = device_type , device_id = device_id , events=events ).put() – yasir Dec 12 '12 at 06:15
0

it is working now i have made a unique key, now i pass this uniqe key to key_name which is unique(default) field in Datastore.

key_name_ = game_code+game_version+device_type+device_id

EventLogModel( **key_name** = key_name_, game_code = game_code, game_version = game_version, device_type = device_type , device_id = device_id , events=events ).put()

yasir
  • 137
  • 2
  • 14