Time stamp plugin to support creating timestamp

Example
  1. //initialize default timestamp functionality
  2. var MyModel = patio.addModel("testTable", {
  3. plugins : [patio.plugins.TimeStampPlugin],
  4.  
  5. static : {
  6. init : function(){
  7. this._super("arguments");
  8. this.timestamp();
  9. }
  10. }
  11. });
  12.  
  13.  
  14.  
  15. //custom updated column
  16. var MyModel = patio.addModel("testTable", {
  17. plugins : [patio.plugins.TimeStampPlugin],
  18.  
  19. static : {
  20. init : function(){
  21. this._super("arguments");
  22. this.timestamp({updated : "myUpdatedColumn"});
  23. }
  24. }
  25. });
  26.  
  27. //custom created column
  28. var MyModel = patio.addModel("testTable", {
  29. plugins : [patio.plugins.TimeStampPlugin],
  30.  
  31. static : {
  32. init : function(){
  33. this._super("arguments");
  34. this.timestamp({created : "customCreatedColumn"});
  35. }
  36. }
  37. });
  38.  
  39. //set both custom columns
  40. var MyModel = patio.addModel("testTable", {
  41. plugins : [patio.plugins.TimeStampPlugin],
  42.  
  43. static : {
  44. init : function(){
  45. this._super("arguments");
  46. this.timestamp({created : "customCreatedColumn", updated : "myUpdatedColumn"});
  47. }
  48. }
  49. });
  50.  
  51. //Set to update the updated column when row is created
  52. var MyModel = patio.addModel("testTable", {
  53. plugins : [patio.plugins.TimeStampPlugin],
  54.  
  55. static : {
  56. init : function(){
  57. this._super("arguments");
  58. this.timestamp({updateOnCreate : true});
  59. }
  60. }
  61. });
  62.  
  63. //Set all three options
  64. var MyModel = patio.addModel("testTable", {
  65. plugins : [patio.plugins.TimeStampPlugin],
  66.  
  67. static : {
  68. init : function(){
  69. this._super("arguments");
  70. this.timestamp({created : "customCreatedColumn", updated : "myUpdatedColumn", updateOnCreate : true});
  71. }
  72. }
  73. });

Constructor

Defined plugins/timestamp.js Source
  1. exports = define(null, {

timestamp Static Function Public


Defined plugins/timestamp.js

Adds timestamp functionality to a table.

Arguments Source
  1. function (options){
  2. options = options || {};
  3. this._timestampOptions = options;
  4. var updateColumn = options.updated || "updated";
  5. var createdColumn = options.created || "created";
  6. var updateOnCreate = options.updateOnCreate || false;
  7. this.pre("save", function (next) {
  8. this[createdColumn] = new Date();
  9. if (updateOnCreate) {
  10. this[updateColumn] = new Date();
  11. }
  12. next();
  13. });
  14. this.pre("update", function (next) {
  15. this[updateColumn] = new Date();
  16. next();
  17. });
  18. return this;
  19. }

Documentation generated using coddoc.