This functionality is available in eXtremeDB starting with version 9.0.
Timestamps allow you to automatically record the creation or modification time of a database record.
eXtremeDB supports timestamps at the kernel level and implements this functionality through its built-in event mechanism. In the schema, class fields can be marked with the
on_createoron_updatekeywords. Whenon_createis specified, the field is automatically populated with the system time (the result of callingmco_system_get_current_time()) at the moment the object is created. Whenon_updateis specified, the field is updated with the current system time whenever the object is modified. Themcocompschema compiler automatically generates the required on-new and on-update event handlers; the application only needs to call the generated registration function<dbname>_register_time_events().Fields marked with
on_createoron_updatecan be used in indexes like any other field. However, note the following:
- An
on_updatefield changes whenever the object is modified. If such a field is indexed, the object will be removed and re-inserted into the index on every update, which may impact performance.- Automatic updates to an
on_updatefield occur only when a scalar field in the class is modified. Changes to arrays, vectors, BLOBs, nested structures, or sequences are not tracked.An example of timestamp field definitions in a schema:
#define int1 signed<1> #define int2 signed<2> #define int4 signed<4> #define int8 signed<8> #define uint8 unsigned<8> #define uint4 unsigned<4> #define uint2 unsigned<2> #define uint1 unsigned<1> declare database tmdb; class MyClass { uint4 key; uint4 payload; on_create datetime ctime; on_update datetime mtime; hash <key> pk[1000]; tree <ctime> created; tree <mtime> updated; };A working code example demonstrating this mechanism is located in the
samples/native/core/10-events/obj-timestampsdirectory.For more information about using events in eXtremeDB, see the Using eXtremeDB Database Events and Time-To-Live Features page.