[google-appengine] Re: why there is no way to build a key id?

2009-07-07 Thread Jeff Enderwick

Just star'd it -thx.

2009/6/24 Jeff S (Google) j...@google.com:
 Hi Jeff,

 This is an idea that we're aware of as well. If you could reserve the next
 ID in advance, then you could actually do this in one put since multiple
 entities could be sent in one batch :-) The workaround available now is to
 use the key_name, but the difficulty becomes ensuring that the key_name is
 unique. Here is a feature request which I'm aware of which is along these
 lines (though the approach differs slightly):

 http://code.google.com/p/googleappengine/issues/detail?id=1003

 Thank you,

 Jeff

 2009/6/24 Jeff Enderwick jeff.enderw...@gmail.com

 Hey Jeff - sorry for the confusion. The idea was that one would be
 able to get the unique id from an GOOG and then do a db.put with that
 id as an arg. For example, let's say I want to create two entities,
 with each referring to each other. I need to do three db.put
 operations:

 a = Foo()
 db.put(a)
 b = Foo()
 b.ref = a.key()
 db.put(b)
 a.ref = b.key()
 db.put(a)

 One would hope to be able to do this with two db.puts.

 Thanks,
 Jeff


 2009/6/16 Jeff S (Google) j...@google.com:
 
  The datastore does not allow key_names which begin with a digit in
  order to avoid confusion with an ID, which is numerical. If you want
  to use numeric key names, you could add a one letter prefix :-)
 
  Happy coding,
 
  Jeff
 
  On Jun 16, 1:17 am, cryb cbuti...@gmail.com wrote:
  Hi Jeff.
  Thanks for your reply.. I really hope that in the near future
  appengine will support setting key ids for entities.
  You mentioned that I can use hooks in order to achieve my goal..
  However I was more interested in a solution based on appengine java
  sdk, and not on python hooks. Does appengine java sdk provide hooks or
  some other similar mechanism?
  It seems that for the moment I'll stick to generating key names.
  One more question: I've tried to generate some entities with key names
  on my local devappserver and I got a strange exception stating that I
  can't create key names that start with a digit (?!?)... this holds on
  google appengine production servers too or it's just a bug of
  devappserver?
 
  Thanks
 
  On Jun 16, 2:45 am, Jeff S (Google) j...@google.com wrote:
 
   Hi cryb,
 
   As you noted, we do not currently allow the ID for a key to be set,
   as we
   ensure that the ID is unique for each existing entity. I recommend
   using a
   key name instead of an ID, as Antoniov suggeted, if possible.
 
   It is technically possible to modify the key of an entity as it is
   being
   converted to a protocol buffer message before it is sent to the
   datastore.
   You could do this using hooks in the API proxy as described in this
   article:http://code.google.com/appengine/articles/hooks.htmlAlsoit is
   possible to
   construct the key for the desired object if you know the ID in
   advance.
 
   class X(db.Model):
 pass
 
   # If you've already created the entity so you have the ID.
   x_id = X().put().id()
 
   # Instead of getting by ID, you can create the key manually.
   k = db.Key.from_path('X', x_id)
 
   Now you have the desired key without having fetched the object, but
   the part
   which the model class does not allow is setting the key yourself. So
   you
   could modify the protocol buffer message before it is written to the
   datastore, but I don't recommend it.
 
   The decision to allow setting key_names but not IDs is something we
   may
   revisit.
 
   Happy coding,
 
   Jeff
 
   2009/6/12 cryb cbuti...@gmail.com
 
Hi.. that is to build key names... What I asked was why I can't
build
a key ID..
 
On Jun 12, 5:35 am, Antoniov nio@gmail.com wrote:
 Use the code:
 s = Story(key_name=xzy123)
 Then you create an entity with the key name xzy123.
 
 Check this:
  
http://code.google.com/intl/en-US/appengine/docs/python/datastore/key...
 
 On 6月12日, 上午1时28分, cryb cbuti...@gmail.com wrote:
 
  Does anyone know why it is possible to build a key name but NOT
  a key
  id? I know key IDs are used as autoincrements, but why can't I
  just
  override this mechanism and build my own key id?
  Suppose I want to overwrite an existent entry in my table that
  has a
  key id I know, and also I want to keep that key id after
  update...
  because I can't just build a key id, I am forced to fetch that
  entity,
  modify it and write it back, instead of just write the updated
  entity
  with the key id I already know - so an additional read to the
  datastore.
  Is there an obscure reason for that? (both key names and key
  ids are
  prefixed with appid/kind as far as I know so there is no chance
  of
  collision with other apps/kinds)
  
 




 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Google App Engine group.
To post to this group, send email to 

[google-appengine] Re: why there is no way to build a key id?

2009-06-24 Thread Jeff Enderwick

Hey Jeff - sorry for the confusion. The idea was that one would be
able to get the unique id from an GOOG and then do a db.put with that
id as an arg. For example, let's say I want to create two entities,
with each referring to each other. I need to do three db.put
operations:

a = Foo()
db.put(a)
b = Foo()
b.ref = a.key()
db.put(b)
a.ref = b.key()
db.put(a)

One would hope to be able to do this with two db.puts.

Thanks,
Jeff


2009/6/16 Jeff S (Google) j...@google.com:

 The datastore does not allow key_names which begin with a digit in
 order to avoid confusion with an ID, which is numerical. If you want
 to use numeric key names, you could add a one letter prefix :-)

 Happy coding,

 Jeff

 On Jun 16, 1:17 am, cryb cbuti...@gmail.com wrote:
 Hi Jeff.
 Thanks for your reply.. I really hope that in the near future
 appengine will support setting key ids for entities.
 You mentioned that I can use hooks in order to achieve my goal..
 However I was more interested in a solution based on appengine java
 sdk, and not on python hooks. Does appengine java sdk provide hooks or
 some other similar mechanism?
 It seems that for the moment I'll stick to generating key names.
 One more question: I've tried to generate some entities with key names
 on my local devappserver and I got a strange exception stating that I
 can't create key names that start with a digit (?!?)... this holds on
 google appengine production servers too or it's just a bug of
 devappserver?

 Thanks

 On Jun 16, 2:45 am, Jeff S (Google) j...@google.com wrote:

  Hi cryb,

  As you noted, we do not currently allow the ID for a key to be set, as we
  ensure that the ID is unique for each existing entity. I recommend using a
  key name instead of an ID, as Antoniov suggeted, if possible.

  It is technically possible to modify the key of an entity as it is being
  converted to a protocol buffer message before it is sent to the datastore.
  You could do this using hooks in the API proxy as described in this 
  article:http://code.google.com/appengine/articles/hooks.htmlAlsoit is 
  possible to
  construct the key for the desired object if you know the ID in advance.

  class X(db.Model):
pass

  # If you've already created the entity so you have the ID.
  x_id = X().put().id()

  # Instead of getting by ID, you can create the key manually.
  k = db.Key.from_path('X', x_id)

  Now you have the desired key without having fetched the object, but the 
  part
  which the model class does not allow is setting the key yourself. So you
  could modify the protocol buffer message before it is written to the
  datastore, but I don't recommend it.

  The decision to allow setting key_names but not IDs is something we may
  revisit.

  Happy coding,

  Jeff

  2009/6/12 cryb cbuti...@gmail.com

   Hi.. that is to build key names... What I asked was why I can't build
   a key ID..

   On Jun 12, 5:35 am, Antoniov nio@gmail.com wrote:
Use the code:
s = Story(key_name=xzy123)
Then you create an entity with the key name xzy123.

Check this:
  http://code.google.com/intl/en-US/appengine/docs/python/datastore/key...

On 6月12日, 上午1时28分, cryb cbuti...@gmail.com wrote:

 Does anyone know why it is possible to build a key name but NOT a key
 id? I know key IDs are used as autoincrements, but why can't I just
 override this mechanism and build my own key id?
 Suppose I want to overwrite an existent entry in my table that has a
 key id I know, and also I want to keep that key id after update...
 because I can't just build a key id, I am forced to fetch that 
 entity,
 modify it and write it back, instead of just write the updated entity
 with the key id I already know - so an additional read to the
 datastore.
 Is there an obscure reason for that? (both key names and key ids are
 prefixed with appid/kind as far as I know so there is no chance of
 collision with other apps/kinds)
 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Google App Engine group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~--~~~~--~~--~--~---



[google-appengine] Re: why there is no way to build a key id?

2009-06-24 Thread Jeff S (Google)
Hi Jeff,

This is an idea that we're aware of as well. If you could reserve the next
ID in advance, then you could actually do this in one put since multiple
entities could be sent in one batch :-) The workaround available now is to
use the key_name, but the difficulty becomes ensuring that the key_name is
unique. Here is a feature request which I'm aware of which is along these
lines (though the approach differs slightly):

http://code.google.com/p/googleappengine/issues/detail?id=1003

Thank you,

Jeff

2009/6/24 Jeff Enderwick jeff.enderw...@gmail.com


 Hey Jeff - sorry for the confusion. The idea was that one would be
 able to get the unique id from an GOOG and then do a db.put with that
 id as an arg. For example, let's say I want to create two entities,
 with each referring to each other. I need to do three db.put
 operations:

 a = Foo()
 db.put(a)
 b = Foo()
 b.ref = a.key()
 db.put(b)
 a.ref = b.key()
 db.put(a)

 One would hope to be able to do this with two db.puts.

 Thanks,
 Jeff


 2009/6/16 Jeff S (Google) j...@google.com:
 
  The datastore does not allow key_names which begin with a digit in
  order to avoid confusion with an ID, which is numerical. If you want
  to use numeric key names, you could add a one letter prefix :-)
 
  Happy coding,
 
  Jeff
 
  On Jun 16, 1:17 am, cryb cbuti...@gmail.com wrote:
  Hi Jeff.
  Thanks for your reply.. I really hope that in the near future
  appengine will support setting key ids for entities.
  You mentioned that I can use hooks in order to achieve my goal..
  However I was more interested in a solution based on appengine java
  sdk, and not on python hooks. Does appengine java sdk provide hooks or
  some other similar mechanism?
  It seems that for the moment I'll stick to generating key names.
  One more question: I've tried to generate some entities with key names
  on my local devappserver and I got a strange exception stating that I
  can't create key names that start with a digit (?!?)... this holds on
  google appengine production servers too or it's just a bug of
  devappserver?
 
  Thanks
 
  On Jun 16, 2:45 am, Jeff S (Google) j...@google.com wrote:
 
   Hi cryb,
 
   As you noted, we do not currently allow the ID for a key to be set, as
 we
   ensure that the ID is unique for each existing entity. I recommend
 using a
   key name instead of an ID, as Antoniov suggeted, if possible.
 
   It is technically possible to modify the key of an entity as it is
 being
   converted to a protocol buffer message before it is sent to the
 datastore.
   You could do this using hooks in the API proxy as described in this
 article:http://code.google.com/appengine/articles/hooks.htmlAlsoit is
 possible to
   construct the key for the desired object if you know the ID in
 advance.
 
   class X(db.Model):
 pass
 
   # If you've already created the entity so you have the ID.
   x_id = X().put().id()
 
   # Instead of getting by ID, you can create the key manually.
   k = db.Key.from_path('X', x_id)
 
   Now you have the desired key without having fetched the object, but
 the part
   which the model class does not allow is setting the key yourself. So
 you
   could modify the protocol buffer message before it is written to the
   datastore, but I don't recommend it.
 
   The decision to allow setting key_names but not IDs is something we
 may
   revisit.
 
   Happy coding,
 
   Jeff
 
   2009/6/12 cryb cbuti...@gmail.com
 
Hi.. that is to build key names... What I asked was why I can't
 build
a key ID..
 
On Jun 12, 5:35 am, Antoniov nio@gmail.com wrote:
 Use the code:
 s = Story(key_name=xzy123)
 Then you create an entity with the key name xzy123.
 
 Check this:
   
 http://code.google.com/intl/en-US/appengine/docs/python/datastore/key...
 
 On 6月12日, 上午1时28分, cryb cbuti...@gmail.com wrote:
 
  Does anyone know why it is possible to build a key name but NOT
 a key
  id? I know key IDs are used as autoincrements, but why can't I
 just
  override this mechanism and build my own key id?
  Suppose I want to overwrite an existent entry in my table that
 has a
  key id I know, and also I want to keep that key id after
 update...
  because I can't just build a key id, I am forced to fetch that
 entity,
  modify it and write it back, instead of just write the updated
 entity
  with the key id I already know - so an additional read to the
  datastore.
  Is there an obscure reason for that? (both key names and key ids
 are
  prefixed with appid/kind as far as I know so there is no chance
 of
  collision with other apps/kinds)
  
 

 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Google App Engine group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com
For more options, visit this 

[google-appengine] Re: why there is no way to build a key id?

2009-06-24 Thread Andy Freeman

see also

http://groups.google.com/group/google-appengine/browse_thread/thread/3f8cfeaf7dc2eb72/d5d599180fe47e02?lnk=gstq=ryan+allocate#d5d599180fe47e02


On Jun 24, 11:33 am, Jeff S (Google) j...@google.com wrote:
 Hi Jeff,

 This is an idea that we're aware of as well. If you could reserve the next
 ID in advance, then you could actually do this in one put since multiple
 entities could be sent in one batch :-) The workaround available now is to
 use the key_name, but the difficulty becomes ensuring that the key_name is
 unique. Here is a feature request which I'm aware of which is along these
 lines (though the approach differs slightly):

 http://code.google.com/p/googleappengine/issues/detail?id=1003

 Thank you,

 Jeff

 2009/6/24 Jeff Enderwick jeff.enderw...@gmail.com





  Hey Jeff - sorry for the confusion. The idea was that one would be
  able to get the unique id from an GOOG and then do a db.put with that
  id as an arg. For example, let's say I want to create two entities,
  with each referring to each other. I need to do three db.put
  operations:

  a = Foo()
  db.put(a)
  b = Foo()
  b.ref = a.key()
  db.put(b)
  a.ref = b.key()
  db.put(a)

  One would hope to be able to do this with two db.puts.

  Thanks,
  Jeff

  2009/6/16 Jeff S (Google) j...@google.com:

   The datastore does not allow key_names which begin with a digit in
   order to avoid confusion with an ID, which is numerical. If you want
   to use numeric key names, you could add a one letter prefix :-)

   Happy coding,

   Jeff

   On Jun 16, 1:17 am, cryb cbuti...@gmail.com wrote:
   Hi Jeff.
   Thanks for your reply.. I really hope that in the near future
   appengine will support setting key ids for entities.
   You mentioned that I can use hooks in order to achieve my goal..
   However I was more interested in a solution based on appengine java
   sdk, and not on python hooks. Does appengine java sdk provide hooks or
   some other similar mechanism?
   It seems that for the moment I'll stick to generating key names.
   One more question: I've tried to generate some entities with key names
   on my local devappserver and I got a strange exception stating that I
   can't create key names that start with a digit (?!?)... this holds on
   google appengine production servers too or it's just a bug of
   devappserver?

   Thanks

   On Jun 16, 2:45 am, Jeff S (Google) j...@google.com wrote:

Hi cryb,

As you noted, we do not currently allow the ID for a key to be set, as
  we
ensure that the ID is unique for each existing entity. I recommend
  using a
key name instead of an ID, as Antoniov suggeted, if possible.

It is technically possible to modify the key of an entity as it is
  being
converted to a protocol buffer message before it is sent to the
  datastore.
You could do this using hooks in the API proxy as described in this
  article:http://code.google.com/appengine/articles/hooks.htmlAlsoitis
  possible to
construct the key for the desired object if you know the ID in
  advance.

class X(db.Model):
  pass

# If you've already created the entity so you have the ID.
x_id = X().put().id()

# Instead of getting by ID, you can create the key manually.
k = db.Key.from_path('X', x_id)

Now you have the desired key without having fetched the object, but
  the part
which the model class does not allow is setting the key yourself. So
  you
could modify the protocol buffer message before it is written to the
datastore, but I don't recommend it.

The decision to allow setting key_names but not IDs is something we
  may
revisit.

Happy coding,

Jeff

2009/6/12 cryb cbuti...@gmail.com

 Hi.. that is to build key names... What I asked was why I can't
  build
 a key ID..

 On Jun 12, 5:35 am, Antoniov nio@gmail.com wrote:
  Use the code:
  s = Story(key_name=xzy123)
  Then you create an entity with the key name xzy123.

  Check this:

 http://code.google.com/intl/en-US/appengine/docs/python/datastore/key...

  On 6月12日, 上午1时28分, cryb cbuti...@gmail.com wrote:

   Does anyone know why it is possible to build a key name but NOT
  a key
   id? I know key IDs are used as autoincrements, but why can't I
  just
   override this mechanism and build my own key id?
   Suppose I want to overwrite an existent entry in my table that
  has a
   key id I know, and also I want to keep that key id after
  update...
   because I can't just build a key id, I am forced to fetch that
  entity,
   modify it and write it back, instead of just write the updated
  entity
   with the key id I already know - so an additional read to the
   datastore.
   Is there an obscure reason for that? (both key names and key ids
  are
   prefixed with appid/kind as far as I know so there is no chance
  of
   collision with other apps/kinds)- Hide quoted text -

 - Show quoted text -

[google-appengine] Re: why there is no way to build a key id?

2009-06-16 Thread cryb

Hi Jeff.
Thanks for your reply.. I really hope that in the near future
appengine will support setting key ids for entities.
You mentioned that I can use hooks in order to achieve my goal..
However I was more interested in a solution based on appengine java
sdk, and not on python hooks. Does appengine java sdk provide hooks or
some other similar mechanism?
It seems that for the moment I'll stick to generating key names.
One more question: I've tried to generate some entities with key names
on my local devappserver and I got a strange exception stating that I
can't create key names that start with a digit (?!?)... this holds on
google appengine production servers too or it's just a bug of
devappserver?

Thanks

On Jun 16, 2:45 am, Jeff S (Google) j...@google.com wrote:
 Hi cryb,

 As you noted, we do not currently allow the ID for a key to be set, as we
 ensure that the ID is unique for each existing entity. I recommend using a
 key name instead of an ID, as Antoniov suggeted, if possible.

 It is technically possible to modify the key of an entity as it is being
 converted to a protocol buffer message before it is sent to the datastore.
 You could do this using hooks in the API proxy as described in this 
 article:http://code.google.com/appengine/articles/hooks.htmlAlso it is 
 possible to
 construct the key for the desired object if you know the ID in advance.

 class X(db.Model):
   pass

 # If you've already created the entity so you have the ID.
 x_id = X().put().id()

 # Instead of getting by ID, you can create the key manually.
 k = db.Key.from_path('X', x_id)

 Now you have the desired key without having fetched the object, but the part
 which the model class does not allow is setting the key yourself. So you
 could modify the protocol buffer message before it is written to the
 datastore, but I don't recommend it.

 The decision to allow setting key_names but not IDs is something we may
 revisit.

 Happy coding,

 Jeff

 2009/6/12 cryb cbuti...@gmail.com



  Hi.. that is to build key names... What I asked was why I can't build
  a key ID..

  On Jun 12, 5:35 am, Antoniov nio@gmail.com wrote:
   Use the code:
   s = Story(key_name=xzy123)
   Then you create an entity with the key name xzy123.

   Check this:
 http://code.google.com/intl/en-US/appengine/docs/python/datastore/key...

   On 6月12日, 上午1时28分, cryb cbuti...@gmail.com wrote:

Does anyone know why it is possible to build a key name but NOT a key
id? I know key IDs are used as autoincrements, but why can't I just
override this mechanism and build my own key id?
Suppose I want to overwrite an existent entry in my table that has a
key id I know, and also I want to keep that key id after update...
because I can't just build a key id, I am forced to fetch that entity,
modify it and write it back, instead of just write the updated entity
with the key id I already know - so an additional read to the
datastore.
Is there an obscure reason for that? (both key names and key ids are
prefixed with appid/kind as far as I know so there is no chance of
collision with other apps/kinds)
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Google App Engine group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~--~~~~--~~--~--~---



[google-appengine] Re: why there is no way to build a key id?

2009-06-16 Thread Andy Freeman

 The decision to allow setting key_names but not IDs is something we may
 revisit.

I hope that you're also considering some way to request and allocate
an unused id for a given path prefix.  (That way we can get unique key
ids to specify.)



On Jun 15, 4:45 pm, Jeff S (Google) j...@google.com wrote:
 Hi cryb,

 As you noted, we do not currently allow the ID for a key to be set, as we
 ensure that the ID is unique for each existing entity. I recommend using a
 key name instead of an ID, as Antoniov suggeted, if possible.

 It is technically possible to modify the key of an entity as it is being
 converted to a protocol buffer message before it is sent to the datastore.
 You could do this using hooks in the API proxy as described in this 
 article:http://code.google.com/appengine/articles/hooks.htmlAlso it is 
 possible to
 construct the key for the desired object if you know the ID in advance.

 class X(db.Model):
   pass

 # If you've already created the entity so you have the ID.
 x_id = X().put().id()

 # Instead of getting by ID, you can create the key manually.
 k = db.Key.from_path('X', x_id)

 Now you have the desired key without having fetched the object, but the part
 which the model class does not allow is setting the key yourself. So you
 could modify the protocol buffer message before it is written to the
 datastore, but I don't recommend it.

 The decision to allow setting key_names but not IDs is something we may
 revisit.

 Happy coding,

 Jeff

 2009/6/12 cryb cbuti...@gmail.com





  Hi.. that is to build key names... What I asked was why I can't build
  a key ID..

  On Jun 12, 5:35 am, Antoniov nio@gmail.com wrote:
   Use the code:
   s = Story(key_name=xzy123)
   Then you create an entity with the key name xzy123.

   Check this:
 http://code.google.com/intl/en-US/appengine/docs/python/datastore/key...

   On 6月12日, 上午1时28分, cryb cbuti...@gmail.com wrote:

Does anyone know why it is possible to build a key name but NOT a key
id? I know key IDs are used as autoincrements, but why can't I just
override this mechanism and build my own key id?
Suppose I want to overwrite an existent entry in my table that has a
key id I know, and also I want to keep that key id after update...
because I can't just build a key id, I am forced to fetch that entity,
modify it and write it back, instead of just write the updated entity
with the key id I already know - so an additional read to the
datastore.
Is there an obscure reason for that? (both key names and key ids are
prefixed with appid/kind as far as I know so there is no chance of
collision with other apps/kinds)- Hide quoted text -

 - Show quoted text -
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Google App Engine group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~--~~~~--~~--~--~---



[google-appengine] Re: why there is no way to build a key id?

2009-06-16 Thread Jeff Enderwick

I second that. I have cases where I'm building a structure of multiple
objects, and I have to do a put() just to get the id, and then I need
to do another put() to the same object later on. Eliminating the 2nd
put() of the same object in the flow would also allow me to wrap it in
a transaction.

2009/6/16 Andy Freeman ana...@earthlink.net:

 The decision to allow setting key_names but not IDs is something we may
 revisit.

 I hope that you're also considering some way to request and allocate
 an unused id for a given path prefix.  (That way we can get unique key
 ids to specify.)



 On Jun 15, 4:45 pm, Jeff S (Google) j...@google.com wrote:
 Hi cryb,

 As you noted, we do not currently allow the ID for a key to be set, as we
 ensure that the ID is unique for each existing entity. I recommend using a
 key name instead of an ID, as Antoniov suggeted, if possible.

 It is technically possible to modify the key of an entity as it is being
 converted to a protocol buffer message before it is sent to the datastore.
 You could do this using hooks in the API proxy as described in this 
 article:http://code.google.com/appengine/articles/hooks.htmlAlso it is 
 possible to
 construct the key for the desired object if you know the ID in advance.

 class X(db.Model):
   pass

 # If you've already created the entity so you have the ID.
 x_id = X().put().id()

 # Instead of getting by ID, you can create the key manually.
 k = db.Key.from_path('X', x_id)

 Now you have the desired key without having fetched the object, but the part
 which the model class does not allow is setting the key yourself. So you
 could modify the protocol buffer message before it is written to the
 datastore, but I don't recommend it.

 The decision to allow setting key_names but not IDs is something we may
 revisit.

 Happy coding,

 Jeff

 2009/6/12 cryb cbuti...@gmail.com





  Hi.. that is to build key names... What I asked was why I can't build
  a key ID..

  On Jun 12, 5:35 am, Antoniov nio@gmail.com wrote:
   Use the code:
   s = Story(key_name=xzy123)
   Then you create an entity with the key name xzy123.

   Check this:
 http://code.google.com/intl/en-US/appengine/docs/python/datastore/key...

   On 6月12日, 上午1时28分, cryb cbuti...@gmail.com wrote:

Does anyone know why it is possible to build a key name but NOT a key
id? I know key IDs are used as autoincrements, but why can't I just
override this mechanism and build my own key id?
Suppose I want to overwrite an existent entry in my table that has a
key id I know, and also I want to keep that key id after update...
because I can't just build a key id, I am forced to fetch that entity,
modify it and write it back, instead of just write the updated entity
with the key id I already know - so an additional read to the
datastore.
Is there an obscure reason for that? (both key names and key ids are
prefixed with appid/kind as far as I know so there is no chance of
collision with other apps/kinds)- Hide quoted text -

 - Show quoted text -
 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Google App Engine group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~--~~~~--~~--~--~---



[google-appengine] Re: why there is no way to build a key id?

2009-06-16 Thread Jeff S (Google)

The datastore does not allow key_names which begin with a digit in
order to avoid confusion with an ID, which is numerical. If you want
to use numeric key names, you could add a one letter prefix :-)

Happy coding,

Jeff

On Jun 16, 1:17 am, cryb cbuti...@gmail.com wrote:
 Hi Jeff.
 Thanks for your reply.. I really hope that in the near future
 appengine will support setting key ids for entities.
 You mentioned that I can use hooks in order to achieve my goal..
 However I was more interested in a solution based on appengine java
 sdk, and not on python hooks. Does appengine java sdk provide hooks or
 some other similar mechanism?
 It seems that for the moment I'll stick to generating key names.
 One more question: I've tried to generate some entities with key names
 on my local devappserver and I got a strange exception stating that I
 can't create key names that start with a digit (?!?)... this holds on
 google appengine production servers too or it's just a bug of
 devappserver?

 Thanks

 On Jun 16, 2:45 am, Jeff S (Google) j...@google.com wrote:

  Hi cryb,

  As you noted, we do not currently allow the ID for a key to be set, as we
  ensure that the ID is unique for each existing entity. I recommend using a
  key name instead of an ID, as Antoniov suggeted, if possible.

  It is technically possible to modify the key of an entity as it is being
  converted to a protocol buffer message before it is sent to the datastore.
  You could do this using hooks in the API proxy as described in this 
  article:http://code.google.com/appengine/articles/hooks.htmlAlsoit is 
  possible to
  construct the key for the desired object if you know the ID in advance.

  class X(db.Model):
pass

  # If you've already created the entity so you have the ID.
  x_id = X().put().id()

  # Instead of getting by ID, you can create the key manually.
  k = db.Key.from_path('X', x_id)

  Now you have the desired key without having fetched the object, but the part
  which the model class does not allow is setting the key yourself. So you
  could modify the protocol buffer message before it is written to the
  datastore, but I don't recommend it.

  The decision to allow setting key_names but not IDs is something we may
  revisit.

  Happy coding,

  Jeff

  2009/6/12 cryb cbuti...@gmail.com

   Hi.. that is to build key names... What I asked was why I can't build
   a key ID..

   On Jun 12, 5:35 am, Antoniov nio@gmail.com wrote:
Use the code:
s = Story(key_name=xzy123)
Then you create an entity with the key name xzy123.

Check this:
  http://code.google.com/intl/en-US/appengine/docs/python/datastore/key...

On 6月12日, 上午1时28分, cryb cbuti...@gmail.com wrote:

 Does anyone know why it is possible to build a key name but NOT a key
 id? I know key IDs are used as autoincrements, but why can't I just
 override this mechanism and build my own key id?
 Suppose I want to overwrite an existent entry in my table that has a
 key id I know, and also I want to keep that key id after update...
 because I can't just build a key id, I am forced to fetch that entity,
 modify it and write it back, instead of just write the updated entity
 with the key id I already know - so an additional read to the
 datastore.
 Is there an obscure reason for that? (both key names and key ids are
 prefixed with appid/kind as far as I know so there is no chance of
 collision with other apps/kinds)
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Google App Engine group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~--~~~~--~~--~--~---



[google-appengine] Re: why there is no way to build a key id?

2009-06-15 Thread Jeff S (Google)
Hi cryb,

As you noted, we do not currently allow the ID for a key to be set, as we
ensure that the ID is unique for each existing entity. I recommend using a
key name instead of an ID, as Antoniov suggeted, if possible.

It is technically possible to modify the key of an entity as it is being
converted to a protocol buffer message before it is sent to the datastore.
You could do this using hooks in the API proxy as described in this article:
http://code.google.com/appengine/articles/hooks.html Also it is possible to
construct the key for the desired object if you know the ID in advance.

class X(db.Model):
  pass

# If you've already created the entity so you have the ID.
x_id = X().put().id()

# Instead of getting by ID, you can create the key manually.
k = db.Key.from_path('X', x_id)

Now you have the desired key without having fetched the object, but the part
which the model class does not allow is setting the key yourself. So you
could modify the protocol buffer message before it is written to the
datastore, but I don't recommend it.

The decision to allow setting key_names but not IDs is something we may
revisit.

Happy coding,

Jeff


2009/6/12 cryb cbuti...@gmail.com


 Hi.. that is to build key names... What I asked was why I can't build
 a key ID..

 On Jun 12, 5:35 am, Antoniov nio@gmail.com wrote:
  Use the code:
  s = Story(key_name=xzy123)
  Then you create an entity with the key name xzy123.
 
  Check this:
 http://code.google.com/intl/en-US/appengine/docs/python/datastore/key...
 
  On 6月12日, 上午1时28分, cryb cbuti...@gmail.com wrote:
 
   Does anyone know why it is possible to build a key name but NOT a key
   id? I know key IDs are used as autoincrements, but why can't I just
   override this mechanism and build my own key id?
   Suppose I want to overwrite an existent entry in my table that has a
   key id I know, and also I want to keep that key id after update...
   because I can't just build a key id, I am forced to fetch that entity,
   modify it and write it back, instead of just write the updated entity
   with the key id I already know - so an additional read to the
   datastore.
   Is there an obscure reason for that? (both key names and key ids are
   prefixed with appid/kind as far as I know so there is no chance of
   collision with other apps/kinds)
 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Google App Engine group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~--~~~~--~~--~--~---



[google-appengine] Re: why there is no way to build a key id?

2009-06-12 Thread cryb

Hi.. that is to build key names... What I asked was why I can't build
a key ID..

On Jun 12, 5:35 am, Antoniov nio@gmail.com wrote:
 Use the code:
 s = Story(key_name=xzy123)
 Then you create an entity with the key name xzy123.

 Check 
 this:http://code.google.com/intl/en-US/appengine/docs/python/datastore/key...

 On 6月12日, 上午1时28分, cryb cbuti...@gmail.com wrote:

  Does anyone know why it is possible to build a key name but NOT a key
  id? I know key IDs are used as autoincrements, but why can't I just
  override this mechanism and build my own key id?
  Suppose I want to overwrite an existent entry in my table that has a
  key id I know, and also I want to keep that key id after update...
  because I can't just build a key id, I am forced to fetch that entity,
  modify it and write it back, instead of just write the updated entity
  with the key id I already know - so an additional read to the
  datastore.
  Is there an obscure reason for that? (both key names and key ids are
  prefixed with appid/kind as far as I know so there is no chance of
  collision with other apps/kinds)
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Google App Engine group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~--~~~~--~~--~--~---



[google-appengine] Re: why there is no way to build a key id?

2009-06-11 Thread Antoniov

Use the code:
s = Story(key_name=xzy123)
Then you create an entity with the key name xzy123.

Check this: 
http://code.google.com/intl/en-US/appengine/docs/python/datastore/keysandentitygroups.html

On 6月12日, 上午1时28分, cryb cbuti...@gmail.com wrote:
 Does anyone know why it is possible to build a key name but NOT a key
 id? I know key IDs are used as autoincrements, but why can't I just
 override this mechanism and build my own key id?
 Suppose I want to overwrite an existent entry in my table that has a
 key id I know, and also I want to keep that key id after update...
 because I can't just build a key id, I am forced to fetch that entity,
 modify it and write it back, instead of just write the updated entity
 with the key id I already know - so an additional read to the
 datastore.
 Is there an obscure reason for that? (both key names and key ids are
 prefixed with appid/kind as far as I know so there is no chance of
 collision with other apps/kinds)

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Google App Engine group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~--~~~~--~~--~--~---