kazu2012 / persevere-framework

Automatically exported from code.google.com/p/persevere-framework
0 stars 0 forks source link

POST id creation function #249

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
A nice enhancement would be to replace the useUUIDs:true notion with a
class attribute that could be set to dictate how POST ids are handled. For
lack of a better name, let's call it postIdHandler. It could be set to the
string "autoincrement" or "uuid" or a function:

Class({ ...
  postIdHandler: function(obj){
    return obj.volumeNumber + '-' + obj.issueNumber;
  }
}

Or if you want, for instance, to override the uuid method (I remember from
couchdb that monotonically increasing ids are known to give a significant
performance boost to inserts on their B+-trees). Say there's some serverjs
uuid library like python's:

Class({ ...
  postIdHandler: require('uuid').uuid4
}

The default postIdHandler could be set to autoincrement on the Object
class. It could totally subsume the function of useUUIDs which could be
deprecated, but otherwise would have no impact on current implementations. 

Moreover, it makes something else possible: numeric ids. If a class doesn't
have its postIdHandler set to autoincrement, numeric ids would be possible.
(Perhaps using setIdSequence on non-autoincrement classes should also throw?)

Original issue reported on code.google.com by dean%dea...@gtempaccount.com on 15 Sep 2009 at 9:09