List:Cluster« Previous MessageNext Message »
From:Magnus Blåudd Date:November 28 2012 3:09pm
Subject:Re: NDB API: PK Autoincrement
View as plain text  

you need to use Ndb::getAutoIncrementValue() to fetch (and reserve) one 
or more autoincrement values for the table you are inserting into. Then 
use the returned value you get in subsequent insert.

Normally it's not recommended to use auto increment columns for NDB 
tables since there is an extra roundtrip  consumed when fetching the 
autoincrement value using the above function. Even though you can fetch 
something like 64 values at a time, you'd get gaps in the  range unless 
you really insert 64 rows.

If possible try to use different primary key. Unless anything obvious is 
available, you can always generate a UUID.

Sorry, couldn't find any simple example.

/ Magnus

On 11/28/2012 02:51 PM, Mazen Hajri wrote:
> Hello there,
> I'm currently implementing some application on top of NDB API, but I'm
> facing a problem of incrementing the PK with an auto_increment attribute. Do
> I have to read the last value then do the auto increment explicitly in the
> code, or is there an easier way?
> A simple example would be of great help.
> Kind regards,
> Mazen

NDB API: PK Autoincrement Mazen Hajri28 Nov
  • Re: NDB API: PK AutoincrementMagnus Blåudd28 Nov
    • Re: NDB API: PK AutoincrementJohan Andersson28 Nov